當前位置: 首頁>>代碼示例>>Java>>正文


Java CompilationUnit.getPackage方法代碼示例

本文整理匯總了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;
}
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:22,代碼來源:NameResolver.java

示例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);
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:16,代碼來源:SDModelBuilder.java

示例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);
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:16,代碼來源:SDModelBuilder.java

示例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;
}
 
開發者ID:SAP,項目名稱:hybris-commerce-eclipse-plugin,代碼行數:19,代碼來源:CopyrightManager.java

示例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();
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:15,代碼來源:JDTUtils.java

示例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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:11,代碼來源:JavadocContentAccess.java

示例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();
}
 
開發者ID:bazelbuild,項目名稱:BUILD_file_generator,代碼行數:5,代碼來源:ReferencedClassesParser.java


注:本文中的org.eclipse.jdt.core.dom.CompilationUnit.getPackage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。