当前位置: 首页>>代码示例>>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;未经允许,请勿转载。