Skip to main content



      Home
Home » Language IDEs » AspectJ » Advice on Constructors With Subclasses
Advice on Constructors With Subclasses [message #72172] Tue, 02 September 2008 19:30
Eclipse UserFriend
I am attempting to write some advice that will run only after the
construction has completely finished, i.e. after the an object has been
completely initialized.

An object can be created in any of the types in an inheritance tree, and
thus, I would like to advise all of the constructors, but only run the
advice once, after the object has been constructed.

This is probably easier to describe via an example:

public class A {
public A() {
System.out.println("init A");
}
}

public class B extends A {
public B() {
super();
System.out.println("init B");
}
}

public class C extends B {
public C() {
super();
System.out.println("init C");
}
}

after(A item) : execution(A+.new()) && target(item) {
System.out.println(thisJoinPoint.getSourceLocation());
}

public static void main(String[] args) {
C c = new C();
B b = new B();
}

The above code has the following output:
init A
A.java:3
init B
B.java:3
init C
C.java:3

init A
A.java:3
init B
B.java:3

What I am attempting to create is advice that will produce the following:
init A
init B
init C
C.java:3

init A
init B
B.java:3

i.e. Only run the advice after the object is completely created

I have tried a few approaches, including !within(A+.new()) and
!cflow(execution(A+.new()), but due to the way the compiler inlines the
super() calls, these approaches produce the same results as above.

Does anybody have any experience with this problem, and/or suggestions on
how to solve it?
Previous Topic:Exception using LTW with signed jars
Next Topic:Advice on Constructors With Subclasses
Goto Forum:
  


Current Time: Tue Jul 08 20:38:24 EDT 2025

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

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

Back to the top