Hi James,
I think it still has a problem when multiple this constructors are
involved. In that case, the advice code would be executed twice (or more
times) depending on how many this() calls there are between constructor.

In this case the initialization pointcut comes in handy, cause it
matches the "first constructor called", so basically makes a distinction
between the originally called constructor and internal calls to this().

Simply changing it to :

public aspect CheckingWithSimplestAspectJEver {

    pointcut constructor(A inst) : initialization(A+.new(..)) && this(inst);
   
    after(A inst) : constructor(inst) {
        if
(inst.getClass().equals(thisJoinPointStaticPart.getSourceLocation().getWithinType()))
System.out.println("Done with " + inst.getClass().getSimpleName());
    }
}

Will avoid also the following situation :

public class C extends B {  
    public C() {
        System.out.println("I'm in C");
    }
    public C(String value) {
        this();
        System.out.println("In C with value");
    }
}

new C("Hello there");

I'm in A
I'm in B
I'm in C
In C with value
Done with C

Simone

James Elliott wrote:
> Simone,
>
> You are brilliant.
>
> This also works with construction via reflection, even within a
> delegate, and is orders of magnitude faster than your first solution.
>
> Thanks so much. =)
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>   


-- 
Simone Gianni
http://www.simonegianni.it/
CEO Semeru s.r.l.
Apache Committer

_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to