Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » Getting the name of a local variable(Using reflection to acquire the name of a variable returned from a call)
Getting the name of a local variable [message #663134] Sun, 03 April 2011 23:51 Go to next message
Scott Ellis is currently offline Scott EllisFriend
Messages: 5
Registered: March 2011
Junior Member
I'm inserting debugging code into the middle of methods, or at least I want to. I found and example in AspectJ In Action that shows how to iterate each line of a method. But I was hoping to find a way to acquire the name of a variable that is assigned from the return of a method. This way I don't have to iterate a method--instead I would advise around targeted methods and do what I need to do.

Say the method that returns an object is: public Object MyClass.getFoo()

When other methods call MyClass.getFoo(), the code could look like this:

MyClass inst = new MyClass();
Object myObject = inst.getFoo();

I want to know how through AspectJ I can acquire the name of the local variable assigned to the return value of myInst.getFoo(), which in this case is "myObject".

Can this be done?


Re: Getting the name of a local variable [message #663140 is a reply to message #663134] Mon, 04 April 2011 03:35 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
Your love of AspectJ may be starting to wane when I tell you that this is not directly possible.

The reason is largely pragmatic. The JVM does not store names of local variables and so it is not possible to reference local variables outside of the method that defines them.

You can't directly capture assignments to local variables, but you can encapsulate the RHS of the assignment in a method call and capture that.
Re: Getting the name of a local variable [message #663295 is a reply to message #663140] Mon, 04 April 2011 14:51 Go to previous message
Scott Ellis is currently offline Scott EllisFriend
Messages: 5
Registered: March 2011
Junior Member
Talk about a buzz kill!

If the information isn't available from the JVM, then I can't blame AspectJ, can I?

Thanks for the information. Now that I know, I will have to alter my strategy. I'll probably alter the source code is subtle ways to make it easier to trace.
Previous Topic:Pointcut that depends on another pointcut
Next Topic:Virgo + Spring + ASPECTJ (load time weaving)
Goto Forum:
  


Current Time: Fri Dec 15 23:46:02 GMT 2017

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

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