本文整理汇总了Java中org.eclipse.jdt.internal.corext.util.JavaModelUtil.getPackageFragmentRoot方法的典型用法代码示例。如果您正苦于以下问题:Java JavaModelUtil.getPackageFragmentRoot方法的具体用法?Java JavaModelUtil.getPackageFragmentRoot怎么用?Java JavaModelUtil.getPackageFragmentRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.util.JavaModelUtil
的用法示例。
在下文中一共展示了JavaModelUtil.getPackageFragmentRoot方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canModifyAccessRules
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private static boolean canModifyAccessRules(IBinding binding) {
IJavaElement element= binding.getJavaElement();
if (element == null)
return false;
IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element);
if (root == null)
return false;
try {
IClasspathEntry classpathEntry= root.getRawClasspathEntry();
if (classpathEntry == null)
return false;
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
return true;
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
ClasspathContainerInitializer classpathContainerInitializer= JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0));
IStatus status= classpathContainerInitializer.getAccessRulesStatus(classpathEntry.getPath(), root.getJavaProject());
return status.isOK();
}
} catch (JavaModelException e) {
return false;
}
return false;
}
示例2: acceptSearchMatch
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object enclosingElement= match.getElement();
if (enclosingElement instanceof IMethod) { // defensive code
try {
IMethod curr= (IMethod) enclosingElement;
if (curr.isMainMethod()) {
if (!considerExternalJars()) {
IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(curr);
if (root == null || root.isArchive()) {
return;
}
}
if (!considerBinaries() && curr.isBinary()) {
return;
}
fResult.add(curr.getDeclaringType());
}
} catch (JavaModelException e) {
JavaPlugin.log(e.getStatus());
}
}
}
示例3: getJavadocBaseLocation
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
public static URL getJavadocBaseLocation(IJavaElement element) throws JavaModelException {
if (element.getElementType() == IJavaElement.JAVA_PROJECT) {
return getProjectJavadocLocation((IJavaProject) element);
}
IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element);
if (root == null) {
return null;
}
if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
IClasspathEntry entry= root.getResolvedClasspathEntry();
URL javadocLocation= getLibraryJavadocLocation(entry);
if (javadocLocation != null) {
return getLibraryJavadocLocation(entry);
}
entry= root.getRawClasspathEntry();
switch (entry.getEntryKind()) {
case IClasspathEntry.CPE_LIBRARY:
case IClasspathEntry.CPE_VARIABLE:
return getLibraryJavadocLocation(entry);
default:
return null;
}
} else {
return getProjectJavadocLocation(root.getJavaProject());
}
}
示例4: getPackageFragmentRoot
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private IPackageFragmentRoot getPackageFragmentRoot(Object element) {
if (element instanceof PackageFragmentRootContainer) {
// return first package fragment root from the container
PackageFragmentRootContainer cp= (PackageFragmentRootContainer)element;
Object[] roots= cp.getPackageFragmentRoots();
if (roots.length > 0)
return (IPackageFragmentRoot)roots[0];
// non resolvable - return null
return null;
}
return JavaModelUtil.getPackageFragmentRoot((IJavaElement)element);
}
示例5: initContainerPage
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
* Initializes the source folder field with a valid package fragment root.
* The package fragment root is computed from the given Java element.
*
* @param elem the Java element used to compute the initial package
* fragment root used as the source folder
*/
protected void initContainerPage(IJavaElement elem) {
IPackageFragmentRoot initRoot= null;
if (elem != null) {
initRoot= JavaModelUtil.getPackageFragmentRoot(elem);
try {
if (initRoot == null || initRoot.getKind() != IPackageFragmentRoot.K_SOURCE) {
IJavaProject jproject= elem.getJavaProject();
if (jproject != null) {
initRoot= null;
if (jproject.exists()) {
IPackageFragmentRoot[] roots= jproject.getPackageFragmentRoots();
for (int i= 0; i < roots.length; i++) {
if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) {
initRoot= roots[i];
break;
}
}
}
if (initRoot == null) {
initRoot= jproject.getPackageFragmentRoot(jproject.getResource());
}
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
}
setPackageFragmentRoot(initRoot, true);
}
示例6: getWrongPackageDeclNameProposals
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
ICompilationUnit cu= context.getCompilationUnit();
boolean isLinked= cu.getResource().isLinked();
// 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));
// move to package
IPackageDeclaration[] packDecls= cu.getPackageDeclarations();
String newPackName= packDecls.length > 0 ? packDecls[0].getElementName() : ""; //$NON-NLS-1$
IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(cu);
IPackageFragment newPack= root.getPackageFragment(newPackName);
ICompilationUnit newCU= newPack.getCompilationUnit(cu.getElementName());
if (!newCU.exists() && !isLinked) {
String label;
if (newPack.isDefaultPackage()) {
label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu));
} else {
String packageLabel= JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT);
label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel });
}
CompositeChange composite= new CompositeChange(label);
composite.add(new CreatePackageChange(newPack));
composite.add(new MoveCompilationUnitChange(cu, newPack));
proposals.add(new ChangeCorrectionProposal(label, composite, IProposalRelevance.MOVE_CU_TO_PACKAGE, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE)));
}
}
示例7: getWrongPackageDeclNameProposals
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
ICompilationUnit cu= context.getCompilationUnit();
boolean isLinked= cu.getResource().isLinked();
// correct package declaration
int relevance= cu.getPackageDeclarations().length == 0 ? 7 : 5; // bug 38357
proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance));
// move to package
IPackageDeclaration[] packDecls= cu.getPackageDeclarations();
String newPackName= packDecls.length > 0 ? packDecls[0].getElementName() : ""; //$NON-NLS-1$
IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(cu);
IPackageFragment newPack= root.getPackageFragment(newPackName);
ICompilationUnit newCU= newPack.getCompilationUnit(cu.getElementName());
if (!newCU.exists() && !isLinked) {
String label;
if (newPack.isDefaultPackage()) {
label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu));
} else {
String packageLabel= JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT);
label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel });
}
CompositeChange composite= new CompositeChange(label);
composite.add(new CreatePackageChange(newPack));
composite.add(new MoveCompilationUnitChange(cu, newPack));
proposals.add(new ChangeCorrectionProposal(label, composite, 6, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE)));
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:32,代码来源:ReorgCorrectionsSubProcessor.java
示例8: appendElementLabel
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
* Appends the label for a Java element with the flags as defined by this class.
*
* @param element the element to render
* @param flags the rendering flags.
*/
public void appendElementLabel(IJavaElement element, long flags) {
int type= element.getElementType();
IPackageFragmentRoot root= null;
if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT && type != IJavaElement.PACKAGE_FRAGMENT_ROOT) {
root= JavaModelUtil.getPackageFragmentRoot(element);
}
if (root != null && getFlag(flags, JavaElementLabels.PREPEND_ROOT_PATH)) {
appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED);
fBuilder.append(JavaElementLabels.CONCAT_STRING);
}
switch (type) {
case IJavaElement.METHOD:
appendMethodLabel((IMethod) element, flags);
break;
case IJavaElement.FIELD:
appendFieldLabel((IField) element, flags);
break;
case IJavaElement.LOCAL_VARIABLE:
appendLocalVariableLabel((ILocalVariable) element, flags);
break;
case IJavaElement.TYPE_PARAMETER:
appendTypeParameterLabel((ITypeParameter) element, flags);
break;
case IJavaElement.INITIALIZER:
appendInitializerLabel((IInitializer) element, flags);
break;
case IJavaElement.TYPE:
appendTypeLabel((IType) element, flags);
break;
case IJavaElement.CLASS_FILE:
appendClassFileLabel((IClassFile) element, flags);
break;
case IJavaElement.COMPILATION_UNIT:
appendCompilationUnitLabel((ICompilationUnit) element, flags);
break;
case IJavaElement.PACKAGE_FRAGMENT:
appendPackageFragmentLabel((IPackageFragment) element, flags);
break;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags);
break;
case IJavaElement.IMPORT_CONTAINER:
case IJavaElement.IMPORT_DECLARATION:
case IJavaElement.PACKAGE_DECLARATION:
appendDeclarationLabel(element, flags);
break;
case IJavaElement.JAVA_PROJECT:
case IJavaElement.JAVA_MODEL:
fBuilder.append(element.getElementName());
break;
default:
fBuilder.append(element.getElementName());
}
if (root != null && getFlag(flags, JavaElementLabels.APPEND_ROOT_PATH)) {
fBuilder.append(JavaElementLabels.CONCAT_STRING);
appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED);
}
}
示例9: enclosingTypeChanged
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
* Hook method that gets called when the enclosing type name has changed. The method
* validates the enclosing type and returns the status of the validation. It also updates the
* enclosing type model.
* <p>
* Subclasses may extend this method to perform their own validation.
* </p>
*
* @return the status of the validation
*/
protected IStatus enclosingTypeChanged() {
StatusInfo status= new StatusInfo();
fCurrEnclosingType= null;
IPackageFragmentRoot root= getPackageFragmentRoot();
fEnclosingTypeDialogField.enableButton(root != null);
if (root == null) {
status.setError(""); //$NON-NLS-1$
return status;
}
String enclName= getEnclosingTypeText();
if (enclName.length() == 0) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeEnterName);
return status;
}
try {
IType type= findType(root.getJavaProject(), enclName);
if (type == null) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists);
return status;
}
if (type.getCompilationUnit() == null) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotInCU);
return status;
}
if (!JavaModelUtil.isEditable(type.getCompilationUnit())) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotEditable);
return status;
}
fCurrEnclosingType= type;
IPackageFragmentRoot enclosingRoot= JavaModelUtil.getPackageFragmentRoot(type);
if (!enclosingRoot.equals(root)) {
status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_EnclosingNotInSourceFolder);
}
return status;
} catch (JavaModelException e) {
status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists);
JavaPlugin.log(e);
return status;
}
}
示例10: isInArchiveOrExternal
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private static boolean isInArchiveOrExternal(IJavaElement element) {
IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element);
return root != null && (root.isArchive() || root.isExternal());
}
示例11: handleDocRoot
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private boolean handleDocRoot(TagElement node) {
if (!TagElement.TAG_DOCROOT.equals(node.getTagName()))
return false;
try {
String url= null;
if (fElement instanceof IMember && ((IMember) fElement).isBinary()) {
URL javadocBaseLocation= JavaUI.getJavadocBaseLocation(fElement);
if (javadocBaseLocation != null) {
url= javadocBaseLocation.toExternalForm();
}
} else {
IPackageFragmentRoot srcRoot= JavaModelUtil.getPackageFragmentRoot(fElement);
if (srcRoot != null) {
IResource resource= srcRoot.getResource();
if (resource != null) {
/*
* Too bad: Browser widget knows nothing about EFS and custom URL handlers,
* so IResource#getLocationURI() does not work in all cases.
* We only support the local file system for now.
* A solution could be https://bugs.eclipse.org/bugs/show_bug.cgi?id=149022 .
*/
IPath location= resource.getLocation();
if (location != null) {
url= location.toFile().toURI().toASCIIString();
}
}
}
}
if (url != null) {
if (url.endsWith("/")) { //$NON-NLS-1$
url= url.substring(0, url.length() -1);
}
fBuf.append(url);
return true;
}
} catch (JavaModelException e) {
}
return false;
}
示例12: appendElementLabel
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
* Appends the label for a Java element with the flags as defined by this class.
*
* @param element the element to render
* @param flags the rendering flags.
*/
public void appendElementLabel(IJavaElement element, long flags) {
int type= element.getElementType();
IPackageFragmentRoot root= null;
if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT && type != IJavaElement.PACKAGE_FRAGMENT_ROOT)
root= JavaModelUtil.getPackageFragmentRoot(element);
if (root != null && getFlag(flags, JavaElementLabels.PREPEND_ROOT_PATH)) {
appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED);
fBuffer.append(JavaElementLabels.CONCAT_STRING);
}
switch (type) {
case IJavaElement.METHOD:
appendMethodLabel((IMethod) element, flags);
break;
case IJavaElement.FIELD:
appendFieldLabel((IField) element, flags);
break;
case IJavaElement.LOCAL_VARIABLE:
appendLocalVariableLabel((ILocalVariable) element, flags);
break;
case IJavaElement.TYPE_PARAMETER:
appendTypeParameterLabel((ITypeParameter) element, flags);
break;
case IJavaElement.INITIALIZER:
appendInitializerLabel((IInitializer) element, flags);
break;
case IJavaElement.TYPE:
appendTypeLabel((IType) element, flags);
break;
case IJavaElement.CLASS_FILE:
appendClassFileLabel((IClassFile) element, flags);
break;
case IJavaElement.COMPILATION_UNIT:
appendCompilationUnitLabel((ICompilationUnit) element, flags);
break;
case IJavaElement.PACKAGE_FRAGMENT:
appendPackageFragmentLabel((IPackageFragment) element, flags);
break;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags);
break;
case IJavaElement.IMPORT_CONTAINER:
case IJavaElement.IMPORT_DECLARATION:
case IJavaElement.PACKAGE_DECLARATION:
appendDeclarationLabel(element, flags);
break;
case IJavaElement.JAVA_PROJECT:
case IJavaElement.JAVA_MODEL:
fBuffer.append(element.getElementName());
break;
default:
fBuffer.append(element.getElementName());
}
if (root != null && getFlag(flags, JavaElementLabels.APPEND_ROOT_PATH)) {
int offset= fBuffer.length();
fBuffer.append(JavaElementLabels.CONCAT_STRING);
appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED);
if (getFlag(flags, JavaElementLabels.COLORIZE)) {
fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
}
}
}
示例13: JavadocHelpContext
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
public JavadocHelpContext(IContext context, Object[] elements) throws JavaModelException {
Assert.isNotNull(elements);
if (context instanceof IContext2)
fTitle= ((IContext2)context).getTitle();
List<IHelpResource> helpResources= new ArrayList<IHelpResource>();
String javadocSummary= null;
for (int i= 0; i < elements.length; i++) {
if (elements[i] instanceof IJavaElement) {
IJavaElement element= (IJavaElement) elements[i];
// if element isn't on the build path skip it
if (!ActionUtil.isOnBuildPath(element))
continue;
// Create Javadoc summary
if (BUG_85721_FIXED) {
if (javadocSummary == null) {
javadocSummary= retrieveText(element);
if (javadocSummary != null) {
String elementLabel= JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_DEFAULT);
// FIXME: needs to be NLSed once the code becomes active
javadocSummary= "<b>Javadoc for " + elementLabel + ":</b><br>" + javadocSummary; //$NON-NLS-1$//$NON-NLS-2$
}
} else {
javadocSummary= ""; // no Javadoc summary for multiple selection //$NON-NLS-1$
}
}
URL url= JavaUI.getJavadocLocation(element, true);
if (url == null || doesNotExist(url)) {
IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element);
if (root != null) {
url= JavaUI.getJavadocBaseLocation(element);
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
element= element.getJavaProject();
} else {
element= root;
}
url= JavaUI.getJavadocLocation(element, false);
}
}
if (url != null) {
IHelpResource javaResource= new JavaUIHelpResource(element, getURLString(url));
helpResources.add(javaResource);
}
}
}
// Add static help topics
if (context != null) {
IHelpResource[] resources= context.getRelatedTopics();
if (resources != null) {
for (int j= 0; j < resources.length; j++) {
helpResources.add(resources[j]);
}
}
}
fHelpResources= helpResources.toArray(new IHelpResource[helpResources.size()]);
if (context != null)
fText= context.getText();
if (BUG_85721_FIXED) {
if (javadocSummary != null && javadocSummary.length() > 0) {
if (fText != null)
fText= context.getText() + "<br><br>" + javadocSummary; //$NON-NLS-1$
else
fText= javadocSummary;
}
}
if (fText == null)
fText= ""; //$NON-NLS-1$
}
示例14: handleDocRoot
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private boolean handleDocRoot(TagElement node) {
if (!TagElement.TAG_DOCROOT.equals(node.getTagName()))
return false;
try {
String url= null;
if (fMember.isBinary()) {
URL javadocBaseLocation= JavaUI.getJavadocBaseLocation(fMember);
if (javadocBaseLocation != null) {
url= javadocBaseLocation.toExternalForm();
}
} else {
IPackageFragmentRoot srcRoot= JavaModelUtil.getPackageFragmentRoot(fMember);
if (srcRoot != null) {
IResource resource= srcRoot.getResource();
if (resource != null) {
/*
* Too bad: Browser widget knows nothing about EFS and custom URL handlers,
* so IResource#getLocationURI() does not work in all cases.
* We only support the local file system for now.
* A solution could be https://bugs.eclipse.org/bugs/show_bug.cgi?id=149022 .
*/
IPath location= resource.getLocation();
if (location != null) {
url= location.toFile().toURI().toASCIIString();
}
}
}
}
if (url != null) {
if (url.endsWith("/")) { //$NON-NLS-1$
url= url.substring(0, url.length() -1);
}
fBuf.append(url);
return true;
}
} catch (JavaModelException e) {
}
return false;
}