Small renames for clarification
RENAME
javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/muzzle/InstrumentationClassPredicateTest.groovy
javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/muzzle/HelperClassPredicateTest.groovy
@@ -8,14 +8,14 @@ package io.opentelemetry.javaagent.tooling.muzzle
import spock.lang.Specification
import spock.lang.Unroll
-class InstrumentationClassPredicateTest extends Specification {
+class HelperClassPredicateTest extends Specification {
@Unroll
def "should collect references for #desc"() {
setup:
- def predicate = new InstrumentationClassPredicate({ it.startsWith("com.example.instrumentation.library") })
+ def predicate = new HelperClassPredicate({ it.startsWith("com.example.instrumentation.library") })
expect:
- predicate.isInstrumentationClass(className)
+ predicate.isHelperClass(className)
where:
desc | className
@@ -27,10 +27,10 @@ class InstrumentationClassPredicateTest extends Specification {
@Unroll
def "should not collect references for #desc"() {
setup:
- def predicate = new InstrumentationClassPredicate({ false })
+ def predicate = new HelperClassPredicate({ false })
expect:
- !predicate.isInstrumentationClass(className)
+ !predicate.isHelperClass(className)
where:
desc | className

RENAME
muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/InstrumentationClassPredicate.java
muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/HelperClassPredicate.java
@@ -7,7 +7,7 @@ package io.opentelemetry.javaagent.tooling.muzzle;
import java.util.function.Predicate;
-public final class InstrumentationClassPredicate {
+public final class HelperClassPredicate {
// javaagent instrumentation packages
private static final String JAVAAGENT_INSTRUMENTATION_PACKAGE =
"io.opentelemetry.javaagent.instrumentation.";
@@ -18,11 +18,10 @@ public final class InstrumentationClassPredicate {
private static final String LIBRARY_INSTRUMENTATION_PACKAGE = "io.opentelemetry.instrumentation.";
private static final String INSTRUMENTATION_API_PACKAGE = "io.opentelemetry.instrumentation.api.";
- private final Predicate<String> additionalLibraryInstrumentationPredicate;
+ private final Predicate<String> additionalLibraryHelperClassPredicate;
- public InstrumentationClassPredicate(
- Predicate<String> additionalLibraryInstrumentationPredicate) {
- this.additionalLibraryInstrumentationPredicate = additionalLibraryInstrumentationPredicate;
+ public HelperClassPredicate(Predicate<String> additionalLibraryHelperClassPredicate) {
+ this.additionalLibraryHelperClassPredicate = additionalLibraryHelperClassPredicate;
}
/**
@@ -37,17 +36,17 @@ public final class InstrumentationClassPredicate {
* <p>Aside from "standard" instrumentation helper class packages, instrumentation modules can
* pass an additional predicate to include instrumentation helper classes from 3rd party packages.
*/
- public boolean isInstrumentationClass(String className) {
- return isJavaagentInstrumentationClass(className)
- || isLibraryInstrumentationClass(className)
- || additionalLibraryInstrumentationPredicate.test(className);
+ public boolean isHelperClass(String className) {
+ return isJavaagentHelperClass(className)
+ || isLibraryHelperClass(className)
+ || additionalLibraryHelperClassPredicate.test(className);
}
- public boolean isProvidedByLibrary(String className) {
- return !isInstrumentationClass(className) && !isProvidedByJavaagent(className);
+ public boolean isLibraryClass(String className) {
+ return !isHelperClass(className) && !isBootstrapClass(className);
}
- private static boolean isProvidedByJavaagent(String className) {
+ private static boolean isBootstrapClass(String className) {
return className.startsWith(JAVAAGENT_API_PACKAGE)
|| className.startsWith(INSTRUMENTATION_API_PACKAGE)
|| className.startsWith("io.opentelemetry.javaagent.bootstrap.")
@@ -57,12 +56,12 @@ public final class InstrumentationClassPredicate {
|| className.startsWith("org.slf4j.");
}
- private static boolean isJavaagentInstrumentationClass(String className) {
+ private static boolean isJavaagentHelperClass(String className) {
return className.startsWith(JAVAAGENT_INSTRUMENTATION_PACKAGE)
&& !className.startsWith(JAVAAGENT_API_PACKAGE);
}
- private static boolean isLibraryInstrumentationClass(String className) {
+ private static boolean isLibraryHelperClass(String className) {
return className.startsWith(LIBRARY_INSTRUMENTATION_PACKAGE)
&& !className.startsWith(INSTRUMENTATION_API_PACKAGE);
}

MODIFY
muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java
muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java
@@ -105,7 +105,7 @@ final class ReferenceCollectingClassVisitor extends ClassVisitor {
return type;
}
- private final InstrumentationClassPredicate instrumentationClassPredicate;
+ private final HelperClassPredicate helperClassPredicate;
private final boolean isAdviceClass;
private final Map<String, ClassRef> references = new LinkedHashMap<>();
@@ -119,9 +119,9 @@ final class ReferenceCollectingClassVisitor extends ClassVisitor {
private Type refSourceType;
ReferenceCollectingClassVisitor(
- InstrumentationClassPredicate instrumentationClassPredicate, boolean isAdviceClass) {
+ HelperClassPredicate helperClassPredicate, boolean isAdviceClass) {
super(Opcodes.ASM7);
- this.instrumentationClassPredicate = instrumentationClassPredicate;
+ this.helperClassPredicate = helperClassPredicate;
this.isAdviceClass = isAdviceClass;
}
@@ -143,7 +143,7 @@ final class ReferenceCollectingClassVisitor extends ClassVisitor {
private void addExtendsReference(ClassRef ref) {
addReference(ref);
- if (instrumentationClassPredicate.isInstrumentationClass(ref.getClassName())) {
+ if (helperClassPredicate.isHelperClass(ref.getClassName())) {
helperSuperClasses.add(ref.getClassName());
}
}
@@ -157,7 +157,7 @@ final class ReferenceCollectingClassVisitor extends ClassVisitor {
references.put(ref.getClassName(), reference.merge(ref));
}
}
- if (instrumentationClassPredicate.isInstrumentationClass(ref.getClassName())) {
+ if (helperClassPredicate.isHelperClass(ref.getClassName())) {
helperClasses.add(ref.getClassName());
}
}

MODIFY
muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollector.java
muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollector.java
@@ -52,7 +52,7 @@ public final class ReferenceCollector {
private final VirtualFieldMappingsBuilderImpl virtualFieldMappingsBuilder =
new VirtualFieldMappingsBuilderImpl();
private final Set<String> visitedClasses = new HashSet<>();
- private final InstrumentationClassPredicate instrumentationClassPredicate;
+ private final HelperClassPredicate helperClassPredicate;
private final ClassLoader resourceLoader;
// only used by tests
@@ -62,8 +62,7 @@ public final class ReferenceCollector {
public ReferenceCollector(
Predicate<String> libraryInstrumentationPredicate, ClassLoader resourceLoader) {
- this.instrumentationClassPredicate =
- new InstrumentationClassPredicate(libraryInstrumentationPredicate);
+ this.helperClassPredicate = new HelperClassPredicate(libraryInstrumentationPredicate);
this.resourceLoader = resourceLoader;
}
@@ -73,7 +72,7 @@ public final class ReferenceCollector {
* implementation as a reference, traversing the graph of classes until a non-instrumentation
* (external) class is encountered.
*
- * @see InstrumentationClassPredicate
+ * @see HelperClassPredicate
*/
public void collectReferencesFromResource(HelperResource helperResource) {
if (!isSpiFile(helperResource.getApplicationPath())) {
@@ -118,7 +117,7 @@ public final class ReferenceCollector {
* encountered.
*
* @param adviceClassName Starting point for generating references.
- * @see InstrumentationClassPredicate
+ * @see HelperClassPredicate
*/
public void collectReferencesFromAdvice(String adviceClassName) {
visitClassesAndCollectReferences(singleton(adviceClassName), /* startsFromAdviceClass= */ true);
@@ -136,7 +135,7 @@ public final class ReferenceCollector {
try (InputStream in = getClassFileStream(visitedClassName)) {
// only start from method bodies for the advice class (skips class/method references)
ReferenceCollectingClassVisitor cv =
- new ReferenceCollectingClassVisitor(instrumentationClassPredicate, isAdviceClass);
+ new ReferenceCollectingClassVisitor(helperClassPredicate, isAdviceClass);
ClassReader reader = new ClassReader(in);
reader.accept(cv, ClassReader.SKIP_FRAMES);
@@ -146,7 +145,7 @@ public final class ReferenceCollector {
// Don't generate references created outside of the instrumentation package.
if (!visitedClasses.contains(refClassName)
- && instrumentationClassPredicate.isInstrumentationClass(refClassName)) {
+ && helperClassPredicate.isHelperClass(refClassName)) {
instrumentationQueue.add(refClassName);
}
addReference(refClassName, reference);
@@ -223,7 +222,7 @@ public final class ReferenceCollector {
for (Iterator<ClassRef> i = references.values().iterator(); i.hasNext(); ) {
ClassRef reference = i.next();
- if (instrumentationClassPredicate.isProvidedByLibrary(reference.getClassName())) {
+ if (helperClassPredicate.isLibraryClass(reference.getClassName())) {
// these are the references to library classes which need to be checked at runtime
continue;
}
@@ -258,7 +257,7 @@ public final class ReferenceCollector {
private Set<ClassRef> getHelperClassesWithLibrarySuperType() {
Set<ClassRef> helperClassesWithLibrarySuperType = new HashSet<>();
for (ClassRef reference : references.values()) {
- if (instrumentationClassPredicate.isInstrumentationClass(reference.getClassName())
+ if (helperClassPredicate.isHelperClass(reference.getClassName())
&& hasLibrarySuperType(reference.getClassName())) {
helperClassesWithLibrarySuperType.add(reference);
}
@@ -268,7 +267,7 @@ public final class ReferenceCollector {
private void addSuperTypesThatAreAlsoHelperClasses(
@Nullable String className, Set<ClassRef> superTypes) {
- if (className != null && instrumentationClassPredicate.isInstrumentationClass(className)) {
+ if (className != null && helperClassPredicate.isHelperClass(className)) {
ClassRef reference = references.get(className);
superTypes.add(reference);
@@ -284,7 +283,7 @@ public final class ReferenceCollector {
if (typeName == null || typeName.startsWith("java.")) {
return false;
}
- if (instrumentationClassPredicate.isProvidedByLibrary(typeName)) {
+ if (helperClassPredicate.isLibraryClass(typeName)) {
return true;
}
ClassRef reference = references.get(typeName);

MODIFY
muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceMatcher.java
muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceMatcher.java
@@ -35,7 +35,7 @@ public final class ReferenceMatcher {
Cache.newBuilder().setWeakKeys().build();
private final Map<String, ClassRef> references;
private final Set<String> helperClassNames;
- private final InstrumentationClassPredicate instrumentationClassPredicate;
+ private final HelperClassPredicate helperClassPredicate;
public static ReferenceMatcher of(InstrumentationModule instrumentationModule) {
return new ReferenceMatcher(
@@ -50,8 +50,7 @@ public final class ReferenceMatcher {
Predicate<String> libraryInstrumentationPredicate) {
this.references = references;
this.helperClassNames = new HashSet<>(helperClassNames);
- this.instrumentationClassPredicate =
- new InstrumentationClassPredicate(libraryInstrumentationPredicate);
+ this.helperClassPredicate = new HelperClassPredicate(libraryInstrumentationPredicate);
}
/**
@@ -109,7 +108,7 @@ public final class ReferenceMatcher {
*/
private List<Mismatch> checkMatch(ClassRef reference, TypePool typePool, ClassLoader loader) {
try {
- if (instrumentationClassPredicate.isInstrumentationClass(reference.getClassName())) {
+ if (helperClassPredicate.isHelperClass(reference.getClassName())) {
// make sure helper class is registered
if (!helperClassNames.contains(reference.getClassName())) {
return singletonList(new Mismatch.MissingClass(reference));

Small renames for clarification (#4294)