[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Method call in super class within an around advice

Suppose you have:

class A { void foo () { ... } }
class B { void foo () { ... } }

then you can have an ITD that adds:

B.super_foo() { super.foo(); }

and then in the advice

around(B b) : ... {
  ...
  b.super_foo();
  ...
}

(obviously this is all pseudo/not-tested code, but it should be enough for you to get the idea)

hope this helps,

-- Éric


On May 31, 2010, at 5:30 PM, Holger King wrote:

> Hi Éric,
> 
> thank you for your hint! Could you make an example of what you mean. I do understand what Inter-type declarations (ITD) are. But how to call the super method.
> 
> Could you offer an example?
> 
> 
> -------- Original-Nachricht --------
>> Datum: Mon, 31 May 2010 16:13:51 -0400
>> Von: Eric Tanter <etanter@xxxxxxxxxxxxx>
>> An: aspectj-users@xxxxxxxxxxx
>> Betreff: Re: [aspectj-users] Method call in super class within an around advice
> 
>> Hi Holger,
>> 
>> I think you can't call super directly this way. The only alternative I can
>> think of is to introduce (with an ITD) a method that does the super call,
>> and call that method from the advice.
>> 
>> Hope this helps,
>> 
>> -- Éric
>> 
>> On May 31, 2010, at 4:10 PM, Holger King wrote:
>> 
>>> Hi,
>>> 
>>> I'm new to AspectJ - so I hope this is not a silly question!
>>> 
>>> The original question is: is there a way to call methods in
>> super-classes within an "around"-advice? If yes, how? ;)
>>> 
>>> I created a named PointCut using a certain parameter list to make them
>> available in the advice context later:
>>> 
>>> pointcut logAbstractGenerationContext(String type, String name, Map
>> params, AbstractGenerationContext abstractGenCtx) :
>>>               execution(public Printable
>> de.subpackage.subpackage.generate.AbstractGenerationContext+.getTemplate(String, String, Map) throws
>> IOException) &&
>>>               args(type, name, params) && this(abstractGenCtx);
>>> 
>>> 
>>> The advice is defined as follows:
>>> 
>>> Printable around(String type, String name, Map params,
>> AbstractGenerationContext abstractGenCtx) throws IOException :
>> logAbstractGenerationContext(type, name, params, abstractGenCtx) {
>>>   ...        
>>>   if(type == null)
>>>       return super.getTemplate(null, name, params);
>>>   ...
>>> }
>>> 
>>> But the parser always marks the "super" variable. I already tried some
>> flavors - but still no success.
>>> 
>>> Hint: the aspect has been declared "privileged" to allow access on
>> private or protected variables of the provided "AbstractGenerationContext"
>> instance.
>>> 
>>> Maybe, you can help me to solve that (easy) problem?
>>> -- 
>>> ----------------------------
>>> e-mail:
>>> HolgerKing@xxxxxxx
>>> 
>>> address:
>>> Eckenhofstr. 36
>>> 78713 Schramberg
>>> Germany
>>> 
>>> call:
>>> +49/(0) 74 22/5 34 93
>>> ----------------------------
>>> 
>>> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
>>> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>>> _______________________________________________
>>> 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
> 
> -- 
> ----------------------------
> e-mail:
> HolgerKing@xxxxxxx
> 
> address:
> Eckenhofstr. 36
> 78713 Schramberg
> Germany
> 
> call:
> +49/(0) 74 22/5 34 93
> ----------------------------
> 
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users