欢迎访问 生活随笔!

凯发ag旗舰厅登录网址下载

当前位置: 凯发ag旗舰厅登录网址下载 > 编程语言 > java >内容正文

java

iextensionunit类-凯发ag旗舰厅登录网址下载

发布时间:2024/10/8 java 0 豆豆
凯发ag旗舰厅登录网址下载 收集整理的这篇文章主要介绍了 iextensionunit类_java icompilationunit.reconcile方法代码示例 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

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);

}

总结

以上是凯发ag旗舰厅登录网址下载为你收集整理的iextensionunit类_java icompilationunit.reconcile方法代码示例的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。

网站地图