org.glowroot.instrumentation.engine.weaving.ImmutablePointcutMethod Maven / Gradle / Ivy
package org.glowroot.instrumentation.engine.weaving;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.base.MoreObjects;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.base.Preconditions;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.collect.ImmutableMap;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.immutables.value.Generated;
import org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.Type;
import org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.commons.Method;
/**
* Immutable implementation of {@link InstrumentationDetail.PointcutMethod}.
*
* Use the builder to create immutable instances:
* {@code ImmutablePointcutMethod.builder()}.
*/
@Generated(from = "InstrumentationDetail.PointcutMethod", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutablePointcutMethod
extends InstrumentationDetail.PointcutMethod {
private final String name;
private final String descriptor;
private final ImmutableSet annotationTypes;
private final ImmutableMap bindAnnotations;
private transient final Method toAsmMethod;
private ImmutablePointcutMethod(
String name,
String descriptor,
ImmutableSet annotationTypes,
ImmutableMap bindAnnotations) {
this.name = name;
this.descriptor = descriptor;
this.annotationTypes = annotationTypes;
this.bindAnnotations = bindAnnotations;
this.toAsmMethod = Preconditions.checkNotNull(super.toAsmMethod(), "toAsmMethod");
}
/**
* @return The value of the {@code name} attribute
*/
@Override
String name() {
return name;
}
/**
* @return The value of the {@code descriptor} attribute
*/
@Override
String descriptor() {
return descriptor;
}
/**
* @return The value of the {@code annotationTypes} attribute
*/
@Override
ImmutableSet annotationTypes() {
return annotationTypes;
}
/**
* @return The value of the {@code bindAnnotations} attribute
*/
@Override
ImmutableMap bindAnnotations() {
return bindAnnotations;
}
/**
* @return The computed-at-construction value of the {@code toAsmMethod} attribute
*/
@Override
Method toAsmMethod() {
return toAsmMethod;
}
/**
* Copy the current immutable object by setting a value for the {@link InstrumentationDetail.PointcutMethod#name() name} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for name
* @return A modified copy of the {@code this} object
*/
public final ImmutablePointcutMethod withName(String value) {
String newValue = Preconditions.checkNotNull(value, "name");
if (this.name.equals(newValue)) return this;
return new ImmutablePointcutMethod(newValue, this.descriptor, this.annotationTypes, this.bindAnnotations);
}
/**
* Copy the current immutable object by setting a value for the {@link InstrumentationDetail.PointcutMethod#descriptor() descriptor} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for descriptor
* @return A modified copy of the {@code this} object
*/
public final ImmutablePointcutMethod withDescriptor(String value) {
String newValue = Preconditions.checkNotNull(value, "descriptor");
if (this.descriptor.equals(newValue)) return this;
return new ImmutablePointcutMethod(this.name, newValue, this.annotationTypes, this.bindAnnotations);
}
/**
* Copy the current immutable object with elements that replace the content of {@link InstrumentationDetail.PointcutMethod#annotationTypes() annotationTypes}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutablePointcutMethod withAnnotationTypes(Type... elements) {
ImmutableSet newValue = ImmutableSet.copyOf(elements);
return new ImmutablePointcutMethod(this.name, this.descriptor, newValue, this.bindAnnotations);
}
/**
* Copy the current immutable object with elements that replace the content of {@link InstrumentationDetail.PointcutMethod#annotationTypes() annotationTypes}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of annotationTypes elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutablePointcutMethod withAnnotationTypes(Iterable extends Type> elements) {
if (this.annotationTypes == elements) return this;
ImmutableSet newValue = ImmutableSet.copyOf(elements);
return new ImmutablePointcutMethod(this.name, this.descriptor, newValue, this.bindAnnotations);
}
/**
* Copy the current immutable object by replacing the {@link InstrumentationDetail.PointcutMethod#bindAnnotations() bindAnnotations} map with the specified map.
* Nulls are not permitted as keys or values.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries The entries to be added to the bindAnnotations map
* @return A modified copy of {@code this} object
*/
public final ImmutablePointcutMethod withBindAnnotations(Map entries) {
if (this.bindAnnotations == entries) return this;
ImmutableMap newValue = ImmutableMap.copyOf(entries);
return new ImmutablePointcutMethod(this.name, this.descriptor, this.annotationTypes, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutablePointcutMethod} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof ImmutablePointcutMethod
&& equalTo((ImmutablePointcutMethod) another);
}
private boolean equalTo(ImmutablePointcutMethod another) {
return name.equals(another.name)
&& descriptor.equals(another.descriptor)
&& annotationTypes.equals(another.annotationTypes)
&& bindAnnotations.equals(another.bindAnnotations)
&& toAsmMethod.equals(another.toAsmMethod);
}
/**
* Computes a hash code from attributes: {@code name}, {@code descriptor}, {@code annotationTypes}, {@code bindAnnotations}, {@code toAsmMethod}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + name.hashCode();
h += (h << 5) + descriptor.hashCode();
h += (h << 5) + annotationTypes.hashCode();
h += (h << 5) + bindAnnotations.hashCode();
h += (h << 5) + toAsmMethod.hashCode();
return h;
}
/**
* Prints the immutable value {@code PointcutMethod} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PointcutMethod")
.omitNullValues()
.add("name", name)
.add("descriptor", descriptor)
.add("annotationTypes", annotationTypes)
.add("bindAnnotations", bindAnnotations)
.add("toAsmMethod", toAsmMethod)
.toString();
}
/**
* Creates an immutable copy of a {@link InstrumentationDetail.PointcutMethod} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance The instance to copy
* @return A copied immutable PointcutMethod instance
*/
public static ImmutablePointcutMethod copyOf(InstrumentationDetail.PointcutMethod instance) {
if (instance instanceof ImmutablePointcutMethod) {
return (ImmutablePointcutMethod) instance;
}
return ImmutablePointcutMethod.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutablePointcutMethod ImmutablePointcutMethod}.
*
* ImmutablePointcutMethod.builder()
* .name(String) // required {@link InstrumentationDetail.PointcutMethod#name() name}
* .descriptor(String) // required {@link InstrumentationDetail.PointcutMethod#descriptor() descriptor}
* .addAnnotationTypes|addAllAnnotationTypes(org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.Type) // {@link InstrumentationDetail.PointcutMethod#annotationTypes() annotationTypes} elements
* .putBindAnnotations|putAllBindAnnotations(int => org.glowroot.instrumentation.engine.weaving.InstrumentationDetail.BindAnnotation) // {@link InstrumentationDetail.PointcutMethod#bindAnnotations() bindAnnotations} mappings
* .build();
*
* @return A new ImmutablePointcutMethod builder
*/
public static ImmutablePointcutMethod.Builder builder() {
return new ImmutablePointcutMethod.Builder();
}
/**
* Builds instances of type {@link ImmutablePointcutMethod ImmutablePointcutMethod}.
* Initialize attributes and then invoke the {@link #build()} method to create an
* immutable instance.
* {@code Builder} is not thread-safe and generally should not be stored in a field or collection,
* but instead used immediately to create instances.
*/
@Generated(from = "InstrumentationDetail.PointcutMethod", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long INIT_BIT_DESCRIPTOR = 0x2L;
private long initBits = 0x3L;
private String name;
private String descriptor;
private ImmutableSet.Builder annotationTypes = ImmutableSet.builder();
private ImmutableMap.Builder bindAnnotations = ImmutableMap.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code PointcutMethod} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(InstrumentationDetail.PointcutMethod instance) {
Preconditions.checkNotNull(instance, "instance");
name(instance.name());
descriptor(instance.descriptor());
addAllAnnotationTypes(instance.annotationTypes());
putAllBindAnnotations(instance.bindAnnotations());
return this;
}
/**
* Initializes the value for the {@link InstrumentationDetail.PointcutMethod#name() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
public final Builder name(String name) {
this.name = Preconditions.checkNotNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes the value for the {@link InstrumentationDetail.PointcutMethod#descriptor() descriptor} attribute.
* @param descriptor The value for descriptor
* @return {@code this} builder for use in a chained invocation
*/
public final Builder descriptor(String descriptor) {
this.descriptor = Preconditions.checkNotNull(descriptor, "descriptor");
initBits &= ~INIT_BIT_DESCRIPTOR;
return this;
}
/**
* Adds one element to {@link InstrumentationDetail.PointcutMethod#annotationTypes() annotationTypes} set.
* @param element A annotationTypes element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAnnotationTypes(Type element) {
this.annotationTypes.add(element);
return this;
}
/**
* Adds elements to {@link InstrumentationDetail.PointcutMethod#annotationTypes() annotationTypes} set.
* @param elements An array of annotationTypes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAnnotationTypes(Type... elements) {
this.annotationTypes.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link InstrumentationDetail.PointcutMethod#annotationTypes() annotationTypes} set.
* @param elements An iterable of annotationTypes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder annotationTypes(Iterable extends Type> elements) {
this.annotationTypes = ImmutableSet.builder();
return addAllAnnotationTypes(elements);
}
/**
* Adds elements to {@link InstrumentationDetail.PointcutMethod#annotationTypes() annotationTypes} set.
* @param elements An iterable of annotationTypes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllAnnotationTypes(Iterable extends Type> elements) {
this.annotationTypes.addAll(elements);
return this;
}
/**
* Put one entry to the {@link InstrumentationDetail.PointcutMethod#bindAnnotations() bindAnnotations} map.
* @param key The key in the bindAnnotations map
* @param value The associated value in the bindAnnotations map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putBindAnnotations(int key, InstrumentationDetail.BindAnnotation value) {
this.bindAnnotations.put(key, value);
return this;
}
/**
* Put one entry to the {@link InstrumentationDetail.PointcutMethod#bindAnnotations() bindAnnotations} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putBindAnnotations(Map.Entry entry) {
this.bindAnnotations.put(entry);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link InstrumentationDetail.PointcutMethod#bindAnnotations() bindAnnotations} map. Nulls are not permitted
* @param entries The entries that will be added to the bindAnnotations map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder bindAnnotations(Map entries) {
this.bindAnnotations = ImmutableMap.builder();
return putAllBindAnnotations(entries);
}
/**
* Put all mappings from the specified map as entries to {@link InstrumentationDetail.PointcutMethod#bindAnnotations() bindAnnotations} map. Nulls are not permitted
* @param entries The entries that will be added to the bindAnnotations map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putAllBindAnnotations(Map entries) {
this.bindAnnotations.putAll(entries);
return this;
}
/**
* Builds a new {@link ImmutablePointcutMethod ImmutablePointcutMethod}.
* @return An immutable instance of PointcutMethod
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutablePointcutMethod build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutablePointcutMethod(name, descriptor, annotationTypes.build(), bindAnnotations.build());
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
if ((initBits & INIT_BIT_DESCRIPTOR) != 0) attributes.add("descriptor");
return "Cannot build PointcutMethod, some of required attributes are not set " + attributes;
}
}
}