Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » Advice not behaving properly(Is there a bug in the AJDT for Eclipse 3.6???)
Advice not behaving properly [message #662923] Fri, 01 April 2011 13:52 Go to next message
Robert Brown III is currently offline Robert Brown IIIFriend
Messages: 36
Registered: July 2009
Member
Greetings:

I have the following interface, with classes that implement it:

public interface IServiceProvider
{
public String getServiceName();
public String getProviderName();
public String getFriendlyServiceName();
public ServiceResult performService(Map<String,String> theParams);
public String getResponseType();
}

And I have the following aspect:

public aspect TestAspect
{
pointcut nameCatch() : call(String IServiceProvider.getFriendlyServiceName());

pointcut serviceCatch(Map<String,String> theMap) :
call(ServiceResult IServiceProvider.performService(Map<String,String>)) &&
args(theMap);

String around() : nameCatch() && !within(TestAspect)
{
System.out.println("Caught a Service Name");

return("MyService");
}

ServiceResult around(Map<String,String> theMap) : serviceCatch(theMap)
&& !within(TestAspect)
{
System.out.println("A Service was called!");

return(proceed(theMap));
}


void around() : call(void PrintStream.println(String))
&& !within(TestAspect) {
System.out.println("Hi from HelloAspect ;-)");
}

}

For some reason, the around advice for the nameCatch() pointcut does not seem to be properly advising the getFriendlyServiceName() method. In Eclipse I get a warning saying that "advice was not applied" and that it doesn't match anything. It also does not engage when I run my test application.

But my pointcut is pretty straightforward and is in the proper syntax for its method! Unless I am wrong (please let me know if I am!) the pointcut was properly formed and should advise the getFriendlyServiceName() method.

Worse: it seems like none of the get methods within the interface can be advised. When I change the nameCatch() pointcut to use any of the get methods in ISereviceProvider, the advice simply doesn't work.

All other advice within the aspect works properly. It seems that, for the IServiceProvider interface, advice only works for the performService() method.

Have I found a bug in AJDT? Or is it an AspectJ bug?

Someone please advise (no pun intended... ).
Re: Advice not behaving properly [message #662968 is a reply to message #662923] Fri, 01 April 2011 15:51 Go to previous message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
Without seeing the rest of your code, it's hard to say exactly what's happening here. You can try the following:

Instead of this:
pointcut nameCatch() : call(String IServiceProvider.getFriendlyServiceName());


Try this:
pointcut nameCatch() : execution(public String IServiceProvider+.getFriendlyServiceName());


Notice in particular that this uses execution, not call. in general, I find execution to be better behaved since it operates from inside the method itself (think of it as the new first line to the method itself), whereas call works on the call site. If the call site is in a third party library, then it won't get woven (unless you explicitly put it on the in path).


Previous Topic:If I use inter-type declarations should I use only compile-time weaving? (ajc compiler)
Next Topic:Pointcut that depends on another pointcut
Goto Forum:
  


Current Time: Sun Dec 17 13:45:25 GMT 2017

Powered by FUDForum. Page generated in 0.01382 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software