Вопрос

I want to invoke a method using eclipse AST. I have the MethodDeclarion of the method to be invoked. How can I invoke this method passing appropriate DUMMY/ default arguments.

i.e.

public void setStr (String str) { ... };
public void setSomeObj (SomeObj obj ) { ... };

Suppose I have MethodDeclarions of the above methods.

Now I want to create a MethodInvocation like the following.

setStr("some dummy value");
setSomeObj(new SomeObj());

The difficulty I have is generating the DUMMY/ default arguments for method invocation. Please help

Это было полезно?

Решение

MethodInvocation s;
s.arguments().add(...);

if you want to add an object that is part of the existing AST it needs to be:

....add((Cast)r.createCopyTarget(Object));

Cast = you will probaby have to cast it to a certain type, eclipse will tell you which.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top