[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] generate a StackTraceElement

> pointcut advices(JoinPoint jp): adviceexecution() && args(jp) && 
> within(...)

You can't bind the JoinPoint available in advice this way.

The code below works, logging all the adviceexecution 
join points.  

Valerio, do you instead want to log the join points being 
advised by the advice (in Main below, staticinitialization
and method-execution)?  If the pointcuts were named and
enumerable, you could do that, but it's awkward.  What's 
the use-case for this? Does the variable 
thisEnclosingJoinPointStaticPart help?

Wes

------------------ bug/Main.java
package bugs;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.SourceLocation;

/**
 */
public class Main {

    public static void main(String[] args) {
    }
}
aspect A {
    before() : within(Main) {
        System.out.println("before() " 
             + thisJoinPointStaticPart);
    }
}
aspect B implements IAspect {
    before() : adviceexecution() && !within(B) {
        log(thisJoinPointStaticPart);
    }
    void log(JoinPoint.StaticPart jp) {
        Signature sig = jp.getSignature();
        SourceLocation loc = jp.getSourceLocation();
        StackTraceElement ste = new StackTraceElement
            (sig.getDeclaringType().getName(), sig.getName(),
                loc.getFileName(), loc.getLine());
        System.out.println("BeforeAndAfter advice: "+ ste);
    }
}



> ------------Original Message------------
> From: Alexandru Popescu <alexandru.popescu@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Thu, Feb-10-2005 10:16 AM
> Subject: Re: [aspectj-users] generate a StackTraceElement
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> [quote Valerio Schiavoni::on 2/10/2005 6:44 PM]
> | On Thursday 10 February 2005 16:29, Alexandru Popescu wrote:
> |> The only available pointcut related to aspects is the 
> adviceexecution() but
> |> you cannot refine it further to match a before advice and after 
> advice.
> |
> | i don't need to refine it. It'd be enough to be able to "dump" the 
> stack
> | everytime an advice is executed.
> |
> | i tried with :
> |
> | pointcut Advices(): adviceexecution() && within(TraceAspect);
> |
> |     after(): Advices() {
> |           StackTraceElement ste = new StackTraceElement
> | (thisJoinPoint.getSignature().getDeclaringType().getName(),
> |                 thisJoinPoint.getSignature().getName(),
> |                 thisJoinPoint.getSourceLocation().getFileName(),
> |                 thisJoinPoint.getSourceLocation().getLine());
> |          System.out.println("BeforeAndAfter advice: "+ ste);
> | }
> |
> | so, if another advice is present, i want to get info about that join 
> point.
> | This is not possible? If so...why ?
> |
> | thanks,
> | valerio
> 
> I think what you are looking for is something in this direction:
> 
> pointcut advices(JoinPoint jp): adviceexecution() && args(jp) && 
> within(...)
> 
> - --
> :alex |.::the_mindstorm::.|
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.0 (MingW32)
> 
> iD8DBQFCC6RYTTDTje0R2dgRAp8wAJ9CWE3CG6X9PJ/ml/CIoMIonv/kIQCfZwYi
> dsqd+9JqRdFNJpKskcdhSHQ=
> =mH0+
> -----END PGP SIGNATURE-----
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>