Why did I get a “no” warning?

Why the following code:

pointcut callsToList() : call(* List.*(..)); before(List l) : callsToList() && target(l) { System.out.println("cool"); } 

generates the following warning:

advice defined in org.eclipse.ajdt.examples.ListAdvice does not apply [Xlint: adviceDidNotMatch]

I work in Eclipse. I installed the eclipse aspectj plugin and of course my project is an aspectj project.

Edit: Moreover, I started with a working example provided by the ajdt plugin:

 pointcut callsToBeginTask() : call(void IProgressMonitor.beginTask(..)); before() : callsToBeginTask() { System.out.println("cool"); }; 

I see no difference except that this example works without warning ...

+6
java aop aspectj ajdt
source share
2 answers

If you want AspectJ to work under OSGi, you should use Equinox Aspects (aka Equinox Weaving). This is a load time loading form that works with osgi class loaders.

This tutorial is a bit outdated, but you need to start:

http://www.eclipse.org/equinox/incubator/aspects/equinox-aspects-quick-start.php

When your aspects are focused on the same project, you do not need Equinox Aspects. Regular weaving of compilation times will be done, but to span multiple packages / plugins this will not work.

+3
source share

My guess is that since List is an interface and you want to combine calls with all expandable classes, you will need to use this syntax:

 pointcut callsToList() : call(* List+.*(..)); 

Update: OK, I got it to work with this version:

 pointcut callsToList(List list) : call(* java.util.List+.*(..)) && target(list); Object around(List l) : callsToList(l) { // code here } 

This also works:

 before(List l) : callsToList(l) { // code here } 
+2
source share

All Articles