Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to modify the parameters of a MethodInvocation node
How to modify the parameters of a MethodInvocation node [message #247831] Wed, 19 September 2007 03:41 Go to next message
Eclipse UserFriend
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
Re: How to modify the parameters of a MethodInvocation node - some corrections [message #247836 is a reply to message #247831] Wed, 19 September 2007 03:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: qkevin.chen.gmail.com

 as I expect, it should generate the statement
 
 someMethodCall("this", "someclass")
 
 But instead it would produce
 
 someMethodCall("someclass", "")


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
Problem solved [message #247842 is a reply to message #247831] Wed, 19 September 2007 03:59 Go to previous message
Eclipse UserFriend
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
Previous Topic:Run As does not show java application as an option
Next Topic:Content-assist: How does the JDT do that little yellow popup window for the parameters?
Goto Forum:
  


Current Time: Thu May 08 22:19:48 EDT 2025

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

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

Back to the top