All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.glowroot.instrumentation.engine.weaving.ImmutablePointcutClass Maven / Gradle / Ivy

The newest version!
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.Objects;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.base.Preconditions;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.collect.ImmutableList;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.primitives.Booleans;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.glowroot.instrumentation.api.weaving.Advice;
import org.immutables.value.Generated;
import org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.Type;

/**
 * Immutable implementation of {@link InstrumentationDetail.PointcutClass}.
 * 

* Use the builder to create immutable instances: * {@code ImmutablePointcutClass.builder()}. */ @Generated(from = "InstrumentationDetail.PointcutClass", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") public final class ImmutablePointcutClass extends InstrumentationDetail.PointcutClass { private final Type type; private final Advice.Pointcut pointcut; private final ImmutableList methods; private final byte[] bytes; private final boolean collocateInClassLoader; private final @Nullable File jarFile; private ImmutablePointcutClass( Type type, Advice.Pointcut pointcut, ImmutableList methods, byte[] bytes, boolean collocateInClassLoader, @Nullable File jarFile) { this.type = type; this.pointcut = pointcut; this.methods = methods; this.bytes = bytes; this.collocateInClassLoader = collocateInClassLoader; this.jarFile = jarFile; } /** * @return The value of the {@code type} attribute */ @Override Type type() { return type; } /** * @return The value of the {@code pointcut} attribute */ @Override Advice.Pointcut pointcut() { return pointcut; } /** * @return The value of the {@code methods} attribute */ @Override ImmutableList methods() { return methods; } /** * @return A cloned {@code bytes} array */ @Override byte[] bytes() { return bytes.clone(); } /** * @return The value of the {@code collocateInClassLoader} attribute */ @Override boolean collocateInClassLoader() { return collocateInClassLoader; } /** * @return The value of the {@code jarFile} attribute */ @Override @Nullable File jarFile() { return jarFile; } /** * Copy the current immutable object by setting a value for the {@link InstrumentationDetail.PointcutClass#type() type} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for type * @return A modified copy of the {@code this} object */ public final ImmutablePointcutClass withType(Type value) { if (this.type == value) return this; Type newValue = Preconditions.checkNotNull(value, "type"); return new ImmutablePointcutClass(newValue, this.pointcut, this.methods, this.bytes, this.collocateInClassLoader, this.jarFile); } /** * Copy the current immutable object by setting a value for the {@link InstrumentationDetail.PointcutClass#pointcut() pointcut} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for pointcut * @return A modified copy of the {@code this} object */ public final ImmutablePointcutClass withPointcut(Advice.Pointcut value) { if (this.pointcut == value) return this; Advice.Pointcut newValue = Preconditions.checkNotNull(value, "pointcut"); return new ImmutablePointcutClass(this.type, newValue, this.methods, this.bytes, this.collocateInClassLoader, this.jarFile); } /** * Copy the current immutable object with elements that replace the content of {@link InstrumentationDetail.PointcutClass#methods() methods}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutablePointcutClass withMethods(InstrumentationDetail.PointcutMethod... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePointcutClass(this.type, this.pointcut, newValue, this.bytes, this.collocateInClassLoader, this.jarFile); } /** * Copy the current immutable object with elements that replace the content of {@link InstrumentationDetail.PointcutClass#methods() methods}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of methods elements to set * @return A modified copy of {@code this} object */ public final ImmutablePointcutClass withMethods(Iterable elements) { if (this.methods == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePointcutClass(this.type, this.pointcut, newValue, this.bytes, this.collocateInClassLoader, this.jarFile); } /** * Copy the current immutable object with elements that replace the content of {@link InstrumentationDetail.PointcutClass#bytes() bytes}. * The array is cloned before being saved as attribute values. * @param elements The non-null elements for bytes * @return A modified copy of {@code this} object */ public final ImmutablePointcutClass withBytes(byte... elements) { byte[] newValue = elements.clone(); return new ImmutablePointcutClass(this.type, this.pointcut, this.methods, newValue, this.collocateInClassLoader, this.jarFile); } /** * Copy the current immutable object by setting a value for the {@link InstrumentationDetail.PointcutClass#collocateInClassLoader() collocateInClassLoader} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for collocateInClassLoader * @return A modified copy of the {@code this} object */ public final ImmutablePointcutClass withCollocateInClassLoader(boolean value) { if (this.collocateInClassLoader == value) return this; return new ImmutablePointcutClass(this.type, this.pointcut, this.methods, this.bytes, value, this.jarFile); } /** * Copy the current immutable object by setting a value for the {@link InstrumentationDetail.PointcutClass#jarFile() jarFile} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for jarFile (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutablePointcutClass withJarFile(@Nullable File value) { if (this.jarFile == value) return this; return new ImmutablePointcutClass(this.type, this.pointcut, this.methods, this.bytes, this.collocateInClassLoader, value); } /** * This instance is equal to all instances of {@code ImmutablePointcutClass} 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 ImmutablePointcutClass && equalTo((ImmutablePointcutClass) another); } private boolean equalTo(ImmutablePointcutClass another) { return type.equals(another.type) && pointcut.equals(another.pointcut) && methods.equals(another.methods) && Arrays.equals(bytes, another.bytes) && collocateInClassLoader == another.collocateInClassLoader && Objects.equal(jarFile, another.jarFile); } /** * Computes a hash code from attributes: {@code type}, {@code pointcut}, {@code methods}, {@code bytes}, {@code collocateInClassLoader}, {@code jarFile}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + type.hashCode(); h += (h << 5) + pointcut.hashCode(); h += (h << 5) + methods.hashCode(); h += (h << 5) + Arrays.hashCode(bytes); h += (h << 5) + Booleans.hashCode(collocateInClassLoader); h += (h << 5) + Objects.hashCode(jarFile); return h; } /** * Prints the immutable value {@code PointcutClass} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("PointcutClass") .omitNullValues() .add("type", type) .add("pointcut", pointcut) .add("methods", methods) .add("bytes", Arrays.toString(bytes)) .add("collocateInClassLoader", collocateInClassLoader) .add("jarFile", jarFile) .toString(); } /** * Creates an immutable copy of a {@link InstrumentationDetail.PointcutClass} 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 PointcutClass instance */ public static ImmutablePointcutClass copyOf(InstrumentationDetail.PointcutClass instance) { if (instance instanceof ImmutablePointcutClass) { return (ImmutablePointcutClass) instance; } return ImmutablePointcutClass.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutablePointcutClass ImmutablePointcutClass}. *

   * ImmutablePointcutClass.builder()
   *    .type(org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.Type) // required {@link InstrumentationDetail.PointcutClass#type() type}
   *    .pointcut(org.glowroot.instrumentation.api.weaving.Advice.Pointcut) // required {@link InstrumentationDetail.PointcutClass#pointcut() pointcut}
   *    .addMethods|addAllMethods(org.glowroot.instrumentation.engine.weaving.InstrumentationDetail.PointcutMethod) // {@link InstrumentationDetail.PointcutClass#methods() methods} elements
   *    .bytes(byte) // required {@link InstrumentationDetail.PointcutClass#bytes() bytes}
   *    .collocateInClassLoader(boolean) // required {@link InstrumentationDetail.PointcutClass#collocateInClassLoader() collocateInClassLoader}
   *    .jarFile(java.io.File | null) // nullable {@link InstrumentationDetail.PointcutClass#jarFile() jarFile}
   *    .build();
   * 
* @return A new ImmutablePointcutClass builder */ public static ImmutablePointcutClass.Builder builder() { return new ImmutablePointcutClass.Builder(); } /** * Builds instances of type {@link ImmutablePointcutClass ImmutablePointcutClass}. * 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.PointcutClass", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_TYPE = 0x1L; private static final long INIT_BIT_POINTCUT = 0x2L; private static final long INIT_BIT_BYTES = 0x4L; private static final long INIT_BIT_COLLOCATE_IN_CLASS_LOADER = 0x8L; private long initBits = 0xfL; private Type type; private Advice.Pointcut pointcut; private ImmutableList.Builder methods = ImmutableList.builder(); private byte[] bytes; private boolean collocateInClassLoader; private File jarFile; private Builder() { } /** * Fill a builder with attribute values from the provided {@code PointcutClass} 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.PointcutClass instance) { Preconditions.checkNotNull(instance, "instance"); type(instance.type()); pointcut(instance.pointcut()); addAllMethods(instance.methods()); bytes(instance.bytes()); collocateInClassLoader(instance.collocateInClassLoader()); @Nullable File jarFileValue = instance.jarFile(); if (jarFileValue != null) { jarFile(jarFileValue); } return this; } /** * Initializes the value for the {@link InstrumentationDetail.PointcutClass#type() type} attribute. * @param type The value for type * @return {@code this} builder for use in a chained invocation */ public final Builder type(Type type) { this.type = Preconditions.checkNotNull(type, "type"); initBits &= ~INIT_BIT_TYPE; return this; } /** * Initializes the value for the {@link InstrumentationDetail.PointcutClass#pointcut() pointcut} attribute. * @param pointcut The value for pointcut * @return {@code this} builder for use in a chained invocation */ public final Builder pointcut(Advice.Pointcut pointcut) { this.pointcut = Preconditions.checkNotNull(pointcut, "pointcut"); initBits &= ~INIT_BIT_POINTCUT; return this; } /** * Adds one element to {@link InstrumentationDetail.PointcutClass#methods() methods} list. * @param element A methods element * @return {@code this} builder for use in a chained invocation */ public final Builder addMethods(InstrumentationDetail.PointcutMethod element) { this.methods.add(element); return this; } /** * Adds elements to {@link InstrumentationDetail.PointcutClass#methods() methods} list. * @param elements An array of methods elements * @return {@code this} builder for use in a chained invocation */ public final Builder addMethods(InstrumentationDetail.PointcutMethod... elements) { this.methods.add(elements); return this; } /** * Sets or replaces all elements for {@link InstrumentationDetail.PointcutClass#methods() methods} list. * @param elements An iterable of methods elements * @return {@code this} builder for use in a chained invocation */ public final Builder methods(Iterable elements) { this.methods = ImmutableList.builder(); return addAllMethods(elements); } /** * Adds elements to {@link InstrumentationDetail.PointcutClass#methods() methods} list. * @param elements An iterable of methods elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllMethods(Iterable elements) { this.methods.addAll(elements); return this; } /** * Initializes the value for the {@link InstrumentationDetail.PointcutClass#bytes() bytes} attribute. * @param bytes The elements for bytes * @return {@code this} builder for use in a chained invocation */ public final Builder bytes(byte... bytes) { this.bytes = bytes.clone(); initBits &= ~INIT_BIT_BYTES; return this; } /** * Initializes the value for the {@link InstrumentationDetail.PointcutClass#collocateInClassLoader() collocateInClassLoader} attribute. * @param collocateInClassLoader The value for collocateInClassLoader * @return {@code this} builder for use in a chained invocation */ public final Builder collocateInClassLoader(boolean collocateInClassLoader) { this.collocateInClassLoader = collocateInClassLoader; initBits &= ~INIT_BIT_COLLOCATE_IN_CLASS_LOADER; return this; } /** * Initializes the value for the {@link InstrumentationDetail.PointcutClass#jarFile() jarFile} attribute. * @param jarFile The value for jarFile (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final Builder jarFile(@Nullable File jarFile) { this.jarFile = jarFile; return this; } /** * Builds a new {@link ImmutablePointcutClass ImmutablePointcutClass}. * @return An immutable instance of PointcutClass * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutablePointcutClass build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutablePointcutClass(type, pointcut, methods.build(), bytes, collocateInClassLoader, jarFile); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList(); if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type"); if ((initBits & INIT_BIT_POINTCUT) != 0) attributes.add("pointcut"); if ((initBits & INIT_BIT_BYTES) != 0) attributes.add("bytes"); if ((initBits & INIT_BIT_COLLOCATE_IN_CLASS_LOADER) != 0) attributes.add("collocateInClassLoader"); return "Cannot build PointcutClass, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy