io.opentelemetry.javaagent.extension.matcher.SafeExtendsClassMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opentelemetry-javaagent-extension-api Show documentation
Show all versions of opentelemetry-javaagent-extension-api Show documentation
Instrumentation of Java libraries using OpenTelemetry.
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.extension.matcher;
import static io.opentelemetry.javaagent.extension.matcher.SafeHasSuperTypeMatcher.safeGetSuperClass;
import io.opentelemetry.javaagent.extension.matcher.internal.DelegatingSuperTypeMatcher;
import javax.annotation.Nullable;
import net.bytebuddy.description.type.TypeDefinition;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
class SafeExtendsClassMatcher extends ElementMatcher.Junction.AbstractBase
implements DelegatingSuperTypeMatcher {
private final ElementMatcher matcher;
public SafeExtendsClassMatcher(ElementMatcher matcher) {
this.matcher = matcher;
}
@Override
public boolean matches(TypeDescription target) {
// We do not use foreach loop and iterator interface here because we need to catch exceptions
// in {@code getSuperClass} calls
TypeDefinition typeDefinition = target;
while (typeDefinition != null) {
if (matcher.matches(typeDefinition.asGenericType())) {
return true;
}
typeDefinition = safeGetSuperClass(typeDefinition);
}
return false;
}
@Override
public String toString() {
return "safeExtendsClass(" + matcher + ")";
}
@Override
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof SafeExtendsClassMatcher)) {
return false;
}
SafeExtendsClassMatcher other = (SafeExtendsClassMatcher) obj;
return matcher.equals(other.matcher);
}
@Override
public int hashCode() {
return matcher.hashCode();
}
@Override
public ElementMatcher> getDelegate() {
return matcher;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy