當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。