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


Java ICompilationUnit.getPackageDeclarations方法代码示例

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


在下文中一共展示了ICompilationUnit.getPackageDeclarations方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addEdits

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
	super.addEdits(doc, root);

	ICompilationUnit cu= getCompilationUnit();

	IPackageFragment parentPack= (IPackageFragment) cu.getParent();
	IPackageDeclaration[] decls= cu.getPackageDeclarations();

	if (parentPack.isDefaultPackage() && decls.length > 0) {
		for (int i= 0; i < decls.length; i++) {
			ISourceRange range= decls[i].getSourceRange();
			root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
		}
		return;
	}
	if (!parentPack.isDefaultPackage() && decls.length == 0) {
		String lineDelim = "\n";
		String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
		root.addChild(new InsertEdit(0, str));
		return;
	}

	root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:CorrectPackageDeclarationProposal.java

示例2: getName

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Override
public String getName() {
	ICompilationUnit cu= getCompilationUnit();
	IPackageFragment parentPack= (IPackageFragment) cu.getParent();
	try {
		IPackageDeclaration[] decls= cu.getPackageDeclarations();
		if (parentPack.isDefaultPackage() && decls.length > 0) {
			return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
		}
		if (!parentPack.isDefaultPackage() && decls.length == 0) {
			return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description,  JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
		}
	} catch(JavaModelException e) {
		JavaLanguageServerPlugin.log(e);
	}
	return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:CorrectPackageDeclarationProposal.java

示例3: getWrongPackageDeclNameProposals

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem,
		Collection<CUCorrectionProposal> proposals) throws CoreException {
	ICompilationUnit cu= context.getCompilationUnit();

	// correct package declaration
	int relevance= cu.getPackageDeclarations().length == 0 ? IProposalRelevance.MISSING_PACKAGE_DECLARATION : IProposalRelevance.CORRECT_PACKAGE_DECLARATION; // bug 38357
	proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:9,代码来源:ReorgCorrectionsSubProcessor.java

示例4: setFrameworkPackageTypes

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private void setFrameworkPackageTypes() throws JavaModelException {
	String className = null;

	// To append the packageName - get the fullyQualified type name
	StringBuilder typeName = new StringBuilder();

	// Current project open
	IProject currentProject = WorkspaceUtilities.getCurrentProject(window);
	
	Set<String> frameworkPackages = defaultingModel.getFrameworkPackages();

	// Get a IcompilationUnit of the current project
	IPackageFragment[] packages = JavaCore.create(currentProject).getPackageFragments();
	for (IPackageFragment mypackage : packages) {
		// Hard-coded package names for now - Until we get logic for the
		// distinguishing Framework Types and ApplicationDefault types
		// Only for MD_Summary for now
		// TOSUM: TODO: Get a logic to distinguish between
		// Added in the package names for CDB, AFS and DL

		if (frameworkPackages.contains(mypackage.getElementName())) {
			for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
				IPackageDeclaration[] pck = unit.getPackageDeclarations();
				for (IPackageDeclaration ipack : pck) {
					IResource resource = ipack.getResource();

					// Get the type Name
					className = resource.getName();
					// Remove the extensions from the typeName
					int indexOf = className.indexOf(".java");
					typeName.append(mypackage.getElementName());
					typeName.append(".");
					typeName.append(className.substring(0, indexOf));

					// XXX. Fix this. No point in storing the package name and the fully qualified type
					model.addFrameworkPackageType(new PackageType(mypackage.getElementName(), typeName.toString()));
				}
				// Clean up StringBuilder
				typeName.setLength(0);
			}
			typeName.setLength(0);
		}
		typeName.setLength(0);
	}
}
 
开发者ID:aroog,项目名称:code,代码行数:46,代码来源:GenerateDefaultMap.java

示例5: setApplicationTypes

import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private void setApplicationTypes() throws JavaModelException {
	String className = null;

	// To append the packageName - get the fullyQualified type name
	StringBuilder typeName = new StringBuilder();

	// Current project open
	IProject currentProject = WorkspaceUtilities.getCurrentProject(window);

	HashSet<String> appPackages = defaultingModel.getApplicationPackages();
	
	// Get a IcompilationUnit of the current project
	IPackageFragment[] packages = JavaCore.create(currentProject).getPackageFragments();
	for (IPackageFragment mypackage : packages) {
		// Hard-coded package names for now - Until we get logic for the
		// distinguishing Framework Types and ApplicationDefault types
		// Only for MD_Summary for now
		// TODO: Get a logic to distinguish between
		// Added in the package names for CDB
		
		// TOSUM: XXX. What the HELL is this? Get the Element name, remove .java, add .java?!?!?
		// Surely, there has to be a MUCH cleaner way of doing this
		// the package declaration has the fully qualified name!!!
		if (appPackages.contains(mypackage.getElementName())) {
			for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
				IPackageDeclaration[] pck = unit.getPackageDeclarations();
				for (IPackageDeclaration ipack : pck) {
					IResource resource = ipack.getResource();
					// Get the type Name
					className = resource.getName();
					// Remove the extensions from the typeName
					int indexOf = className.indexOf(".java");
					typeName.append(mypackage.getElementName());
					typeName.append(".");
					typeName.append(className.substring(0, indexOf));

					// XXX. Fix this. No point in storing the package name and the fully qualified type
					model.addApplicationPackageType(new PackageType(mypackage.getElementName(), typeName.toString()));
				}
				typeName.setLength(0);
			}
			typeName.setLength(0);
		}
		typeName.setLength(0);
	}
}
 
开发者ID:aroog,项目名称:code,代码行数:47,代码来源:GenerateDefaultMap.java


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