本文整理汇总了Java中org.eclipse.jdt.core.dom.CompilationUnit.getPackage方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit.getPackage方法的具体用法?Java CompilationUnit.getPackage怎么用?Java CompilationUnit.getPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.getPackage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFullName
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
* Evaluates fully qualified name of the TypeDeclaration object.
*/
public static String getFullName(TypeDeclaration decl) {
String name = decl.getName().getIdentifier();
ASTNode parent = decl.getParent();
// resolve full name e.g.: A.B
while (parent != null && parent.getClass() == TypeDeclaration.class) {
name = ((TypeDeclaration) parent).getName().getIdentifier() + "." + name;
parent = parent.getParent();
}
// resolve fully qualified name e.g.: some.package.A.B
if (decl.getRoot().getClass() == CompilationUnit.class) {
CompilationUnit root = (CompilationUnit) decl.getRoot();
if (root.getPackage() != null) {
PackageDeclaration pack = root.getPackage();
name = pack.getName().getFullyQualifiedName() + "." + name;
}
}
return name;
}
示例2: processCompilationUnit
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
protected void processCompilationUnit(String sourceFilePath, char[] fileContent, CompilationUnit compilationUnit, SDModel model) {
PackageDeclaration packageDeclaration = compilationUnit.getPackage();
String packageName = "";
if (packageDeclaration != null) {
packageName = packageDeclaration.getName().getFullyQualifiedName();
}
String packagePath = packageName.replace('.', '/');
String sourceFolder = "/";
if (sourceFilePath.contains(packagePath)) {
sourceFolder = sourceFilePath.substring(0, sourceFilePath.indexOf(packagePath));
}
// RastNode nCompUnit = model.createCompilationUnit(packageName, sourceFolder, sourceFilePath, compilationUnit);
BindingsRecoveryAstVisitor visitor = new BindingsRecoveryAstVisitor(model, compilationUnit, sourceFilePath, fileContent, packageName, postProcessReferences, postProcessSupertypes);
compilationUnit.accept(visitor);
}
示例3: processCompilationUnit
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
protected void processCompilationUnit(String sourceFilePath, char[] fileContent, CompilationUnit compilationUnit, SDModel.Snapshot model) {
PackageDeclaration packageDeclaration = compilationUnit.getPackage();
String packageName = "";
if (packageDeclaration != null) {
packageName = packageDeclaration.getName().getFullyQualifiedName();
}
String packagePath = packageName.replace('.', '/');
String sourceFolder = "/";
if (sourceFilePath.contains(packagePath)) {
sourceFolder = sourceFilePath.substring(0, sourceFilePath.indexOf(packagePath));
}
SDPackage sdPackage = model.getOrCreatePackage(packageName, sourceFolder);
BindingsRecoveryAstVisitor visitor = new BindingsRecoveryAstVisitor(model, sourceFilePath, fileContent, sdPackage, postProcessReferences, postProcessSupertypes, postProcessClientCode, srbForTypes, srbForMethods, srbForAttributes);
compilationUnit.accept(visitor);
}
示例4: hasCopyrightsComment
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
/**
* Checks whether {@link CompilationUnit} has copyright header
*
* @param compilationUnit
* checked compilation unit
* @return true if {@link CompilationUnit} has copyright header
*/
public boolean hasCopyrightsComment(final CompilationUnit compilationUnit) {
final List<Comment> comments = getCommentList(compilationUnit);
boolean hasCopyrights = false;
if (!comments.isEmpty()) {
final PackageDeclaration packageNode = compilationUnit.getPackage();
final boolean commentBeforePackage = comments.get(0).getStartPosition() <= packageNode.getStartPosition();
final boolean hasJavaDoc = packageNode.getJavadoc() != null;
hasCopyrights = commentBeforePackage || hasJavaDoc;
}
return hasCopyrights;
}
示例5: getPackageName
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public static String getPackageName(IJavaProject javaProject, String fileContent) {
if (fileContent == null) {
return "";
}
//TODO probably not the most efficient way to get the package name as this reads the whole file;
char[] source = fileContent.toCharArray();
ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
parser.setProject(javaProject);
parser.setIgnoreMethodBodies(true);
parser.setSource(source);
CompilationUnit ast = (CompilationUnit) parser.createAST(null);
PackageDeclaration pkg = ast.getPackage();
return (pkg == null || pkg.getName() == null)?"":pkg.getName().getFullyQualifiedName();
}
示例6: getPackageJavadocNode
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
private static Javadoc getPackageJavadocNode(IJavaElement element, String cuSource) {
CompilationUnit cu= createAST(element, cuSource);
if (cu != null) {
PackageDeclaration packDecl= cu.getPackage();
if (packDecl != null) {
return packDecl.getJavadoc();
}
}
return null;
}
示例7: getPackageOfJavaFile
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
private static String getPackageOfJavaFile(CompilationUnit cu) {
PackageDeclaration pkg = cu.getPackage();
return pkg == null ? "" : pkg.getName().getFullyQualifiedName();
}