Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I got "advice has not been applied" warning?

Why does 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 has not been applied [Xlint:adviceDidNotMatch]

I am working with in Eclipse. I installed eclipse aspectj plugin and of course my project is an aspectj project.

Edit: Moreover I started from a working example provided by ajdt plugin:

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

I can't see any difference except the fact that this example works without warning ...

like image 1000
Manuel Selva Avatar asked Nov 04 '10 13:11

Manuel Selva


2 Answers

When you want AspectJ to work in an OSGi environment, you must use Equinox Aspects (aka Equinox Weaving). This is a form of Load time weaving that works with osgi classloaders.

This tutorial is a little out of date, but should get you started:

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

When your aspects are all targeted within the same project, you do not need Equinox Aspects. Regular compile time weaving will do, but to span multiple bundles/plugins, this will not work.

like image 103
Andrew Eisenberg Avatar answered Oct 07 '22 03:10

Andrew Eisenberg


My guess is that because List is an interface and you want to match calls to all extending Classes you would have 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
}
like image 24
Sean Patrick Floyd Avatar answered Oct 07 '22 03:10

Sean Patrick Floyd