How to modify the parameters of a MethodInvocation node [message #247831] |
Wed, 19 September 2007 03:41  |
Eclipse User |
|
|
|
Originally posted by: qkevin.chen.gmail.com
Hi,
I was instrumenting the source code file with some method call.
But I had some problems modifying the parameters of a MethodInvocation node.
Given the following code snippet on some ast,
SimpleName methodName = ast.newSimpleName("someMethodCall");
MethodInvocation methodEntry = ast.newMethodInvocation();
methodEntry.setName(methodName);
List<Expression> arguments = (List<Expression>) methodEntry.arguments();
StringLiteral currentObject = ast.newStringLiteral();
currentObject.setLiteralValue("this");
arguments.add(currentObject);
List<Expression> arguments2 = (List<Expression>) methodEntry.arguments();
StringLiteral currentClass = ast.newStringLiteral();
currentObject.setLiteralValue("someclass");
arguments2.add(currentClass);
as I expect, it should generate the statement
someMethodCall(this, someclass)
But instead it would produce
someMethodCall(someclass, "")
I was so frustrated that It could only reflect the last change you made to
the arguments list.
My intention is to let someMethodCall have 5 StringLiteral parameters which
I never achieved.
I doubt is there something wrong with my code.
You help would be much appreciated.
Kevin
|
|
|
|
Problem solved [message #247842 is a reply to message #247831] |
Wed, 19 September 2007 03:59  |
Eclipse User |
|
|
|
Originally posted by: qkevin.chen.gmail.com
Problem solved.
It was because some problem in my code.
Thanks.
Kevin Chen wrote:
> Hi,
>
> I was instrumenting the source code file with some method call.
>
> But I had some problems modifying the parameters of a MethodInvocation
> node.
>
> Given the following code snippet on some ast,
>
> SimpleName methodName = ast.newSimpleName("someMethodCall");
> MethodInvocation methodEntry = ast.newMethodInvocation();
> methodEntry.setName(methodName);
> List<Expression> arguments = (List<Expression>) methodEntry.arguments();
> StringLiteral currentObject = ast.newStringLiteral();
> currentObject.setLiteralValue("this");
> arguments.add(currentObject);
>
> List<Expression> arguments2 = (List<Expression>) methodEntry.arguments();
> StringLiteral currentClass = ast.newStringLiteral();
> currentObject.setLiteralValue("someclass");
> arguments2.add(currentClass);
>
>
> as I expect, it should generate the statement
>
> someMethodCall(this, someclass)
>
> But instead it would produce
>
> someMethodCall(someclass, "")
>
> I was so frustrated that It could only reflect the last change you made to
> the arguments list.
>
> My intention is to let someMethodCall have 5 StringLiteral parameters
> which I never achieved.
>
> I doubt is there something wrong with my code.
>
> You help would be much appreciated.
>
>
>
> Kevin
|
|
|
Powered by
FUDForum. Page generated in 0.03896 seconds