Search code examples
javaaopaspectjajdt

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 ...


Solution

  • 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.