Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm looking for a pointcut that matches method executions in classes that subclass a class with a specific annotation. The excellent AspectJ cheat sheet helped me to create the following pointcut:

within(@my.own.annotations.AnnotationToMatch *) && execution(* *(..))

This matches all method calls of a class A that carries the @AnnotationToMatch, but not method of a class B that extends A. How can I match both?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
376 views
Welcome To Ask or Share your Answers For Others

1 Answer

public aspect AnnotatedParentPointcutAspect {   

//introducing empty marker interface
declare parents : (@MyAnnotation *) implements TrackedParentMarker;

public pointcut p1() : execution(* TrackedParentMarker+.*(..));

before(): p1(){
    System.out.println("Crosscutted method: "
            +thisJoinPointStaticPart.getSignature().getDeclaringTypeName()
            +"." 
            +thisJoinPointStaticPart.getSignature().getName());
}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...