本文整理汇总了Java中japa.parser.ast.CompilationUnit.getImports方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit.getImports方法的具体用法?Java CompilationUnit.getImports怎么用?Java CompilationUnit.getImports使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类japa.parser.ast.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.getImports方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Fact
import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
public Fact(File file, CompilationUnit compilationUnit) throws FileNotFoundException {
if (compilationUnit.getPackage() != null)
packageName = compilationUnit.getPackage().getName().toString().replace("package", "");
comment = extractTopComment(file);
imports = new HashSet<String>();
if (compilationUnit.getImports() != null)
for (ImportDeclaration imp : compilationUnit.getImports()) {
String str = imp.getName().toString();
if (!imp.isAsterisk())
str = str.substring(0, str.lastIndexOf("."));
imports.add(str);
}
declarations = new ArrayList<Declaration>();
if (compilationUnit.getTypes() != null)
for (TypeDeclaration decl : compilationUnit.getTypes()) {
if (decl instanceof ClassOrInterfaceDeclaration)
declarations.add(new Declaration(decl));
}
}
示例2: visit
import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
public R visit(CompilationUnit n, A arg) {
if (n.getPackage() != null) {
n.getPackage().accept(this, arg);
}
if (n.getImports() != null) {
for (ImportDeclaration i : n.getImports()) {
i.accept(this, arg);
}
}
if (n.getTypes() != null) {
for (TypeDeclaration typeDeclaration : n.getTypes()) {
typeDeclaration.accept(this, arg);
}
}
return null;
}
示例3: visit
import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
public void visit(CompilationUnit n, Object arg) {
if (n.getPackage() != null) {
n.getPackage().accept(this, arg);
}
if (n.getImports() != null) {
for (ImportDeclaration i : n.getImports()) {
i.accept(this, arg);
}
printer.printLn();
}
if (n.getTypes() != null) {
for (Iterator<TypeDeclaration> i = n.getTypes().iterator(); i.hasNext();) {
i.next().accept(this, arg);
printer.printLn();
if (i.hasNext()) {
printer.printLn();
}
}
}
}
示例4: visit
import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
public Node visit(CompilationUnit n, A arg) {
if (n.getPackage() != null) {
n.setPackage((PackageDeclaration) n.getPackage().accept(this, arg));
}
List<ImportDeclaration> imports = n.getImports();
if (imports != null) {
for (int i = 0; i < imports.size(); i++) {
imports.set(i, (ImportDeclaration) imports.get(i).accept(this, arg));
}
removeNulls(imports);
}
List<TypeDeclaration> types = n.getTypes();
if (types != null) {
for (int i = 0; i < types.size(); i++) {
types.set(i, (TypeDeclaration) types.get(i).accept(this, arg));
}
removeNulls(types);
}
return n;
}
示例5: visit
import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
public void visit(CompilationUnit n, A arg) {
if (n.getPackage() != null) {
n.getPackage().accept(this, arg);
}
if (n.getImports() != null) {
for (ImportDeclaration i : n.getImports()) {
i.accept(this, arg);
}
}
if (n.getTypes() != null) {
for (TypeDeclaration typeDeclaration : n.getTypes()) {
typeDeclaration.accept(this, arg);
}
}
}
示例6: addImport
import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
private static void addImport(CompilationUnit cu, String imp) {
for (ImportDeclaration id : cu.getImports()) {
if (imp.equals(id.getName().toString())) {
return;
}
}
cu.getImports().add(
new ImportDeclaration(new NameExpr(imp), false, false));
}