Bug 154058 - @AdviceName is ignored in Aspect
Summary: @AdviceName is ignored in Aspect
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-16 11:04 EDT by Karsten Becker CLA
Modified: 2007-10-25 04:28 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karsten Becker CLA 2006-08-16 11:04:14 EDT
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
Comment 1 Andrew Clement CLA 2006-08-23 10:54:01 EDT
clarify for 1.5.3
Comment 2 Helen Beeken CLA 2006-09-11 06:44:28 EDT
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)
Comment 3 Karsten Becker CLA 2006-09-11 08:43:21 EDT
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.
Comment 4 Andrew Clement CLA 2006-09-11 09:21:29 EDT
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
Comment 5 Karsten Becker CLA 2006-09-11 17:18:08 EDT
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.
Comment 6 Andrew Clement CLA 2006-09-25 09:38:06 EDT
moving to possible enhancement