Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] due to interface not advised

I see.  When the aspect is compiled, the reference to 'Context' will
be resolved to either one or the other (your interface or your
implementation - depending on what the aspect can see) and from then
on it will only match on that.  It won't be re-resolved if the aspect
is used in a different configuration.  If you need it to work with
both, you probably need something more like this:

after( Object con ) : selectSingletons() && this(con) && within(*Context*) {
}

and then in your advice you can work out what you are dealing with
(the interface or the implementation).

cheers,
Andy

2009/5/12 Michael Rogger <Michael.Rogger@xxxxxxx>:
> Thank you very much for your fast answer!
>
> Your example works fine for me, I think this has maybe something to do
> with the fact that:
> -Context interface and Context implementation have the same name
> (different packages and different projects)
> -Interfaces and Implementations are strictly decoupled (both in seperate
> projects)
> -aspectj is used using maven-plugins and compiling aspects into a jar,
> afterwards the aspects are applied to the differents projects
>
> So maybe aspectj has problems with that?
>
> thank you
> Michael
>
> Andy Clement schrieb:
>> Hi Michael,
>>
>> i dont quite follow - can you flesh out the example?  I just wrote:
>>
>> ---A.java---
>> interface Context {}
>> class ContextImpl implements Context {}
>>
>> aspect X {
>>   pointcut selectSingletons(): execution(* d*(..));
>>
>>   after(Context con): selectSingletons() && this(con) {
>>   }
>> }
>>
>> class A {
>>   Context doSomething() { return null; }
>>   ContextImpl doSomethingElse() { return null; }
>> }
>>
>> ----
>>
>> ajc -showWeaveInfo A.java
>> Join point 'method-execution(Context A.doSomething())' in Type 'A'
>> (A.java:11) advised by after advice from 'X' (A.java:6) [with runtime
>> test]
>> Join point 'method-execution(ContextImpl A.doSomethingElse())' in Type
>> 'A' (A.java:12) advised by after advice from 'X' (A.java:6) [with
>> runtime test]
>>
>> What is different between what I did and what you are saying?
>>
>> Andy.
>>
>> 2009/5/12 Michael Rogger <Michael.Rogger@xxxxxxx>:
>>> Hi,
>>>
>>> I have for example this aspect:
>>>
>>> after( Context con ) : selectSingletons() && this(con){
>>> ...
>>> }
>>>
>>> Where Context is an interface.
>>>
>>> -If a method has as return type Context (infterface) it will be advised
>>> by aspectj.
>>> -If a method has as return type Context (class which implements
>>> interface) it will not be advised
>>>
>>> In theory this should work, any ideas?
>>>
>>> thanks
>>>
>>> --
>>> Michael Rogger
>>> STI Innsbruck (www.sti-innsbruck.at)
>>> University of Innsbruck
>>> ICT Technologiepark
>>> Technikerstr. 21a
>>> 6020 Innsbruck, Austria
>>>
>>> T +43 512 507 96844
>>> F +43 512 507 9872
>>> E michael.rogger@xxxxxxx
>>>
>>> Skype michael.rogger.work
>>> _______________________________________________
>>> aspectj-users mailing list
>>> aspectj-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>>
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>>
>
>
> --
> Michael Rogger
> STI Innsbruck (www.sti-innsbruck.at)
> University of Innsbruck
> ICT Technologiepark
> Technikerstr. 21a
> 6020 Innsbruck, Austria
>
> T +43 512 507 96844
> F +43 512 507 9872
> E michael.rogger@xxxxxxx
>
> Skype michael.rogger.work
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top