Class AnnotationReflectionHelper
- java.lang.Object
-
- io.opentelemetry.instrumentation.api.annotation.support.AnnotationReflectionHelper
-
public class AnnotationReflectionHelper extends Object
Helper class for reflecting over annotations at runtime..
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <A extends Annotation,T>
Function<A,T>bindAnnotationElementMethod(MethodHandles.Lookup lookup, Class<? extends Annotation> annotationClass, String methodName, Class<T> returnClass)Binds a lambda of the functional interfaceFunction<A extends Annotation, T>to the element of anAnnotationclass by name which, when invoked with an instance of that annotation, will return the value of that element.static Class<? extends Annotation>forNameOrNull(ClassLoader classLoader, String className)Returns theClass<? extends Annotation>for the name of theAnnotationat runtime, otherwise returnsnull.
-
-
-
Method Detail
-
forNameOrNull
@Nullable public static Class<? extends Annotation> forNameOrNull(ClassLoader classLoader, String className)
Returns theClass<? extends Annotation>for the name of theAnnotationat runtime, otherwise returnsnull.
-
bindAnnotationElementMethod
public static <A extends Annotation,T> Function<A,T> bindAnnotationElementMethod(MethodHandles.Lookup lookup, Class<? extends Annotation> annotationClass, String methodName, Class<T> returnClass) throws Throwable
Binds a lambda of the functional interfaceFunction<A extends Annotation, T>to the element of anAnnotationclass by name which, when invoked with an instance of that annotation, will return the value of that element.For example, calling this method as follows:
Function<WithSpan, String> function = AnnotationReflectionHelper.bindAnnotationElementMethod( MethodHandles.lookup(), WithSpan.class, "value", String.class);is equivalent to the following Java code:
Function<WithSpan, String> function = WithSpan::value;- Type Parameters:
A- the type of the annotationT- the type of the annotation element- Parameters:
lookup- theMethodHandles.Lookupof the calling method, e.g.MethodHandles.lookup()annotationClass- theClassof theAnnotationmethodName- name of the annotation element methodreturnClass- type of the annotation element- Returns:
- Instance of
Function<Annotation, T>that is bound to the annotation element method - Throws:
NoSuchMethodException- the annotation element method was not foundThrowable- on failing to bind to the
-
-