I'm working with INRIA Spoon.
I have some dynamic methods invocations like the following one:
a.doSomething();
I can obtain to the variable access a
using the getTarget()
method of the CtInvocation
instance. My task is to generate code to store a
into file. To do so, I need the type and source position (class name, line, etc) of a
so I can generate code like logger.logSerializable(a, "My.Class:21")
or like logger.logDoubleArrayList(a, "My.otherClass:23)"
.
So far so good, I managed to do this just fine by acquiring the result of the getTarget
method of a CtInvocation
instance. However, when the invocation's target is equal this
, like for example:
doSomething(); // equivalent to -> this.doSomething();
the getTarget
returns null.
How can I get the this
variable access one given CtInvocation
is targeting?
By looking for targets (getTarget
) instance of CtThisAccess
or by directly processing CtThisAccess