Getting exception at rewriteAST [message #1707722] |
Tue, 08 September 2015 15:00  |
Eclipse User |
|
|
|
I am trying to replace annotation node with another annotation :
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setIgnoreMethodBodies(true);
parser.setBindingsRecovery(true);
parser.setSource(iCompilationUnit);
parser.setResolveBindings(true);
CompilationUnit compUnit = (CompilationUnit) parser.createAST(null); // parse
final AST ast = compUnit.getAST();
compUnit.recordModifications();
final Document document = new Document();
final ASTRewrite rewriter = ASTRewrite.create(ast);
compUnit.accept(new ASTVisitor() {
public boolean visit(SingleMemberAnnotation node) {
final NormalAnnotation newNormalAnnotation = ast.newNormalAnnotation();
newNormalAnnotation.setTypeName(ast.newName("AnnotationTest"));
rewriter.replace(node, newNormalAnnotation, null);
return true;
}
});
TextEdit edits = rewriter.rewriteAST(document, null);
I am getting an exception at
TextEdit edits = rewriter.rewriteAST(document, null);
java.lang.IllegalArgumentException: Document does not match the AST
Caused by: org.eclipse.core.runtime.CoreException: End Of File
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.24663 seconds