本文整理汇总了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));
}
}
示例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;
}
示例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;
}
示例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();
}
}
}
}
示例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;
}
示例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());
}
}
示例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);
}
}
}