0

I have an annotation named Metric

@Target({ElementType.FIELD, ElementType.METHOD})
public @interface Metric {
    String name() default "";
}

I want to weave some logic when some methods with the @Metric annotation, like:

public class MethodWithMetricDemo{

    @Metric
    public void targetMethod(){
        // do some thing
    }
}

But how to match the class MethodWithMetricDemo in new AgentBuilder.Default().type(xxxxxxxxxxxxxxxx) ?

Sartner
  • 25
  • 2
  • 6

1 Answers1

0

You would need to match your type based on the method annotatation. As methods are inherited virtually, you would however need to travers the entire class hierarchy by hasSuperType(declaresMethod(isAnnotatedWith(...))). This is possible but rather expensive. If you choose to use such a matcher, you should probably restrict your matching to a given namespace.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192