MengZhi
MengZhi

Reputation: 51

How to get annotation value from AnnotationDescription.Loadable in Bytebuddy

I want get annotation value form a specific annotation, such as @Callcount, which has a field named key.

 MethodList<MethodDescription.InDefinedShape> methods = typeDefinition.getDeclaredMethods();
    for (MethodDescription.InDefinedShape method : methods) {
        AnnotationDescription.Loadable<CalledCount> callCountAnno;
        if ((callCountAnno = method.getDeclaredAnnotations().ofType(CalledCount.class)) != null) {
           callCountAnno.getValue(?);//how can i do here?
        }
    }

i don't know how to build the parameter of method callCountAnno.getValue(), what i shoud do?

Upvotes: 2

Views: 292

Answers (1)

Rafael Winterhalter
Rafael Winterhalter

Reputation: 44032

The easiest solution would be to load the annotation which allows you to access the value in a type-safe manner. You can do so via the load or loadSilent methods. Alternatively, you need to provide the propery you want to resolve. You can provide a loaded method reference via: MethodDescription.ForLoadedMethod( ... ).

Upvotes: 2

Related Questions