Eclipse AST not changing files which are not opened in eclipse

前端 未结 1 1642

I am trying to modify source code using eclipse plugin, JDT and AST (Abstract Syntax Tree). I can read all Java files and make operation on all those file, But when i am saving

相关标签:
1条回答
  • 2021-01-25 07:34

    Try to:

    1. Apply the TextEdit directly to the ICompilationUnit instead of using Document.
    2. Use ICompilationUnit.commitWorkingCopy to save the changes

    I use code similar to this:

    iCompilationUnit.becomeWorkingCopy(new NullProgressMonitor());
    CompilationUnit cu = parse(iCompilationUnit);
    ASTRewrite rewriter = ASTRewrite.create(cu.getAST());
    
    ... process AST ...
    
    iCompilationUnit.applyTextEdit(rewrite.rewriteAST(), new NullProgressMonitor());
    iCompilationUnit.commitWorkingCopy(false, new NullProgressMonitor());   
    
    0 讨论(0)
提交回复
热议问题