iextensionunit类-尊龙游戏旗舰厅官网
import org.eclipse.jdt.core.icompilationunit; //导入方法依赖的package包/类
/**
* @param file
* @param info
* @param monitor
* @throws malformedtreeexception
* @throws badlocationexception
* @throws coreexception
*/
@suppresswarnings("deprecation")
public static void addgeneratedannotation(ifile file, ifile graphfile, iprogressmonitor monitor)
throws malformedtreeexception, badlocationexception, coreexception {
icompilationunit compilationunit = javacore.createcompilationunitfrom(file);
try {
string source = compilationunit.getsource();
document document = new document(source);
compilationunit.becomeworkingcopy(new subprogressmonitor(monitor, 1));
astparser parser = astparser.newparser(ast.jls8);
parser.setsource(compilationunit);
parser.setresolvebindings(true);
compilationunit astroot = (compilationunit) parser.createast(new subprogressmonitor(monitor, 1));
astroot.recordmodifications();
final importrewrite importrewrite = importrewrite.create(astroot, true);
importrewrite.addimport("javax.annotation.generated");
astroot.accept(new astvisitor() {
@suppresswarnings("unchecked")
@override
public boolean visit(typedeclaration node) {
astnode copiednode = null;
// add generated annotation
classextension ce;
try {
ce = new classextension(false, false, false, false, false, false, "", "", null, false, false,
"", "", "", graphfile);
normalannotation annotation = ce.getgeneratedclassannotation();
if (annotation != null) {
copiednode = astnode.copysubtree(node.getast(), annotation);
node.modifiers().add(0, copiednode);
}
} catch (javamodelexception e) {
resourcemanager.logexception(e);
}
return super.visit(node);
}
});
textedit rewrite = astroot.rewrite(document, compilationunit.getjavaproject().getoptions(true));
rewrite.apply(document);
textedit rewriteimports = importrewrite.rewriteimports(new subprogressmonitor(monitor, 1));
rewriteimports.apply(document);
string newsource = document.get();
compilationunit.getbuffer().setcontents(newsource);
compilationunit.reconcile(icompilationunit.no_ast, false, null, new subprogressmonitor(monitor, 1));
compilationunit.commitworkingcopy(false, new subprogressmonitor(monitor, 1));
} finally {
compilationunit.discardworkingcopy();
monitor.done();
}
// workbenchfacade.jdtmanager.reorganizeimport(compilationunit);
}
总结
以上是尊龙游戏旗舰厅官网为你收集整理的iextensionunit类_java icompilationunit.reconcile方法代码示例的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: if else 简写_15 js简写骚
- 下一篇: 报错 插入更新_自增主键,三类插入测验答