Skip to main content

[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

Hi Anwar,
technically an around advice is NOT something inside the class you are weaving, so "this" does not refer to the instance of the weaved class and nor does "super". The fact that the current implementation of the AspectJ weaver usually places bytecode of your advices inside the target class is an implementation detail.

Following this idea, you can in fact write an around advice that weaves into multiple classes/methods, in which case referring to "super" would rise the question "super of who?". A typical around advice for tracing (the usual example) is something like :

Object around() : execution(* *.*(..)) {
   logger.trace("Executing " + thisJoinPoint........);
   Object ret = proceed();
   logger.trace("Finished ...... returning " + ret);
   return ret;
}

In this case, caling super is obviously impossible cause the advice is not bound to any specific class.

On the opposite, ITDs are type modifications, so they are bound to a specific class or interface. That is also why tou cannot write an ITD that gets weaved into multiple classes, if not using interfaces, and in that case the ITD is considered relative to the interface so "this" refers to "an instance implementing this interface", and only that interface methods are available.

Hope this helps,
Simone

2010/6/1 Anwar Rizal <anrizal05@xxxxxxxx>
Hi Eric/Holger,

I would say that it does make sense to have possibility to call super method in an advice without being obliged defining ITD as you described.

I wonder if there's any reason not to have this.

Cheers,
Anwar .

On 1 Jun 2010, at 02:06, Eric Tanter <etanter@xxxxxxxxxxxxx> wrote:

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

_______________________________________________
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


Back to the top