org.glowroot.weaving.AnalyzedMethod Maven / Gradle / Ivy
package org.glowroot.weaving;
import org.glowroot.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.shaded.google.common.base.MoreObjects;
import org.glowroot.shaded.google.common.base.Objects;
import org.glowroot.shaded.google.common.base.Preconditions;
import org.glowroot.shaded.google.common.collect.ImmutableList;
import org.glowroot.shaded.google.common.collect.Lists;
import java.util.Collection;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link AnalyzedMethodBase}.
*
* Use builder to create immutable instances:
* {@code AnalyzedMethod.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "AnalyzedMethodBase"})
@Immutable
final class AnalyzedMethod extends AnalyzedMethodBase {
private final String name;
private final ImmutableList parameterTypes;
private final String returnType;
private final int modifiers;
private final @Nullable String signature;
private final ImmutableList exceptions;
private final ImmutableList advisors;
private AnalyzedMethod(
String name,
ImmutableList parameterTypes,
String returnType,
int modifiers,
@Nullable String signature,
ImmutableList exceptions,
ImmutableList advisors) {
this.name = name;
this.parameterTypes = parameterTypes;
this.returnType = returnType;
this.modifiers = modifiers;
this.signature = signature;
this.exceptions = exceptions;
this.advisors = advisors;
}
/**
* {@inheritDoc}
* @return value of {@code name} attribute
*/
@JsonProperty("name")
@Override
public String name() {
return name;
}
/**
* {@inheritDoc}
* @return value of {@code parameterTypes} attribute
*/
@JsonProperty("parameterTypes")
@Override
public ImmutableList parameterTypes() {
return parameterTypes;
}
/**
* {@inheritDoc}
* @return value of {@code returnType} attribute
*/
@JsonProperty("returnType")
@Override
public String returnType() {
return returnType;
}
/**
* {@inheritDoc}
* @return value of {@code modifiers} attribute
*/
@JsonProperty("modifiers")
@Override
public int modifiers() {
return modifiers;
}
/**
* {@inheritDoc}
* @return value of {@code signature} attribute
*/
@JsonProperty("signature")
@Override
public String signature() {
return signature;
}
/**
* {@inheritDoc}
* @return value of {@code exceptions} attribute
*/
@JsonProperty("exceptions")
@Override
public ImmutableList exceptions() {
return exceptions;
}
/**
* {@inheritDoc}
* @return value of {@code advisors} attribute
*/
@JsonProperty("advisors")
@Override
public ImmutableList advisors() {
return advisors;
}
/**
* Copy current immutable object by setting value for {@link AnalyzedMethodBase#name() name}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for name
* @return modified copy of the {@code this} object
*/
public final AnalyzedMethod withName(String value) {
if (this.name == value) {
return this;
}
String newValue = Preconditions.checkNotNull(value);
return new AnalyzedMethod(
newValue,
this.parameterTypes,
this.returnType,
this.modifiers,
this.signature,
this.exceptions,
this.advisors);
}
/**
* Copy current immutable object with elements that replace content of {@link AnalyzedMethodBase#parameterTypes() parameterTypes}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final AnalyzedMethod withParameterTypes(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new AnalyzedMethod(
this.name,
newValue,
this.returnType,
this.modifiers,
this.signature,
this.exceptions,
this.advisors);
}
/**
* Copy current immutable object with elements that replace content of {@link AnalyzedMethodBase#parameterTypes() parameterTypes}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of parameterTypes elements to set
* @return modified copy of {@code this} object
*/
public final AnalyzedMethod withParameterTypes(Iterable elements) {
if (this.parameterTypes == elements) {
return this;
}
ImmutableList newValue = ImmutableList.copyOf(elements);
return new AnalyzedMethod(
this.name,
newValue,
this.returnType,
this.modifiers,
this.signature,
this.exceptions,
this.advisors);
}
/**
* Copy current immutable object by setting value for {@link AnalyzedMethodBase#returnType() returnType}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for returnType
* @return modified copy of the {@code this} object
*/
public final AnalyzedMethod withReturnType(String value) {
if (this.returnType == value) {
return this;
}
String newValue = Preconditions.checkNotNull(value);
return new AnalyzedMethod(
this.name,
this.parameterTypes,
newValue,
this.modifiers,
this.signature,
this.exceptions,
this.advisors);
}
/**
* Copy current immutable object by setting value for {@link AnalyzedMethodBase#modifiers() modifiers}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for modifiers
* @return modified copy of the {@code this} object
*/
public final AnalyzedMethod withModifiers(int value) {
if (this.modifiers == value) {
return this;
}
int newValue = value;
return new AnalyzedMethod(
this.name,
this.parameterTypes,
this.returnType,
newValue,
this.signature,
this.exceptions,
this.advisors);
}
/**
* Copy current immutable object by setting value for {@link AnalyzedMethodBase#signature() signature}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for signature, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final AnalyzedMethod withSignature(@Nullable String value) {
if (this.signature == value) {
return this;
}
@Nullable String newValue = value;
return new AnalyzedMethod(
this.name,
this.parameterTypes,
this.returnType,
this.modifiers,
newValue,
this.exceptions,
this.advisors);
}
/**
* Copy current immutable object with elements that replace content of {@link AnalyzedMethodBase#exceptions() exceptions}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final AnalyzedMethod withExceptions(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new AnalyzedMethod(
this.name,
this.parameterTypes,
this.returnType,
this.modifiers,
this.signature,
newValue,
this.advisors);
}
/**
* Copy current immutable object with elements that replace content of {@link AnalyzedMethodBase#exceptions() exceptions}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of exceptions elements to set
* @return modified copy of {@code this} object
*/
public final AnalyzedMethod withExceptions(Iterable elements) {
if (this.exceptions == elements) {
return this;
}
ImmutableList newValue = ImmutableList.copyOf(elements);
return new AnalyzedMethod(
this.name,
this.parameterTypes,
this.returnType,
this.modifiers,
this.signature,
newValue,
this.advisors);
}
/**
* Copy current immutable object with elements that replace content of {@link AnalyzedMethodBase#advisors() advisors}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final AnalyzedMethod withAdvisors(Advice... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new AnalyzedMethod(
this.name,
this.parameterTypes,
this.returnType,
this.modifiers,
this.signature,
this.exceptions,
newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link AnalyzedMethodBase#advisors() advisors}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of advisors elements to set
* @return modified copy of {@code this} object
*/
public final AnalyzedMethod withAdvisors(Iterable extends Advice> elements) {
if (this.advisors == elements) {
return this;
}
ImmutableList newValue = ImmutableList.copyOf(elements);
return new AnalyzedMethod(
this.name,
this.parameterTypes,
this.returnType,
this.modifiers,
this.signature,
this.exceptions,
newValue);
}
/**
* This instance is equal to instances of {@code AnalyzedMethod} with equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
return this == another
|| (another instanceof AnalyzedMethod && equalTo((AnalyzedMethod) another));
}
private boolean equalTo(AnalyzedMethod another) {
return name.equals(another.name)
&& parameterTypes.equals(another.parameterTypes)
&& returnType.equals(another.returnType)
&& modifiers == another.modifiers
&& Objects.equal(signature, another.signature)
&& exceptions.equals(another.exceptions)
&& advisors.equals(another.advisors);
}
/**
* Computes hash code from attributes: {@code name}, {@code parameterTypes}, {@code returnType}, {@code modifiers}, {@code signature}, {@code exceptions}, {@code advisors}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + name.hashCode();
h = h * 17 + parameterTypes.hashCode();
h = h * 17 + returnType.hashCode();
h = h * 17 + modifiers;
h = h * 17 + Objects.hashCode(signature);
h = h * 17 + exceptions.hashCode();
h = h * 17 + advisors.hashCode();
return h;
}
/**
* Prints immutable value {@code AnalyzedMethod{...}} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AnalyzedMethod")
.add("name", name)
.add("parameterTypes", parameterTypes)
.add("returnType", returnType)
.add("modifiers", modifiers)
.add("signature", signature)
.add("exceptions", exceptions)
.add("advisors", advisors)
.toString();
}
@JsonCreator
public static AnalyzedMethod fromAllAttributes(
@JsonProperty("name") @Nullable String name,
@JsonProperty("parameterTypes") @Nullable ImmutableList parameterTypes,
@JsonProperty("returnType") @Nullable String returnType,
@JsonProperty("modifiers") @Nullable Integer modifiers,
@JsonProperty("signature") @Nullable String signature,
@JsonProperty("exceptions") @Nullable ImmutableList exceptions,
@JsonProperty("advisors") @Nullable ImmutableList advisors) {
AnalyzedMethod.Builder builder = AnalyzedMethod.builder();
if (name != null) {
builder.name(name);
}
if (parameterTypes != null) {
builder.addAllParameterTypes(parameterTypes);
}
if (returnType != null) {
builder.returnType(returnType);
}
if (modifiers != null) {
builder.modifiers(modifiers);
}
if (signature != null) {
builder.signature(signature);
}
if (exceptions != null) {
builder.addAllExceptions(exceptions);
}
if (advisors != null) {
builder.addAllAdvisors(advisors);
}
return builder.build();
}
/**
* Creates immutable copy of {@link AnalyzedMethodBase}.
* 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 AnalyzedMethod instance
*/
static AnalyzedMethod copyOf(AnalyzedMethodBase instance) {
if (instance instanceof AnalyzedMethod) {
return (AnalyzedMethod) instance;
}
return AnalyzedMethod.builder()
.name(instance.name())
.addAllParameterTypes(instance.parameterTypes())
.returnType(instance.returnType())
.modifiers(instance.modifiers())
.signature(instance.signature())
.addAllExceptions(instance.exceptions())
.addAllAdvisors(instance.advisors())
.build();
}
/**
* Creates builder for {@link org.glowroot.weaving.AnalyzedMethod}.
* @return new AnalyzedMethod builder
*/
static AnalyzedMethod.Builder builder() {
return new AnalyzedMethod.Builder();
}
/**
* Builds instances of {@link org.glowroot.weaving.AnalyzedMethod}.
* Initialized attributes and then invoke {@link #build()} method to create
* immutable instance.
* Builder is not thread safe and generally should not be stored in field or collection,
* but used immediately to create instances.
*/
@NotThreadSafe
static final class Builder {
private static final long INITIALIZED_BITSET_ALL = 0x7;
private static final long INITIALIZED_BIT_NAME = 0x1L;
private static final long INITIALIZED_BIT_RETURN_TYPE = 0x2L;
private static final long INITIALIZED_BIT_MODIFIERS = 0x4L;
private static final long NONDEFAULT_BIT_SIGNATURE = 0x1L;
private long initializedBitset;
private long nondefaultBitset;
private @Nullable String name;
private ImmutableList.Builder parameterTypesBuilder = ImmutableList.builder();
private @Nullable String returnType;
private int modifiers;
private @Nullable String signature;
private ImmutableList.Builder exceptionsBuilder = ImmutableList.builder();
private ImmutableList.Builder advisorsBuilder = ImmutableList.builder();
private Builder() {}
/**
* Initializes value for {@link AnalyzedMethodBase#name() name}.
* @param name value for name
* @return {@code this} builder for chained invocation
*/
public final Builder name(String name) {
checkNotIsSet(nameIsSet(), "name");
this.name = Preconditions.checkNotNull(name);
initializedBitset |= INITIALIZED_BIT_NAME;
return this;
}
/**
* Adds one element to {@link AnalyzedMethodBase#parameterTypes() parameterTypes} list.
* @param element parameterTypes element
* @return {@code this} builder for chained invocation
*/
public final Builder addParameterTypes(String element) {
parameterTypesBuilder.add(element);
return this;
}
/**
* Adds elements to {@link AnalyzedMethodBase#parameterTypes() parameterTypes} list.
* @param elements array of parameterTypes elements
* @return {@code this} builder for chained invocation
*/
public final Builder addParameterTypes(String... elements) {
parameterTypesBuilder.add(elements);
return this;
}
/**
* Adds elements to {@link AnalyzedMethodBase#parameterTypes() parameterTypes} list.
* @param elements iterable of parameterTypes elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllParameterTypes(Iterable elements) {
parameterTypesBuilder.addAll(elements);
return this;
}
/**
* Initializes value for {@link AnalyzedMethodBase#returnType() returnType}.
* @param returnType value for returnType
* @return {@code this} builder for chained invocation
*/
public final Builder returnType(String returnType) {
checkNotIsSet(returnTypeIsSet(), "returnType");
this.returnType = Preconditions.checkNotNull(returnType);
initializedBitset |= INITIALIZED_BIT_RETURN_TYPE;
return this;
}
/**
* Initializes value for {@link AnalyzedMethodBase#modifiers() modifiers}.
* @param modifiers value for modifiers
* @return {@code this} builder for chained invocation
*/
public final Builder modifiers(int modifiers) {
checkNotIsSet(modifiersIsSet(), "modifiers");
this.modifiers = modifiers;
initializedBitset |= INITIALIZED_BIT_MODIFIERS;
return this;
}
/**
* Initializes value for {@link AnalyzedMethodBase#signature() signature}.
* @param signature value for signature, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder signature(@Nullable String signature) {
checkNotIsSet(signatureIsSet(), "signature");
this.signature = signature;
nondefaultBitset |= NONDEFAULT_BIT_SIGNATURE;
return this;
}
/**
* Adds one element to {@link AnalyzedMethodBase#exceptions() exceptions} list.
* @param element exceptions element
* @return {@code this} builder for chained invocation
*/
public final Builder addExceptions(String element) {
exceptionsBuilder.add(element);
return this;
}
/**
* Adds elements to {@link AnalyzedMethodBase#exceptions() exceptions} list.
* @param elements array of exceptions elements
* @return {@code this} builder for chained invocation
*/
public final Builder addExceptions(String... elements) {
exceptionsBuilder.add(elements);
return this;
}
/**
* Adds elements to {@link AnalyzedMethodBase#exceptions() exceptions} list.
* @param elements iterable of exceptions elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllExceptions(Iterable elements) {
exceptionsBuilder.addAll(elements);
return this;
}
/**
* Adds one element to {@link AnalyzedMethodBase#advisors() advisors} list.
* @param element advisors element
* @return {@code this} builder for chained invocation
*/
public final Builder addAdvisors(Advice element) {
advisorsBuilder.add(element);
return this;
}
/**
* Adds elements to {@link AnalyzedMethodBase#advisors() advisors} list.
* @param elements array of advisors elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAdvisors(Advice... elements) {
advisorsBuilder.add(elements);
return this;
}
/**
* Adds elements to {@link AnalyzedMethodBase#advisors() advisors} list.
* @param elements iterable of advisors elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllAdvisors(Iterable extends Advice> elements) {
advisorsBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.weaving.AnalyzedMethod}.
* @return immutable instance of AnalyzedMethod
*/
public org.glowroot.weaving.AnalyzedMethod build() {
checkRequiredAttributes();
return new AnalyzedMethod(
name,
parameterTypesBuilder.build(),
returnType,
modifiers,
signature,
exceptionsBuilder.build(),
advisorsBuilder.build());
}
private boolean signatureIsSet() {
return (nondefaultBitset & NONDEFAULT_BIT_SIGNATURE) != 0;
}
private boolean nameIsSet() {
return (initializedBitset & INITIALIZED_BIT_NAME) != 0;
}
private boolean returnTypeIsSet() {
return (initializedBitset & INITIALIZED_BIT_RETURN_TYPE) != 0;
}
private boolean modifiersIsSet() {
return (initializedBitset & INITIALIZED_BIT_MODIFIERS) != 0;
}
private void checkNotIsSet(boolean isSet, String name) {
if (isSet) {
throw new IllegalStateException("Builder of AnalyzedMethod is strict, attribute is already set: ".concat(name));
}
}
private void checkRequiredAttributes() {
if (initializedBitset != INITIALIZED_BITSET_ALL) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
Collection attributes = Lists.newArrayList();
if (!nameIsSet()) {
attributes.add("name");
}
if (!returnTypeIsSet()) {
attributes.add("returnType");
}
if (!modifiersIsSet()) {
attributes.add("modifiers");
}
return "Cannot build AnalyzedMethod, some of required attributes are not set " + attributes;
}
}
}