[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Catching/monitoring for Constructors

Hi all,
    I must have overlooked something in the documentation.  I want an aspect to be applied everytime a constructor is called (by way of a new ie String myString = new String().  After much fidgeting, I have developed this aspect:

public aspect ThreadTest {
    pointcut all():execution(*.new(..)) && !within(ThreadTest) && !within(Holder) &&!within(com.vladium..*);

    after(): all()
    {    
         System.out.println("Success");
    }
}


and thought it was working.  But then I tried to develop other parts of my project and was using the most generic pointcut I could think of:

public aspect ThreadTest {
    pointcut all():execution(* *.*(..)) && !within(ThreadTest) && !within(Holder) &&!within(com.vladium..*);  
   
    after(): all()
    {
        System.out.println("Success");
        }
    }
}


and noticed that the generic pointcut does not catch constructors.  Is there a special way to catch constructors?

I just noticed this and actually am more interested in catching calls to init(..) made by a Tomcat server, but general curiousity is getting the better of me.  Also, the calls to init() are sometimes returning null thisJoinPoint.getTarget() calls, so I figure a solution to the constructor mystery may help me. 

If you have any ideas on the init() or new() calls, let me know.

Thanks!
Tyler