[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.jdt] Re: How to remove parameter using ASTParser

Fayezin Islam wrote:

  Just several key words that may help you

  CompilationUnit.recordModifications();
  MethodDeclaration.parameters().remove(index);
  Document document = new Document(source);
  MultiTextEdit edits = (MultiTextEdit) serviceRoot.rewrite(document,
     javaProjectOptions);
  edits.apply(document);
  newSource = document.get();


Suppose, I have a method invocation like -
class1.method1(par1, par2, par3);

I want to change it to:
class1.method1(par2);

How can I do this using the Eclipse ASTParser?

The parameters to be removed are decided by Static Analysis (Program Slicing).

Please note that I should be able to change invocations like these ase well -

class1.method1(new Object(), par2, par3);

Previously, I have analyzed code using the ASTParser but did not transformed/change code as of yet.

Therefore, a reply with an example will be very appreciated...

Thanks,

Fayezin