
org.glowroot.agent.weaving.ImmutableAdvice Maven / Gradle / Ivy
package org.glowroot.agent.weaving;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.agent.shaded.google.common.base.MoreObjects;
import org.glowroot.agent.shaded.google.common.base.Objects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.ImmutableSet;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Booleans;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.glowroot.agent.plugin.api.weaving.Pointcut;
import org.glowroot.agent.shaded.objectweb.asm.Type;
import org.glowroot.agent.shaded.objectweb.asm.commons.Method;
/**
* Immutable implementation of {@link Advice}.
*
* Use builder to create immutable instances:
* {@code ImmutableAdvice.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "Advice"})
@Immutable
public final class ImmutableAdvice extends Advice {
private final Pointcut pointcut;
private final Type adviceType;
private final String pointcutDeclaringClassName;
private final @Nullable String pointcutTargetClassName;
private final @Nullable Pattern pointcutDeclaringClassNamePattern;
private final @Nullable Pattern pointcutTargetClassNamePattern;
private final @Nullable Pattern pointcutMethodNamePattern;
private final @Nullable Type travelerType;
private final @Nullable Method isEnabledAdvice;
private final @Nullable Method onBeforeAdvice;
private final @Nullable Method onReturnAdvice;
private final @Nullable Method onThrowAdvice;
private final @Nullable Method onAfterAdvice;
private final ImmutableList isEnabledParameters;
private final ImmutableList onBeforeParameters;
private final ImmutableList onReturnParameters;
private final ImmutableList onThrowParameters;
private final ImmutableList onAfterParameters;
private final boolean reweavable;
private final ImmutableSet classMetaTypes;
private final ImmutableSet methodMetaTypes;
private static final int STAGE_INITIALIZING = -1;
private static final int STAGE_UNINITIALIZED = 0;
private static final int STAGE_INITIALIZED = 1;
private volatile InitShim initShim = new InitShim();
private final class InitShim {
private ImmutableSet classMetaTypes;
private byte classMetaTypesStage;
ImmutableSet classMetaTypes() {
if (classMetaTypesStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (classMetaTypesStage == STAGE_UNINITIALIZED) {
classMetaTypesStage = STAGE_INITIALIZING;
this.classMetaTypes = Preconditions.checkNotNull(ImmutableAdvice.super.classMetaTypes());
classMetaTypesStage = STAGE_INITIALIZED;
}
return classMetaTypes;
}
private ImmutableSet methodMetaTypes;
private byte methodMetaTypesStage;
ImmutableSet methodMetaTypes() {
if (methodMetaTypesStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (methodMetaTypesStage == STAGE_UNINITIALIZED) {
methodMetaTypesStage = STAGE_INITIALIZING;
this.methodMetaTypes = Preconditions.checkNotNull(ImmutableAdvice.super.methodMetaTypes());
methodMetaTypesStage = STAGE_INITIALIZED;
}
return methodMetaTypes;
}
private String formatInitCycleMessage() {
ArrayList attributes = Lists.newArrayList();;
if (classMetaTypesStage == STAGE_INITIALIZING) attributes.add("classMetaTypes");
if (methodMetaTypesStage == STAGE_INITIALIZING) attributes.add("methodMetaTypes");
return "Cannot build Advice, attribute initializers form cycle" + attributes;
}
}
private ImmutableAdvice(
Pointcut pointcut,
Type adviceType,
String pointcutDeclaringClassName,
@Nullable String pointcutTargetClassName,
@Nullable Pattern pointcutDeclaringClassNamePattern,
@Nullable Pattern pointcutTargetClassNamePattern,
@Nullable Pattern pointcutMethodNamePattern,
@Nullable Type travelerType,
@Nullable Method isEnabledAdvice,
@Nullable Method onBeforeAdvice,
@Nullable Method onReturnAdvice,
@Nullable Method onThrowAdvice,
@Nullable Method onAfterAdvice,
ImmutableList isEnabledParameters,
ImmutableList onBeforeParameters,
ImmutableList onReturnParameters,
ImmutableList onThrowParameters,
ImmutableList onAfterParameters,
boolean reweavable) {
this.pointcut = pointcut;
this.adviceType = adviceType;
this.pointcutDeclaringClassName = pointcutDeclaringClassName;
this.pointcutTargetClassName = pointcutTargetClassName;
this.pointcutDeclaringClassNamePattern = pointcutDeclaringClassNamePattern;
this.pointcutTargetClassNamePattern = pointcutTargetClassNamePattern;
this.pointcutMethodNamePattern = pointcutMethodNamePattern;
this.travelerType = travelerType;
this.isEnabledAdvice = isEnabledAdvice;
this.onBeforeAdvice = onBeforeAdvice;
this.onReturnAdvice = onReturnAdvice;
this.onThrowAdvice = onThrowAdvice;
this.onAfterAdvice = onAfterAdvice;
this.isEnabledParameters = isEnabledParameters;
this.onBeforeParameters = onBeforeParameters;
this.onReturnParameters = onReturnParameters;
this.onThrowParameters = onThrowParameters;
this.onAfterParameters = onAfterParameters;
this.reweavable = reweavable;
this.classMetaTypes = Preconditions.checkNotNull(super.classMetaTypes());
this.methodMetaTypes = Preconditions.checkNotNull(super.methodMetaTypes());
this.initShim = null;
}
/**
* @return value of {@code pointcut} attribute
*/
@JsonProperty
@Override
public Pointcut pointcut() {
return pointcut;
}
/**
* @return value of {@code adviceType} attribute
*/
@JsonProperty
@Override
public Type adviceType() {
return adviceType;
}
/**
* @return value of {@code pointcutDeclaringClassName} attribute
*/
@JsonProperty
@Override
public String pointcutDeclaringClassName() {
return pointcutDeclaringClassName;
}
/**
* @return value of {@code pointcutTargetClassName} attribute
*/
@JsonProperty
@Override
public @Nullable String pointcutTargetClassName() {
return pointcutTargetClassName;
}
/**
* @return value of {@code pointcutDeclaringClassNamePattern} attribute
*/
@JsonProperty
@Override
public @Nullable Pattern pointcutDeclaringClassNamePattern() {
return pointcutDeclaringClassNamePattern;
}
/**
* @return value of {@code pointcutTargetClassNamePattern} attribute
*/
@JsonProperty
@Override
public @Nullable Pattern pointcutTargetClassNamePattern() {
return pointcutTargetClassNamePattern;
}
/**
* @return value of {@code pointcutMethodNamePattern} attribute
*/
@JsonProperty
@Override
public @Nullable Pattern pointcutMethodNamePattern() {
return pointcutMethodNamePattern;
}
/**
* @return value of {@code travelerType} attribute
*/
@JsonProperty
@Override
public @Nullable Type travelerType() {
return travelerType;
}
/**
* @return value of {@code isEnabledAdvice} attribute
*/
@JsonProperty
@Override
public @Nullable Method isEnabledAdvice() {
return isEnabledAdvice;
}
/**
* @return value of {@code onBeforeAdvice} attribute
*/
@JsonProperty
@Override
public @Nullable Method onBeforeAdvice() {
return onBeforeAdvice;
}
/**
* @return value of {@code onReturnAdvice} attribute
*/
@JsonProperty
@Override
public @Nullable Method onReturnAdvice() {
return onReturnAdvice;
}
/**
* @return value of {@code onThrowAdvice} attribute
*/
@JsonProperty
@Override
public @Nullable Method onThrowAdvice() {
return onThrowAdvice;
}
/**
* @return value of {@code onAfterAdvice} attribute
*/
@JsonProperty
@Override
public @Nullable Method onAfterAdvice() {
return onAfterAdvice;
}
/**
* @return value of {@code isEnabledParameters} attribute
*/
@JsonProperty
@Override
public ImmutableList isEnabledParameters() {
return isEnabledParameters;
}
/**
* @return value of {@code onBeforeParameters} attribute
*/
@JsonProperty
@Override
public ImmutableList onBeforeParameters() {
return onBeforeParameters;
}
/**
* @return value of {@code onReturnParameters} attribute
*/
@JsonProperty
@Override
public ImmutableList onReturnParameters() {
return onReturnParameters;
}
/**
* @return value of {@code onThrowParameters} attribute
*/
@JsonProperty
@Override
public ImmutableList onThrowParameters() {
return onThrowParameters;
}
/**
* @return value of {@code onAfterParameters} attribute
*/
@JsonProperty
@Override
public ImmutableList onAfterParameters() {
return onAfterParameters;
}
/**
* @return value of {@code reweavable} attribute
*/
@JsonProperty
@Override
public boolean reweavable() {
return reweavable;
}
/**
* @return computed at construction value of {@code classMetaTypes} attribute
*/
@JsonProperty
@Override
public ImmutableSet classMetaTypes() {
return initShim != null
? initShim.classMetaTypes()
: classMetaTypes;
}
/**
* @return computed at construction value of {@code methodMetaTypes} attribute
*/
@JsonProperty
@Override
public ImmutableSet methodMetaTypes() {
return initShim != null
? initShim.methodMetaTypes()
: methodMetaTypes;
}
/**
* Copy current immutable object by setting value for {@link Advice#pointcut() pointcut}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for pointcut
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withPointcut(Pointcut value) {
if (this.pointcut == value) return this;
Pointcut newValue = Preconditions.checkNotNull(value);
return new ImmutableAdvice(
newValue,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#adviceType() adviceType}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for adviceType
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withAdviceType(Type value) {
if (this.adviceType == value) return this;
Type newValue = Preconditions.checkNotNull(value);
return new ImmutableAdvice(
this.pointcut,
newValue,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#pointcutDeclaringClassName() pointcutDeclaringClassName}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for pointcutDeclaringClassName
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withPointcutDeclaringClassName(String value) {
if (this.pointcutDeclaringClassName == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
newValue,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#pointcutTargetClassName() pointcutTargetClassName}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for pointcutTargetClassName, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withPointcutTargetClassName(@Nullable String value) {
if (this.pointcutTargetClassName == value) return this;
@Nullable String newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
newValue,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#pointcutDeclaringClassNamePattern() pointcutDeclaringClassNamePattern}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for pointcutDeclaringClassNamePattern, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withPointcutDeclaringClassNamePattern(@Nullable Pattern value) {
if (this.pointcutDeclaringClassNamePattern == value) return this;
@Nullable Pattern newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
newValue,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#pointcutTargetClassNamePattern() pointcutTargetClassNamePattern}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for pointcutTargetClassNamePattern, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withPointcutTargetClassNamePattern(@Nullable Pattern value) {
if (this.pointcutTargetClassNamePattern == value) return this;
@Nullable Pattern newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
newValue,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#pointcutMethodNamePattern() pointcutMethodNamePattern}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for pointcutMethodNamePattern, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withPointcutMethodNamePattern(@Nullable Pattern value) {
if (this.pointcutMethodNamePattern == value) return this;
@Nullable Pattern newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
newValue,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#travelerType() travelerType}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for travelerType, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withTravelerType(@Nullable Type value) {
if (this.travelerType == value) return this;
@Nullable Type newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
newValue,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#isEnabledAdvice() isEnabledAdvice}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for isEnabledAdvice, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withIsEnabledAdvice(@Nullable Method value) {
if (this.isEnabledAdvice == value) return this;
@Nullable Method newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
newValue,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#onBeforeAdvice() onBeforeAdvice}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for onBeforeAdvice, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withOnBeforeAdvice(@Nullable Method value) {
if (this.onBeforeAdvice == value) return this;
@Nullable Method newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
newValue,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#onReturnAdvice() onReturnAdvice}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for onReturnAdvice, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withOnReturnAdvice(@Nullable Method value) {
if (this.onReturnAdvice == value) return this;
@Nullable Method newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
newValue,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#onThrowAdvice() onThrowAdvice}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for onThrowAdvice, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withOnThrowAdvice(@Nullable Method value) {
if (this.onThrowAdvice == value) return this;
@Nullable Method newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
newValue,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#onAfterAdvice() onAfterAdvice}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for onAfterAdvice, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withOnAfterAdvice(@Nullable Method value) {
if (this.onAfterAdvice == value) return this;
@Nullable Method newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
newValue,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#isEnabledParameters() isEnabledParameters}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withIsEnabledParameters(Advice.AdviceParameter... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
newValue,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#isEnabledParameters() isEnabledParameters}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of isEnabledParameters elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withIsEnabledParameters(Iterable extends Advice.AdviceParameter> elements) {
if (this.isEnabledParameters == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
newValue,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#onBeforeParameters() onBeforeParameters}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withOnBeforeParameters(Advice.AdviceParameter... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
newValue,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#onBeforeParameters() onBeforeParameters}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of onBeforeParameters elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withOnBeforeParameters(Iterable extends Advice.AdviceParameter> elements) {
if (this.onBeforeParameters == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
newValue,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#onReturnParameters() onReturnParameters}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withOnReturnParameters(Advice.AdviceParameter... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
newValue,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#onReturnParameters() onReturnParameters}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of onReturnParameters elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withOnReturnParameters(Iterable extends Advice.AdviceParameter> elements) {
if (this.onReturnParameters == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
newValue,
this.onThrowParameters,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#onThrowParameters() onThrowParameters}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withOnThrowParameters(Advice.AdviceParameter... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
newValue,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#onThrowParameters() onThrowParameters}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of onThrowParameters elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withOnThrowParameters(Iterable extends Advice.AdviceParameter> elements) {
if (this.onThrowParameters == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
newValue,
this.onAfterParameters,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#onAfterParameters() onAfterParameters}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withOnAfterParameters(Advice.AdviceParameter... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
newValue,
this.reweavable);
}
/**
* Copy current immutable object with elements that replace content of {@link Advice#onAfterParameters() onAfterParameters}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of onAfterParameters elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAdvice withOnAfterParameters(Iterable extends Advice.AdviceParameter> elements) {
if (this.onAfterParameters == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
newValue,
this.reweavable);
}
/**
* Copy current immutable object by setting value for {@link Advice#reweavable() reweavable}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for reweavable
* @return modified copy of the {@code this} object
*/
public final ImmutableAdvice withReweavable(boolean value) {
if (this.reweavable == value) return this;
boolean newValue = value;
return new ImmutableAdvice(
this.pointcut,
this.adviceType,
this.pointcutDeclaringClassName,
this.pointcutTargetClassName,
this.pointcutDeclaringClassNamePattern,
this.pointcutTargetClassNamePattern,
this.pointcutMethodNamePattern,
this.travelerType,
this.isEnabledAdvice,
this.onBeforeAdvice,
this.onReturnAdvice,
this.onThrowAdvice,
this.onAfterAdvice,
this.isEnabledParameters,
this.onBeforeParameters,
this.onReturnParameters,
this.onThrowParameters,
this.onAfterParameters,
newValue);
}
/**
* This instance is equal to instances of {@code ImmutableAdvice} with equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableAdvice
&& equalTo((ImmutableAdvice) another);
}
private boolean equalTo(ImmutableAdvice another) {
return pointcut.equals(another.pointcut)
&& adviceType.equals(another.adviceType)
&& pointcutDeclaringClassName.equals(another.pointcutDeclaringClassName)
&& Objects.equal(pointcutTargetClassName, another.pointcutTargetClassName)
&& Objects.equal(pointcutDeclaringClassNamePattern, another.pointcutDeclaringClassNamePattern)
&& Objects.equal(pointcutTargetClassNamePattern, another.pointcutTargetClassNamePattern)
&& Objects.equal(pointcutMethodNamePattern, another.pointcutMethodNamePattern)
&& Objects.equal(travelerType, another.travelerType)
&& Objects.equal(isEnabledAdvice, another.isEnabledAdvice)
&& Objects.equal(onBeforeAdvice, another.onBeforeAdvice)
&& Objects.equal(onReturnAdvice, another.onReturnAdvice)
&& Objects.equal(onThrowAdvice, another.onThrowAdvice)
&& Objects.equal(onAfterAdvice, another.onAfterAdvice)
&& isEnabledParameters.equals(another.isEnabledParameters)
&& onBeforeParameters.equals(another.onBeforeParameters)
&& onReturnParameters.equals(another.onReturnParameters)
&& onThrowParameters.equals(another.onThrowParameters)
&& onAfterParameters.equals(another.onAfterParameters)
&& reweavable == another.reweavable
&& classMetaTypes.equals(another.classMetaTypes)
&& methodMetaTypes.equals(another.methodMetaTypes);
}
/**
* Computes hash code from attributes: {@code pointcut}, {@code adviceType}, {@code pointcutDeclaringClassName}, {@code pointcutTargetClassName}, {@code pointcutDeclaringClassNamePattern}, {@code pointcutTargetClassNamePattern}, {@code pointcutMethodNamePattern}, {@code travelerType}, {@code isEnabledAdvice}, {@code onBeforeAdvice}, {@code onReturnAdvice}, {@code onThrowAdvice}, {@code onAfterAdvice}, {@code isEnabledParameters}, {@code onBeforeParameters}, {@code onReturnParameters}, {@code onThrowParameters}, {@code onAfterParameters}, {@code reweavable}, {@code classMetaTypes}, {@code methodMetaTypes}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + pointcut.hashCode();
h = h * 17 + adviceType.hashCode();
h = h * 17 + pointcutDeclaringClassName.hashCode();
h = h * 17 + Objects.hashCode(pointcutTargetClassName);
h = h * 17 + Objects.hashCode(pointcutDeclaringClassNamePattern);
h = h * 17 + Objects.hashCode(pointcutTargetClassNamePattern);
h = h * 17 + Objects.hashCode(pointcutMethodNamePattern);
h = h * 17 + Objects.hashCode(travelerType);
h = h * 17 + Objects.hashCode(isEnabledAdvice);
h = h * 17 + Objects.hashCode(onBeforeAdvice);
h = h * 17 + Objects.hashCode(onReturnAdvice);
h = h * 17 + Objects.hashCode(onThrowAdvice);
h = h * 17 + Objects.hashCode(onAfterAdvice);
h = h * 17 + isEnabledParameters.hashCode();
h = h * 17 + onBeforeParameters.hashCode();
h = h * 17 + onReturnParameters.hashCode();
h = h * 17 + onThrowParameters.hashCode();
h = h * 17 + onAfterParameters.hashCode();
h = h * 17 + Booleans.hashCode(reweavable);
h = h * 17 + classMetaTypes.hashCode();
h = h * 17 + methodMetaTypes.hashCode();
return h;
}
/**
* Prints immutable value {@code Advice...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Advice")
.add("pointcut", pointcut)
.add("adviceType", adviceType)
.add("pointcutDeclaringClassName", pointcutDeclaringClassName)
.add("pointcutTargetClassName", pointcutTargetClassName)
.add("pointcutDeclaringClassNamePattern", pointcutDeclaringClassNamePattern)
.add("pointcutTargetClassNamePattern", pointcutTargetClassNamePattern)
.add("pointcutMethodNamePattern", pointcutMethodNamePattern)
.add("travelerType", travelerType)
.add("isEnabledAdvice", isEnabledAdvice)
.add("onBeforeAdvice", onBeforeAdvice)
.add("onReturnAdvice", onReturnAdvice)
.add("onThrowAdvice", onThrowAdvice)
.add("onAfterAdvice", onAfterAdvice)
.add("isEnabledParameters", isEnabledParameters)
.add("onBeforeParameters", onBeforeParameters)
.add("onReturnParameters", onReturnParameters)
.add("onThrowParameters", onThrowParameters)
.add("onAfterParameters", onAfterParameters)
.add("reweavable", reweavable)
.add("classMetaTypes", classMetaTypes)
.add("methodMetaTypes", methodMetaTypes)
.toString();
}
/**
* Simple representation of this value type suitable Jackson binding
* @deprecated Do not use this type directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
static final class Json {
@JsonProperty
@Nullable Pointcut pointcut;
@JsonProperty
@Nullable Type adviceType;
@JsonProperty
@Nullable String pointcutDeclaringClassName;
@JsonProperty
@Nullable String pointcutTargetClassName;
@JsonProperty
@Nullable Pattern pointcutDeclaringClassNamePattern;
@JsonProperty
@Nullable Pattern pointcutTargetClassNamePattern;
@JsonProperty
@Nullable Pattern pointcutMethodNamePattern;
@JsonProperty
@Nullable Type travelerType;
@JsonProperty
@Nullable Method isEnabledAdvice;
@JsonProperty
@Nullable Method onBeforeAdvice;
@JsonProperty
@Nullable Method onReturnAdvice;
@JsonProperty
@Nullable Method onThrowAdvice;
@JsonProperty
@Nullable Method onAfterAdvice;
@JsonProperty
@Nullable ImmutableList isEnabledParameters;
@JsonProperty
@Nullable ImmutableList onBeforeParameters;
@JsonProperty
@Nullable ImmutableList onReturnParameters;
@JsonProperty
@Nullable ImmutableList onThrowParameters;
@JsonProperty
@Nullable ImmutableList onAfterParameters;
@JsonProperty
@Nullable Boolean reweavable;
@JsonProperty
@Nullable ImmutableSet classMetaTypes;
@JsonProperty
@Nullable ImmutableSet methodMetaTypes;
}
/**
* @param json JSON-bindable data structure
* @return immutable value type
* @deprecated Do not use this method directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
@JsonCreator
static ImmutableAdvice fromJson(Json json) {
ImmutableAdvice.Builder builder = ImmutableAdvice.builder();
if (json.pointcut != null) {
builder.pointcut(json.pointcut);
}
if (json.adviceType != null) {
builder.adviceType(json.adviceType);
}
if (json.pointcutDeclaringClassName != null) {
builder.pointcutDeclaringClassName(json.pointcutDeclaringClassName);
}
if (json.pointcutTargetClassName != null) {
builder.pointcutTargetClassName(json.pointcutTargetClassName);
}
if (json.pointcutDeclaringClassNamePattern != null) {
builder.pointcutDeclaringClassNamePattern(json.pointcutDeclaringClassNamePattern);
}
if (json.pointcutTargetClassNamePattern != null) {
builder.pointcutTargetClassNamePattern(json.pointcutTargetClassNamePattern);
}
if (json.pointcutMethodNamePattern != null) {
builder.pointcutMethodNamePattern(json.pointcutMethodNamePattern);
}
if (json.travelerType != null) {
builder.travelerType(json.travelerType);
}
if (json.isEnabledAdvice != null) {
builder.isEnabledAdvice(json.isEnabledAdvice);
}
if (json.onBeforeAdvice != null) {
builder.onBeforeAdvice(json.onBeforeAdvice);
}
if (json.onReturnAdvice != null) {
builder.onReturnAdvice(json.onReturnAdvice);
}
if (json.onThrowAdvice != null) {
builder.onThrowAdvice(json.onThrowAdvice);
}
if (json.onAfterAdvice != null) {
builder.onAfterAdvice(json.onAfterAdvice);
}
if (json.isEnabledParameters != null) {
builder.addAllIsEnabledParameters(json.isEnabledParameters);
}
if (json.onBeforeParameters != null) {
builder.addAllOnBeforeParameters(json.onBeforeParameters);
}
if (json.onReturnParameters != null) {
builder.addAllOnReturnParameters(json.onReturnParameters);
}
if (json.onThrowParameters != null) {
builder.addAllOnThrowParameters(json.onThrowParameters);
}
if (json.onAfterParameters != null) {
builder.addAllOnAfterParameters(json.onAfterParameters);
}
if (json.reweavable != null) {
builder.reweavable(json.reweavable);
}
return builder.build();
}
/**
* Creates immutable copy of {@link Advice}.
* Uses accessors to get values to initialize immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance instance to copy
* @return copied immutable Advice instance
*/
public static ImmutableAdvice copyOf(Advice instance) {
if (instance instanceof ImmutableAdvice) {
return (ImmutableAdvice) instance;
}
return ImmutableAdvice.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.agent.weaving.ImmutableAdvice ImmutableAdvice}.
* @return new ImmutableAdvice builder
*/
public static ImmutableAdvice.Builder builder() {
return new ImmutableAdvice.Builder();
}
/**
* Builds instances of {@link org.glowroot.agent.weaving.ImmutableAdvice ImmutableAdvice}.
* Initialize attributes and then invoke {@link #build()} method to create
* immutable instance.
* {@code Builder} is not thread safe and generally should not be stored in field or collection,
* but used immediately to create instances.
*/
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_POINTCUT = 0x1L;
private static final long INIT_BIT_ADVICE_TYPE = 0x2L;
private static final long INIT_BIT_POINTCUT_DECLARING_CLASS_NAME = 0x4L;
private static final long INIT_BIT_REWEAVABLE = 0x8L;
private long initBits = 0xf;
private @Nullable Pointcut pointcut;
private @Nullable Type adviceType;
private @Nullable String pointcutDeclaringClassName;
private @Nullable String pointcutTargetClassName;
private @Nullable Pattern pointcutDeclaringClassNamePattern;
private @Nullable Pattern pointcutTargetClassNamePattern;
private @Nullable Pattern pointcutMethodNamePattern;
private @Nullable Type travelerType;
private @Nullable Method isEnabledAdvice;
private @Nullable Method onBeforeAdvice;
private @Nullable Method onReturnAdvice;
private @Nullable Method onThrowAdvice;
private @Nullable Method onAfterAdvice;
private ImmutableList.Builder isEnabledParametersBuilder = ImmutableList.builder();
private ImmutableList.Builder onBeforeParametersBuilder = ImmutableList.builder();
private ImmutableList.Builder onReturnParametersBuilder = ImmutableList.builder();
private ImmutableList.Builder onThrowParametersBuilder = ImmutableList.builder();
private ImmutableList.Builder onAfterParametersBuilder = ImmutableList.builder();
private boolean reweavable;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link Advice} instance.
* Regular attribute values will be replaced with ones of an instance.
* Instance's absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance instance to copy values from
* @return {@code this} builder for chained invocation
*/
public final Builder copyFrom(Advice instance) {
Preconditions.checkNotNull(instance);
pointcut(instance.pointcut());
adviceType(instance.adviceType());
pointcutDeclaringClassName(instance.pointcutDeclaringClassName());
@Nullable String pointcutTargetClassNameValue = instance.pointcutTargetClassName();
if (pointcutTargetClassNameValue != null) {
pointcutTargetClassName(pointcutTargetClassNameValue);
}
@Nullable Pattern pointcutDeclaringClassNamePatternValue = instance.pointcutDeclaringClassNamePattern();
if (pointcutDeclaringClassNamePatternValue != null) {
pointcutDeclaringClassNamePattern(pointcutDeclaringClassNamePatternValue);
}
@Nullable Pattern pointcutTargetClassNamePatternValue = instance.pointcutTargetClassNamePattern();
if (pointcutTargetClassNamePatternValue != null) {
pointcutTargetClassNamePattern(pointcutTargetClassNamePatternValue);
}
@Nullable Pattern pointcutMethodNamePatternValue = instance.pointcutMethodNamePattern();
if (pointcutMethodNamePatternValue != null) {
pointcutMethodNamePattern(pointcutMethodNamePatternValue);
}
@Nullable Type travelerTypeValue = instance.travelerType();
if (travelerTypeValue != null) {
travelerType(travelerTypeValue);
}
@Nullable Method isEnabledAdviceValue = instance.isEnabledAdvice();
if (isEnabledAdviceValue != null) {
isEnabledAdvice(isEnabledAdviceValue);
}
@Nullable Method onBeforeAdviceValue = instance.onBeforeAdvice();
if (onBeforeAdviceValue != null) {
onBeforeAdvice(onBeforeAdviceValue);
}
@Nullable Method onReturnAdviceValue = instance.onReturnAdvice();
if (onReturnAdviceValue != null) {
onReturnAdvice(onReturnAdviceValue);
}
@Nullable Method onThrowAdviceValue = instance.onThrowAdvice();
if (onThrowAdviceValue != null) {
onThrowAdvice(onThrowAdviceValue);
}
@Nullable Method onAfterAdviceValue = instance.onAfterAdvice();
if (onAfterAdviceValue != null) {
onAfterAdvice(onAfterAdviceValue);
}
addAllIsEnabledParameters(instance.isEnabledParameters());
addAllOnBeforeParameters(instance.onBeforeParameters());
addAllOnReturnParameters(instance.onReturnParameters());
addAllOnThrowParameters(instance.onThrowParameters());
addAllOnAfterParameters(instance.onAfterParameters());
reweavable(instance.reweavable());
return this;
}
/**
* Initializes value for {@link Advice#pointcut() pointcut}.
* @param pointcut value for pointcut
* @return {@code this} builder for chained invocation
*/
public final Builder pointcut(Pointcut pointcut) {
this.pointcut = Preconditions.checkNotNull(pointcut);
initBits &= ~INIT_BIT_POINTCUT;
return this;
}
/**
* Initializes value for {@link Advice#adviceType() adviceType}.
* @param adviceType value for adviceType
* @return {@code this} builder for chained invocation
*/
public final Builder adviceType(Type adviceType) {
this.adviceType = Preconditions.checkNotNull(adviceType);
initBits &= ~INIT_BIT_ADVICE_TYPE;
return this;
}
/**
* Initializes value for {@link Advice#pointcutDeclaringClassName() pointcutDeclaringClassName}.
* @param pointcutDeclaringClassName value for pointcutDeclaringClassName
* @return {@code this} builder for chained invocation
*/
public final Builder pointcutDeclaringClassName(String pointcutDeclaringClassName) {
this.pointcutDeclaringClassName = Preconditions.checkNotNull(pointcutDeclaringClassName);
initBits &= ~INIT_BIT_POINTCUT_DECLARING_CLASS_NAME;
return this;
}
/**
* Initializes value for {@link Advice#pointcutTargetClassName() pointcutTargetClassName}.
* @param pointcutTargetClassName value for pointcutTargetClassName, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder pointcutTargetClassName(@Nullable String pointcutTargetClassName) {
this.pointcutTargetClassName = pointcutTargetClassName;
return this;
}
/**
* Initializes value for {@link Advice#pointcutDeclaringClassNamePattern() pointcutDeclaringClassNamePattern}.
* @param pointcutDeclaringClassNamePattern value for pointcutDeclaringClassNamePattern, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder pointcutDeclaringClassNamePattern(@Nullable Pattern pointcutDeclaringClassNamePattern) {
this.pointcutDeclaringClassNamePattern = pointcutDeclaringClassNamePattern;
return this;
}
/**
* Initializes value for {@link Advice#pointcutTargetClassNamePattern() pointcutTargetClassNamePattern}.
* @param pointcutTargetClassNamePattern value for pointcutTargetClassNamePattern, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder pointcutTargetClassNamePattern(@Nullable Pattern pointcutTargetClassNamePattern) {
this.pointcutTargetClassNamePattern = pointcutTargetClassNamePattern;
return this;
}
/**
* Initializes value for {@link Advice#pointcutMethodNamePattern() pointcutMethodNamePattern}.
* @param pointcutMethodNamePattern value for pointcutMethodNamePattern, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder pointcutMethodNamePattern(@Nullable Pattern pointcutMethodNamePattern) {
this.pointcutMethodNamePattern = pointcutMethodNamePattern;
return this;
}
/**
* Initializes value for {@link Advice#travelerType() travelerType}.
* @param travelerType value for travelerType, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder travelerType(@Nullable Type travelerType) {
this.travelerType = travelerType;
return this;
}
/**
* Initializes value for {@link Advice#isEnabledAdvice() isEnabledAdvice}.
* @param isEnabledAdvice value for isEnabledAdvice, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder isEnabledAdvice(@Nullable Method isEnabledAdvice) {
this.isEnabledAdvice = isEnabledAdvice;
return this;
}
/**
* Initializes value for {@link Advice#onBeforeAdvice() onBeforeAdvice}.
* @param onBeforeAdvice value for onBeforeAdvice, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder onBeforeAdvice(@Nullable Method onBeforeAdvice) {
this.onBeforeAdvice = onBeforeAdvice;
return this;
}
/**
* Initializes value for {@link Advice#onReturnAdvice() onReturnAdvice}.
* @param onReturnAdvice value for onReturnAdvice, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder onReturnAdvice(@Nullable Method onReturnAdvice) {
this.onReturnAdvice = onReturnAdvice;
return this;
}
/**
* Initializes value for {@link Advice#onThrowAdvice() onThrowAdvice}.
* @param onThrowAdvice value for onThrowAdvice, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder onThrowAdvice(@Nullable Method onThrowAdvice) {
this.onThrowAdvice = onThrowAdvice;
return this;
}
/**
* Initializes value for {@link Advice#onAfterAdvice() onAfterAdvice}.
* @param onAfterAdvice value for onAfterAdvice, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder onAfterAdvice(@Nullable Method onAfterAdvice) {
this.onAfterAdvice = onAfterAdvice;
return this;
}
/**
* Adds one element to {@link Advice#isEnabledParameters() isEnabledParameters} list.
* @param element isEnabledParameters element
* @return {@code this} builder for chained invocation
*/
public final Builder addIsEnabledParameters(Advice.AdviceParameter element) {
isEnabledParametersBuilder.add(element);
return this;
}
/**
* Adds elements to {@link Advice#isEnabledParameters() isEnabledParameters} list.
* @param elements array of isEnabledParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addIsEnabledParameters(Advice.AdviceParameter... elements) {
isEnabledParametersBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link Advice#isEnabledParameters() isEnabledParameters} list.
* @param elements iterable of isEnabledParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder isEnabledParameters(Iterable extends Advice.AdviceParameter> elements) {
isEnabledParametersBuilder = ImmutableList.builder();
return addAllIsEnabledParameters(elements);
}
/**
* Adds elements to {@link Advice#isEnabledParameters() isEnabledParameters} list.
* @param elements iterable of isEnabledParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllIsEnabledParameters(Iterable extends Advice.AdviceParameter> elements) {
isEnabledParametersBuilder.addAll(elements);
return this;
}
/**
* Adds one element to {@link Advice#onBeforeParameters() onBeforeParameters} list.
* @param element onBeforeParameters element
* @return {@code this} builder for chained invocation
*/
public final Builder addOnBeforeParameters(Advice.AdviceParameter element) {
onBeforeParametersBuilder.add(element);
return this;
}
/**
* Adds elements to {@link Advice#onBeforeParameters() onBeforeParameters} list.
* @param elements array of onBeforeParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addOnBeforeParameters(Advice.AdviceParameter... elements) {
onBeforeParametersBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link Advice#onBeforeParameters() onBeforeParameters} list.
* @param elements iterable of onBeforeParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder onBeforeParameters(Iterable extends Advice.AdviceParameter> elements) {
onBeforeParametersBuilder = ImmutableList.builder();
return addAllOnBeforeParameters(elements);
}
/**
* Adds elements to {@link Advice#onBeforeParameters() onBeforeParameters} list.
* @param elements iterable of onBeforeParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllOnBeforeParameters(Iterable extends Advice.AdviceParameter> elements) {
onBeforeParametersBuilder.addAll(elements);
return this;
}
/**
* Adds one element to {@link Advice#onReturnParameters() onReturnParameters} list.
* @param element onReturnParameters element
* @return {@code this} builder for chained invocation
*/
public final Builder addOnReturnParameters(Advice.AdviceParameter element) {
onReturnParametersBuilder.add(element);
return this;
}
/**
* Adds elements to {@link Advice#onReturnParameters() onReturnParameters} list.
* @param elements array of onReturnParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addOnReturnParameters(Advice.AdviceParameter... elements) {
onReturnParametersBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link Advice#onReturnParameters() onReturnParameters} list.
* @param elements iterable of onReturnParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder onReturnParameters(Iterable extends Advice.AdviceParameter> elements) {
onReturnParametersBuilder = ImmutableList.builder();
return addAllOnReturnParameters(elements);
}
/**
* Adds elements to {@link Advice#onReturnParameters() onReturnParameters} list.
* @param elements iterable of onReturnParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllOnReturnParameters(Iterable extends Advice.AdviceParameter> elements) {
onReturnParametersBuilder.addAll(elements);
return this;
}
/**
* Adds one element to {@link Advice#onThrowParameters() onThrowParameters} list.
* @param element onThrowParameters element
* @return {@code this} builder for chained invocation
*/
public final Builder addOnThrowParameters(Advice.AdviceParameter element) {
onThrowParametersBuilder.add(element);
return this;
}
/**
* Adds elements to {@link Advice#onThrowParameters() onThrowParameters} list.
* @param elements array of onThrowParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addOnThrowParameters(Advice.AdviceParameter... elements) {
onThrowParametersBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link Advice#onThrowParameters() onThrowParameters} list.
* @param elements iterable of onThrowParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder onThrowParameters(Iterable extends Advice.AdviceParameter> elements) {
onThrowParametersBuilder = ImmutableList.builder();
return addAllOnThrowParameters(elements);
}
/**
* Adds elements to {@link Advice#onThrowParameters() onThrowParameters} list.
* @param elements iterable of onThrowParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllOnThrowParameters(Iterable extends Advice.AdviceParameter> elements) {
onThrowParametersBuilder.addAll(elements);
return this;
}
/**
* Adds one element to {@link Advice#onAfterParameters() onAfterParameters} list.
* @param element onAfterParameters element
* @return {@code this} builder for chained invocation
*/
public final Builder addOnAfterParameters(Advice.AdviceParameter element) {
onAfterParametersBuilder.add(element);
return this;
}
/**
* Adds elements to {@link Advice#onAfterParameters() onAfterParameters} list.
* @param elements array of onAfterParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addOnAfterParameters(Advice.AdviceParameter... elements) {
onAfterParametersBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link Advice#onAfterParameters() onAfterParameters} list.
* @param elements iterable of onAfterParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder onAfterParameters(Iterable extends Advice.AdviceParameter> elements) {
onAfterParametersBuilder = ImmutableList.builder();
return addAllOnAfterParameters(elements);
}
/**
* Adds elements to {@link Advice#onAfterParameters() onAfterParameters} list.
* @param elements iterable of onAfterParameters elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllOnAfterParameters(Iterable extends Advice.AdviceParameter> elements) {
onAfterParametersBuilder.addAll(elements);
return this;
}
/**
* Initializes value for {@link Advice#reweavable() reweavable}.
* @param reweavable value for reweavable
* @return {@code this} builder for chained invocation
*/
public final Builder reweavable(boolean reweavable) {
this.reweavable = reweavable;
initBits &= ~INIT_BIT_REWEAVABLE;
return this;
}
/**
* Builds new {@link org.glowroot.agent.weaving.ImmutableAdvice ImmutableAdvice}.
* @return immutable instance of Advice
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableAdvice build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableAdvice(
pointcut,
adviceType,
pointcutDeclaringClassName,
pointcutTargetClassName,
pointcutDeclaringClassNamePattern,
pointcutTargetClassNamePattern,
pointcutMethodNamePattern,
travelerType,
isEnabledAdvice,
onBeforeAdvice,
onReturnAdvice,
onThrowAdvice,
onAfterAdvice,
isEnabledParametersBuilder.build(),
onBeforeParametersBuilder.build(),
onReturnParametersBuilder.build(),
onThrowParametersBuilder.build(),
onAfterParametersBuilder.build(),
reweavable);
}
private boolean pointcutIsSet() {
return (initBits & INIT_BIT_POINTCUT) == 0;
}
private boolean adviceTypeIsSet() {
return (initBits & INIT_BIT_ADVICE_TYPE) == 0;
}
private boolean pointcutDeclaringClassNameIsSet() {
return (initBits & INIT_BIT_POINTCUT_DECLARING_CLASS_NAME) == 0;
}
private boolean reweavableIsSet() {
return (initBits & INIT_BIT_REWEAVABLE) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!pointcutIsSet()) attributes.add("pointcut");
if (!adviceTypeIsSet()) attributes.add("adviceType");
if (!pointcutDeclaringClassNameIsSet()) attributes.add("pointcutDeclaringClassName");
if (!reweavableIsSet()) attributes.add("reweavable");
return "Cannot build Advice, some of required attributes are not set " + attributes;
}
}
}