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

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

There is a newer version: 0.14.9
Show 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.Preconditions;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.immutables.value.Generated;
import org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.Label;

/**
 * Immutable implementation of {@link WeavingMethodVisitor.CatchHandler}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableCatchHandler.builder()}. */ @Generated(from = "WeavingMethodVisitor.CatchHandler", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") final class ImmutableCatchHandler implements WeavingMethodVisitor.CatchHandler { private final Label catchStartLabel; private final ImmutableList advisors; private ImmutableCatchHandler( Label catchStartLabel, ImmutableList advisors) { this.catchStartLabel = catchStartLabel; this.advisors = advisors; } /** * @return The value of the {@code catchStartLabel} attribute */ @Override public Label catchStartLabel() { return catchStartLabel; } /** * @return The value of the {@code advisors} attribute */ @Override public ImmutableList advisors() { return advisors; } /** * Copy the current immutable object by setting a value for the {@link WeavingMethodVisitor.CatchHandler#catchStartLabel() catchStartLabel} 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 catchStartLabel * @return A modified copy of the {@code this} object */ public final ImmutableCatchHandler withCatchStartLabel(Label value) { if (this.catchStartLabel == value) return this; Label newValue = Preconditions.checkNotNull(value, "catchStartLabel"); return new ImmutableCatchHandler(newValue, this.advisors); } /** * Copy the current immutable object with elements that replace the content of {@link WeavingMethodVisitor.CatchHandler#advisors() advisors}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableCatchHandler withAdvisors(Advice... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableCatchHandler(this.catchStartLabel, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link WeavingMethodVisitor.CatchHandler#advisors() advisors}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of advisors elements to set * @return A modified copy of {@code this} object */ public final ImmutableCatchHandler withAdvisors(Iterable elements) { if (this.advisors == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableCatchHandler(this.catchStartLabel, newValue); } /** * This instance is equal to all instances of {@code ImmutableCatchHandler} 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 ImmutableCatchHandler && equalTo((ImmutableCatchHandler) another); } private boolean equalTo(ImmutableCatchHandler another) { return catchStartLabel.equals(another.catchStartLabel) && advisors.equals(another.advisors); } /** * Computes a hash code from attributes: {@code catchStartLabel}, {@code advisors}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + catchStartLabel.hashCode(); h += (h << 5) + advisors.hashCode(); return h; } /** * Prints the immutable value {@code CatchHandler} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("CatchHandler") .omitNullValues() .add("catchStartLabel", catchStartLabel) .add("advisors", advisors) .toString(); } /** * Creates an immutable copy of a {@link WeavingMethodVisitor.CatchHandler} 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 CatchHandler instance */ public static ImmutableCatchHandler copyOf(WeavingMethodVisitor.CatchHandler instance) { if (instance instanceof ImmutableCatchHandler) { return (ImmutableCatchHandler) instance; } return ImmutableCatchHandler.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableCatchHandler ImmutableCatchHandler}. *

   * ImmutableCatchHandler.builder()
   *    .catchStartLabel(org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.Label) // required {@link WeavingMethodVisitor.CatchHandler#catchStartLabel() catchStartLabel}
   *    .addAdvisors|addAllAdvisors(org.glowroot.instrumentation.engine.weaving.Advice) // {@link WeavingMethodVisitor.CatchHandler#advisors() advisors} elements
   *    .build();
   * 
* @return A new ImmutableCatchHandler builder */ public static ImmutableCatchHandler.Builder builder() { return new ImmutableCatchHandler.Builder(); } /** * Builds instances of type {@link ImmutableCatchHandler ImmutableCatchHandler}. * 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 = "WeavingMethodVisitor.CatchHandler", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_CATCH_START_LABEL = 0x1L; private long initBits = 0x1L; private Label catchStartLabel; private ImmutableList.Builder advisors = ImmutableList.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code CatchHandler} 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(WeavingMethodVisitor.CatchHandler instance) { Preconditions.checkNotNull(instance, "instance"); catchStartLabel(instance.catchStartLabel()); addAllAdvisors(instance.advisors()); return this; } /** * Initializes the value for the {@link WeavingMethodVisitor.CatchHandler#catchStartLabel() catchStartLabel} attribute. * @param catchStartLabel The value for catchStartLabel * @return {@code this} builder for use in a chained invocation */ public final Builder catchStartLabel(Label catchStartLabel) { this.catchStartLabel = Preconditions.checkNotNull(catchStartLabel, "catchStartLabel"); initBits &= ~INIT_BIT_CATCH_START_LABEL; return this; } /** * Adds one element to {@link WeavingMethodVisitor.CatchHandler#advisors() advisors} list. * @param element A advisors element * @return {@code this} builder for use in a chained invocation */ public final Builder addAdvisors(Advice element) { this.advisors.add(element); return this; } /** * Adds elements to {@link WeavingMethodVisitor.CatchHandler#advisors() advisors} list. * @param elements An array of advisors elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAdvisors(Advice... elements) { this.advisors.add(elements); return this; } /** * Sets or replaces all elements for {@link WeavingMethodVisitor.CatchHandler#advisors() advisors} list. * @param elements An iterable of advisors elements * @return {@code this} builder for use in a chained invocation */ public final Builder advisors(Iterable elements) { this.advisors = ImmutableList.builder(); return addAllAdvisors(elements); } /** * Adds elements to {@link WeavingMethodVisitor.CatchHandler#advisors() advisors} list. * @param elements An iterable of advisors elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllAdvisors(Iterable elements) { this.advisors.addAll(elements); return this; } /** * Builds a new {@link ImmutableCatchHandler ImmutableCatchHandler}. * @return An immutable instance of CatchHandler * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableCatchHandler build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableCatchHandler(catchStartLabel, advisors.build()); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList(); if ((initBits & INIT_BIT_CATCH_START_LABEL) != 0) attributes.add("catchStartLabel"); return "Cannot build CatchHandler, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy