ASTRequestor to remove MethodDeclaration nodes [message #648645] |
Thu, 13 January 2011 18:50 |
|
Hi,
I've started to develop a JDT plugin to sort methods in Java files.
I've read the tutorial "Unleashing the Power of Refactoring" from
"Eclipse Corner Articles".
Everything is set up in my project (same layout as the sample code
provided in the tutorial). The first step I'm trying to climb is to
remove method nodes one by one in a file, this is not the final strategy
I plan, just to play with nodes.
I succeed in finding node, removing them from the ASTRewrite, creating
TextFileChange. But the refactored source code remains not modified.
Here is my requestor below, does anyone can see a mistake in my code?
Thank you,
Chris
// The "source" variable is an ICompilationUnit instance
final Document document = new Document(source.getSource());
// The "node" variable is a CompilationUnit instance
final AST ast = node.getAST();
final ASTRewrite rewriter = ASTRewrite.create(ast);
final TextEditGroup group = new TextEditGroup(SortClassMembersRefactoring.class.getName());
final MethodDeclarationFinder finder = new MethodDeclarationFinder();
final Collection<MethodDeclaration> methodDeclarationNodes = finder.getMethodDeclarations(node);
for (final MethodDeclaration methodDeclarationNode : methodDeclarationNodes) {
// I enter here
rewriter.remove(methodDeclarationNode, group);
}
if (methodDeclarationNodes.size() > 0) {
// I enter here
final TextEdit edit = rewriter.rewriteAST(document, null);
edit.apply(document);
TextFileChange change = SortClassMembersRefactoring.this._changes.get(source);
if (change == null) {
// I enter here
change = new TextFileChange(source.getElementName(), (IFile) source.getResource());
change.setTextType("java");
change.setEdit(edit);
} else {
change.getEdit().addChild(edit);
}
SortClassMembersRefactoring.this._changes.put(source, change);
}
[Updated on: Mon, 17 January 2011 11:02] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02349 seconds