Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ajdt-dev] How to get the caller's details for a executionpointcut?

Hi Patil,
this is no AspectJ specific feature. You can call
Thread.getStrackTrace() to obtain the current stack trace inside java,
for example :

StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

The array of StackTraceElement returned is the current stack trace (from
your main() or Thread.run() up to your current position). From there,
you can see who is calling you.

Simone

PATIL Arvind wrote:
>
> Hi Andy,
>
> It would be helpful if you could give more details on ‘how to manually
> inspect stack trace’?
>
> Code snippet will be useful.
>
>  
>
> regards,
>
> arvind
>
> *=========================*
>
> *From:* ajdt-dev-bounces@xxxxxxxxxxx
> [mailto:ajdt-dev-bounces@xxxxxxxxxxx] *On Behalf Of *Andy Clement
> *Sent:* Tuesday, July 29, 2008 9:47 PM
> *To:* ajdt-dev@xxxxxxxxxxx
> *Subject:* Re: [ajdt-dev] How to get the caller's details for a
> executionpointcut?
>
>  
>
> You can only get the callers information if you advise the call-site. 
> If you advise the execution-site then it is too late (although you
> *could* 'manually' inspect the stack trace at that point to determine
> the caller).
>
> cheers,
> Andy.
>
> 2008/7/29 PATIL Arvind <Arvind_PATIL@xxxxxxxxxxxxxxxxx
> <mailto:Arvind_PATIL@xxxxxxxxxxxxxxxxx>>
>
> Hi,
>
> I have defined a pointcut of type /execution /for a method /test()/ in
> a class /ABC./
>
> And I have defined a before-advice which is supposed to show the file
> name and line number of the caller programs which invoke this method
> /ABC.test()/.
>
>  
>
> This is the advice code.
>
>  
>
>    static private void printParameters(JoinPoint jp) {
>
>                    System.out.println("Source: " +jp.getSourceLocation());
>
> }
>
>  
>
> However, this always displays the callee method details.
>
> How can I get the caller's details for a /execution /pointcut?
>
>  
>
> thanks,
>
> arvind
>
> -------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>  
>
>
> _______________________________________________
> ajdt-dev mailing list
> ajdt-dev@xxxxxxxxxxx <mailto:ajdt-dev@xxxxxxxxxxx>
> https://dev.eclipse.org/mailman/listinfo/ajdt-dev
>
>  
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ajdt-dev mailing list
> ajdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/ajdt-dev
>   


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



Back to the top