6

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

Manuel Selva
  • 18,554
  • 22
  • 89
  • 134
  • Maybe this is related to Eclipse/OSgi class loading policy ? How does aspectj work in order to hook the provided pointcuts ? – Manuel Selva Nov 04 '10 at 13:48
  • Can you show the code that should be weaved by the advice? – Espen Nov 04 '10 at 14:20
  • Not sure to understand your request. I want this advice to be called in an Eclipse application running several custom plugins. Thus the code I want to "analyze" is splitted across many plugins/packages/classes. – Manuel Selva Nov 04 '10 at 14:27

2 Answers2

3

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.

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
2

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
}
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • Your answer doesn't solve my issue. Moreover I started from a working example provided by ajdt plugin: pointcut callsToBeginTask() : call(void IProgressMonitor.beginTask(..)); before() : callsToBeginTask() {}; – Manuel Selva Nov 04 '10 at 13:44
  • This example doesn't generate any warning even if IProgressMonitor is an interface. – Manuel Selva Nov 04 '10 at 13:45
  • see my updated answer, this works for me. about the progressmonitor stuff: please put that in your question (or a separate question) if you want it answered. – Sean Patrick Floyd Nov 04 '10 at 14:27
  • So I guess you reproduced the same Issue than me ? Have you got an idea about why we need using around ?? According to the doc of aspectj it should work with before, isn't it ? Many thanks for your help. – Manuel Selva Nov 04 '10 at 14:50
  • I had all kinds of strange issues, but now it works, with before as well (see my update) – Sean Patrick Floyd Nov 04 '10 at 14:54