全国奶瓶排行榜10强:谁用过eclipse jdt中的ASTRewrite,有问题

来源:百度文库 编辑:高校问答 时间:2024/04/27 13:43:36
I use the method "replace(ASTNode node,ASTNode replacement,TextEditGroup editGroup)" to update the node.But there is a problem.The ast tree didn't change(the new node didn't replace the old node).Any error??Partly code is followed
=========================================================
ASTParser parser = ASTParser.newParser(AST.JLS2);
parser.setSource(doc.get().toCharArray());
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
AST ast = cu.getAST();
// create new javadoc
Javadoc jc = ast.newJavadoc();
TagElement tag = ast.newTagElement();
tag.setTagName(TagElement.TAG_AUTHOR);
tag.fragments().add(ast.newSimpleName("Manoel Marques"));
jc.tags().add(tag);
tag = ast.newTagElement();
TextElement te = ast.newTextElement();
te.setText("Sample SWT Composite class created using the ASTParser");
tag.fragments().add(te);
jc.tags().add(tag);
ASTRewrite re = ASTRewrite.create(ast);
//replace
re.replace((Javadoc) (cu.getCommentList().get(0)), jc, null);
TextEdit edits=re.rewriteAST(doc, null);
edits.apply(doc);

说真的我也不知道
我是学计算机的有事可以早我 哦哦