Community
Participate
Working Groups
Hi, I have this small example aspect: public aspect SayWorldAspect { @AdviceName("afterReturningExecution") after() returning:execution(void HelloWorldClass.main(String[])){ System.out.println(" world!"); } } But ajc ignores the AdviceName annotation and generates a method named: ajc$afterReturning$offline_general_afteradvice_SayWorldAspect$1$fea4b20e I expected it to be equivialent to: @Aspect public class SayWorldAspect { @AfterReturning(pointcut="execution(void offline.general.afteradvice.HelloWorldClass.main(String[]))") public void afterReturning(JoinPoint jp){ System.out.println(" world!"); } } Karsten
clarify for 1.5.3
The javadoc for @AdviceName is: "Used to annotated code-style advice to name it Name is used by reflection api if present, may in future be used in adviceexecution() pcd. It is an error to use the @AdviceName annotation on an annotation-style advice declaration." (http://www.eclipse.org/aspectj/doc/released/aspectj5rt-api/org/aspectj/lang/annotation/AdviceName.html)
Does that mean it is simply not implemented yet? What would be the purpose of this annotation other then defining it on an Aspect Advice.
As the javadoc says (perhaps not too clearly...), the purpose of this annotation is to provide a name for the advice when it is accessed through the AspectJ reflection mechanism. It is not used to name the method generated in the code. Here is a program that shows how to use the AspectJ reflection mechanism: import org.aspectj.lang.annotation.AdviceName; import org.aspectj.lang.reflect.Advice; import org.aspectj.lang.reflect.AdviceKind; import org.aspectj.lang.reflect.AjType; import org.aspectj.lang.reflect.AjTypeSystem; public class C { public static void main(String[] args) { AjType t = AjTypeSystem.getAjType(MyAspect.class); Advice[] advice = t.getAdvice(); for (int i = 0; i < advice.length; i++) { Advice advice2 = advice[i]; System.err.println("Advice: ["+advice2+"] name="+advice2.getName()); } } } aspect MyAspect { before(): execution(* F*(..)) { } @AdviceName("AndysAdvice") after(): execution(* F*(..)) { } } You can see 'AdviceName' has been used to name the after advice, when run this prints: Advice: [before() : execution(* F*(..))] name= Advice: [@AdviceName("AndysAdvice") after() : execution(* F*(..))] name=AndysAdvice
Ahh ok. I expected that reflection would mean the usal java reflection. Because the name of an annotated advice is the same as the method name. Wouldn't it be possible to influence the method name by this annoation? It would make an annotated aspect more consistent with the aspect language.
moving to possible enhancement