Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Super's accessibility from within the advice

Hi -

It's correct that there are no join points for super calls.
However, a method declared in the aspect on a type can use
super calls, and you can use around advice to completely
replace a method execution join point.  So you could declare
a method that calls super and delegate to that in the
around advice that replaced a method.  Awkward, and probably
knows too much about the implementation, but feasible.
Code below.

Wes

P.S. - If you only want to replace the method-execution of 
the super class, then put around advice on that. You might
even use thisEnclosingJoinPointStaticPart to test whether
the caller is a subtype, and behave differently if so.

-------- output of ClassA.java
$ f=ClassA
$ aspectj-1.2 -classpath $ajrt $f.java 
  && java -classpath ".;$ajrt" -Drunning=true $f
ClassSuperA.a3()

$ aspectj-1.2 -classpath $ajrt $f.java 
  && java -classpath ".;$ajrt" -Drunning=false $f
ClassA.a3()
ClassSuperA.a1()
ClassA.a1()
ClassA.a2()

-------- ClassA.java
// remove "public" from ClassSuperA, include both in file

aspect A {
  static boolean running() {
     return Boolean.getBoolean("running");
  }
  void around(ClassA a) : this(a) && if(running())
      && execution(void a2()) {
    a.a2Replacement();
  }
  void ClassA.a2Replacement() {
    super.a3();
  }
}



> ------------Original Message------------
> From: "Marius M." <marin_marius@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Tue, Sep-28-2004 6:53 AM
> Subject: [aspectj-users] Super's accessibility from within the advice
>
> Hello,
> 
> I think the following action is not possible in
> AspectJ:
> 
> public class ClassSuperA {
> 
>    public void a1() {
>        a3();
>        System.out.println("ClassSuperA.a1()");
>    }
>      public void a3() {
>        System.out.println("ClassSuperA.a3()");
>    }
>       }
> 
> -----------------------------------------------------------
> 
> public class ClassA extends ClassSuperA{
> 
>    public void a1() {
>        System.out.println("ClassA.a1()");
>    }
>      public void a2() {
>        super.a1();
>        a1();
>        System.out.println("ClassA.a2()");
>    }
>      public void a3() {
>        System.out.println("ClassA.a3()");
>    }
> 
>      public static void main(String[] args) {
>        ClassA a = new ClassA();
>        a.a2();
>    }
> }
> 
> ----------------------------------------------------------
> 
> 
> Instead of calling super.a1(), I would like to have an
> advice for the execution of ClassA.a2() that calls
> ClassSuperA.a3(); That is, to advise ClassA.a2() with
> the functionality of ClassSuperA.a1().
> 
> Moreover, I think it is not possible to have access to
> the super's functionality of the advised object from
> within the advice.
> 
> 
> Thank you in advance for your opinions,
> Marius 
> 
> 
> 
> 
> 		
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 




Back to the top