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

io.opentelemetry.javaagent.tooling.muzzle.references.ClassRef Maven / Gradle / Ivy

The newest version!
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.javaagent.tooling.muzzle.references;

import static io.opentelemetry.javaagent.tooling.muzzle.references.ReferenceMergeUtil.mergeFields;
import static io.opentelemetry.javaagent.tooling.muzzle.references.ReferenceMergeUtil.mergeFlags;
import static io.opentelemetry.javaagent.tooling.muzzle.references.ReferenceMergeUtil.mergeMethods;
import static io.opentelemetry.javaagent.tooling.muzzle.references.ReferenceMergeUtil.mergeSet;

import java.util.Set;
import javax.annotation.Nullable;

/**
 * Represents a reference to a class used in the instrumentation advice or helper class code (or the
 * helper class itself).
 *
 * 

This class is used in the auto-generated {@code InstrumentationModule#getMuzzleReferences()} * method, it is not meant to be used directly by agent extension developers. */ public final class ClassRef { private final Set sources; private final Set flags; private final String className; private final String superClassName; private final Set interfaceNames; private final Set fields; private final Set methods; ClassRef( Set sources, Set flags, String className, String superClassName, Set interfaceNames, Set fields, Set methods) { this.sources = sources; this.flags = flags; this.className = className; this.superClassName = superClassName; this.interfaceNames = interfaceNames; this.fields = fields; this.methods = methods; } /** Start building a new {@linkplain ClassRef reference}. */ public static ClassRefBuilder builder(String className) { return new ClassRefBuilder(className); } /** Returns information about code locations where this class was referenced. */ public Set getSources() { return sources; } /** Returns modifier flags of this class. */ public Set getFlags() { return flags; } /** Returns the name of this class. */ public String getClassName() { return className; } /** Returns the name of the super class, if this class extends one; null otherwise. */ @Nullable public String getSuperClassName() { return superClassName; } /** Returns the set of interfaces implemented by this class. */ public Set getInterfaceNames() { return interfaceNames; } /** Returns the set of references to fields of this class. */ public Set getFields() { return fields; } /** Returns the set of references to methods of this class. */ public Set getMethods() { return methods; } /** * Create a new reference which combines this reference with another reference of the same type. * * @param anotherReference A reference to the same class. * @return a new {@linkplain ClassRef reference} which merges the two references. */ public ClassRef merge(ClassRef anotherReference) { if (!anotherReference.getClassName().equals(className)) { throw new IllegalStateException("illegal merge " + this + " != " + anotherReference); } String superName = null == this.superClassName ? anotherReference.superClassName : this.superClassName; return new ClassRef( mergeSet(sources, anotherReference.sources), mergeFlags(flags, anotherReference.flags), className, superName, mergeSet(interfaceNames, anotherReference.interfaceNames), mergeFields(fields, anotherReference.fields), mergeMethods(methods, anotherReference.methods)); } @Override public String toString() { String extendsPart = superClassName == null ? "" : " extends " + superClassName; String implementsPart = interfaceNames.isEmpty() ? "" : " implements " + String.join(", ", interfaceNames); return getClass().getSimpleName() + ": " + className + extendsPart + implementsPart; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy