本文整理了Java中com.github.javaparser.ast.CompilationUnit.setImports()
方法的一些代码示例,展示了CompilationUnit.setImports()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CompilationUnit.setImports()
方法的具体详情如下:
包路径:com.github.javaparser.ast.CompilationUnit
类名称:CompilationUnit
方法名:setImports
暂无
代码示例来源:origin: kawasima/enkan
imports.add(new ImportDeclaration(ASTHelper.createNameExpr("java.sql.Connection"), false, false));
imports.add(new ImportDeclaration(ASTHelper.createNameExpr("java.sql.Statement"), false, false));
cu.setImports(imports);
代码示例来源:origin: beihaifeiwu/dolphin
@Override
public CompilationUnit doMerge(CompilationUnit first, CompilationUnit second) {
CompilationUnit unit = new CompilationUnit();
unit.setPackage(mergeSingle(first.getPackage(), second.getPackage()));
unit.setImports(mergeCollections(first.getImports(), second.getImports()));
unit.setTypes(mergeCollections(first.getTypes(), second.getTypes()));
return unit;
}
代码示例来源:origin: beihaifeiwu/dolphin
public static String mergeContent(CompilationUnit one, CompilationUnit two) throws Exception {
// 包声明不同,返回null
if (!one.getPackage().equals(two.getPackage())) return null;
CompilationUnit cu = new CompilationUnit();
// add package declaration to the compilation unit
PackageDeclaration pd = new PackageDeclaration();
pd.setName(one.getPackage().getName());
cu.setPackage(pd);
// check and merge file comment;
Comment fileComment = mergeSelective(one.getComment(), two.getComment());
cu.setComment(fileComment);
// check and merge imports
List<ImportDeclaration> ids = mergeListNoDuplicate(one.getImports(), two.getImports());
cu.setImports(ids);
// check and merge Types
List<TypeDeclaration> types = mergeTypes(one.getTypes(), two.getTypes());
cu.setTypes(types);
return cu.toString();
}
内容来源于网络,如有侵权,请联系作者删除!