当前位置: 首页>>代码示例>>Java>>正文


Java CompilationUnit.getPackage方法代码示例

本文整理汇总了Java中japa.parser.ast.CompilationUnit.getPackage方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit.getPackage方法的具体用法?Java CompilationUnit.getPackage怎么用?Java CompilationUnit.getPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在japa.parser.ast.CompilationUnit的用法示例。


在下文中一共展示了CompilationUnit.getPackage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
        }
}
 
开发者ID:amritbhat786,项目名称:DocIT,代码行数:23,代码来源:Fact.java

示例2: getNode

import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
public static Node getNode(CompilationUnit unit, String fqName) {
	String pkg = getQualifiedName(unit.getPackage().getName());
	if (!fqName.startsWith(pkg)) {
		return null;
	}
	if (fqName.equals(pkg)) {
		return unit.getPackage();
	}

	String name = fqName.substring(pkg.length() + 1);

	for (TypeDeclaration typeDecl : unit.getTypes()) {
		if (name.startsWith(typeDecl.getName())) {
			if (name.length() == typeDecl.getName().length()) {
				return typeDecl;
			} else {
				return getNode(typeDecl, name.substring(typeDecl.getName().length() + 1));
			}
		}
	}

	return null;
}
 
开发者ID:jedwards1211,项目名称:breakout,代码行数:24,代码来源:JavaParserUtils.java

示例3: 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;
}
 
开发者ID:rfw,项目名称:genja,代码行数:17,代码来源:GenericVisitorAdapter.java

示例4: 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();
            }
        }
    }
}
 
开发者ID:rfw,项目名称:genja,代码行数:21,代码来源:DumpVisitor.java

示例5: 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;
}
 
开发者ID:rfw,项目名称:genja,代码行数:21,代码来源:ModifierVisitorAdapter.java

示例6: getPackage

import japa.parser.ast.CompilationUnit; //导入方法依赖的package包/类
public final JavaPackage getPackage(final String fileIdentifier) {
    Validate.notBlank(fileIdentifier, "Compilation unit path required");
    Validate.isTrue(new File(fileIdentifier).exists(),
            "The file doesn't exist");
    Validate.isTrue(new File(fileIdentifier).isFile(),
            "The identifier doesn't represent a file");
    try {
        final File file = new File(fileIdentifier);
        String typeContents = "";
        try {
            typeContents = FileUtils.readFileToString(file);
        }
        catch (final IOException ignored) {
        }
        if (StringUtils.isBlank(typeContents)) {
            return null;
        }
        final CompilationUnit compilationUnit = JavaParser
                .parse(new ByteArrayInputStream(typeContents.getBytes()));
        if (compilationUnit == null || compilationUnit.getPackage() == null) {
            return null;
        }
        return new JavaPackage(compilationUnit.getPackage().getName()
                .toString());
    }
    catch (final ParseException e) {
        throw new IllegalStateException("Failed to parse " + fileIdentifier
                + " : " + e.getMessage());
    }
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:31,代码来源:JavaParserTypeResolutionService.java

示例7: 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);
        }
    }
}
 
开发者ID:rfw,项目名称:genja,代码行数:16,代码来源:VoidVisitorAdapter.java


注:本文中的japa.parser.ast.CompilationUnit.getPackage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。