Java Code Examples for org.eclipse.jdt.core.IPackageFragmentRoot#isExternal()
The following examples show how to use
org.eclipse.jdt.core.IPackageFragmentRoot#isExternal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Storage2UriMapperJavaImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.5 */ @Override public URI getUri(/* @NonNull */ IStorage storage) { if (storage instanceof IJarEntryResource) { final IJarEntryResource casted = (IJarEntryResource) storage; IPackageFragmentRoot packageFragmentRoot = casted.getPackageFragmentRoot(); Map<URI, IStorage> data = getAllEntries(packageFragmentRoot); for (Map.Entry<URI, IStorage> entry : data.entrySet()) { if (entry.getValue().equals(casted)) return entry.getKey(); } if (packageFragmentRoot.exists() && packageFragmentRoot.isArchive()) { IPath jarPath = packageFragmentRoot.getPath(); URI jarURI; if (packageFragmentRoot.isExternal()) { jarURI = URI.createFileURI(jarPath.toOSString()); } else { jarURI = URI.createPlatformResourceURI(jarPath.toString(), true); } URI result = URI.createURI("archive:" + jarURI + "!" + storage.getFullPath()); return result; } } return null; }
Example 2
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public boolean canEnable() throws JavaModelException { if (!super.canEnable() || fPackageFragmentRoots.length == 0) { return false; } for (int i= 0; i < fPackageFragmentRoots.length; i++) { IPackageFragmentRoot root= fPackageFragmentRoots[i]; if (!(ReorgUtils.isSourceFolder(root) || root.isArchive() && !root.isExternal())) { return false; } } if (ReorgUtils.containsLinkedResources(fPackageFragmentRoots)) { return false; } return true; }
Example 3
Source File: FilteredTypesSelectionDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private String getContainerName(TypeNameMatch type) { IPackageFragmentRoot root= type.getPackageFragmentRoot(); if (root.isExternal()) { IPath path= root.getPath(); for (int i= 0; i < fInstallLocations.length; i++) { if (fInstallLocations[i].isPrefixOf(path)) { return fVMNames[i]; } } String lib= fLib2Name.get(path); if (lib != null) return lib; } StringBuffer buf= new StringBuffer(); JavaElementLabels.getPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED | JavaElementLabels.ROOT_VARIABLE, buf); return buf.toString(); }
Example 4
Source File: XtendUIValidator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected String getExpectedPackageName(XtendFile xtendFile) { URI fileURI = xtendFile.eResource().getURI(); for(Pair<IStorage, IProject> storage: storage2UriMapper.getStorages(fileURI)) { if(storage.getFirst() instanceof IFile) { IPath fileWorkspacePath = storage.getFirst().getFullPath(); IJavaProject javaProject = JavaCore.create(storage.getSecond()); if(javaProject != null && javaProject.exists() && javaProject.isOpen()) { try { for(IPackageFragmentRoot root: javaProject.getPackageFragmentRoots()) { if(!root.isArchive() && !root.isExternal()) { IResource resource = root.getResource(); if(resource != null) { IPath sourceFolderPath = resource.getFullPath(); if(sourceFolderPath.isPrefixOf(fileWorkspacePath)) { IPath claspathRelativePath = fileWorkspacePath.makeRelativeTo(sourceFolderPath); return claspathRelativePath.removeLastSegments(1).toString().replace("/", "."); } } } } } catch (JavaModelException e) { LOG.error("Error resolving expected path for XtendFile", e); } } } } return null; }
Example 5
Source File: ReorgUtils.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isArchiveOrExternalMember(IJavaElement[] elements) { for (int i= 0; i < elements.length; i++) { IJavaElement element= elements[i]; IPackageFragmentRoot root= (IPackageFragmentRoot)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && (root.isArchive() || root.isExternal())) return true; } return false; }
Example 6
Source File: JavaElementLabelComposer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) { try { IClasspathEntry rawEntry= root.getRawClasspathEntry(); if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry entry= JavaModelUtil.getClasspathEntry(root); if (entry.getReferencingEntry() != null) { return false; // not the variable entry itself, but a referenced entry } IPath path= rawEntry.getPath().makeRelative(); if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { int segements= path.segmentCount(); if (segements > 0) { fBuilder.append(path.segment(segements - 1)); if (segements > 1) { fBuilder.append(JavaElementLabels.CONCAT_STRING); fBuilder.append(path.removeLastSegments(1).toOSString()); } } else { fBuilder.append(path.toString()); } } else { fBuilder.append(path.toString()); } fBuilder.append(JavaElementLabels.CONCAT_STRING); if (root.isExternal()) { fBuilder.append(root.getPath().toOSString()); } else { fBuilder.append(root.getPath().makeRelative().toString()); } return true; } } catch (JavaModelException e) { // problems with class path, ignore (bug 202792) return false; } return false; }
Example 7
Source File: JavaElementLabelComposer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void appendArchiveLabel(IPackageFragmentRoot root, long flags) { boolean external= root.isExternal(); if (external) { appendExternalArchiveLabel(root, flags); } else { appendInternalArchiveLabel(root, flags); } }
Example 8
Source File: DeletePackageFragmentRootChange.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private boolean confirmDeleteIfReferenced() throws JavaModelException { IPackageFragmentRoot root= getRoot(); if (!root.isArchive() && !root.isExternal()) { return true; } if (fUpdateClasspathQuery == null) { return true; } IJavaProject[] referencingProjects= JavaElementUtil.getReferencingProjects(getRoot()); if (referencingProjects.length <= 1) { return true; } return fUpdateClasspathQuery.confirmManipulation(getRoot(), referencingProjects); }
Example 9
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean canChildrenBeDestinations(IJavaElement javaElement) { switch (javaElement.getElementType()) { case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: return true; case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot root= (IPackageFragmentRoot) javaElement; return !root.isArchive() && !root.isExternal(); default: return false; } }
Example 10
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public boolean canChildrenBeDestinations(IJavaElement javaElement) { switch (javaElement.getElementType()) { case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: return true; case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot root= (IPackageFragmentRoot) javaElement; return !root.isArchive() && !root.isExternal(); default: return false; } }
Example 11
Source File: ReorgUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isArchiveOrExternalMember(IJavaElement[] elements) { for (int i= 0; i < elements.length; i++) { IJavaElement element= elements[i]; IPackageFragmentRoot root= (IPackageFragmentRoot)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && (root.isArchive() || root.isExternal())) { return true; } } return false; }
Example 12
Source File: DeletePackageFragmentRootChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean confirmDeleteIfReferenced() throws JavaModelException { IPackageFragmentRoot root= getRoot(); if (!root.isArchive() && !root.isExternal()) //for source folders, you don't ask, just do it return true; if (fUpdateClasspathQuery == null) return true; IJavaProject[] referencingProjects= JavaElementUtil.getReferencingProjects(getRoot()); if (referencingProjects.length <= 1) return true; return fUpdateClasspathQuery.confirmManipulation(getRoot(), referencingProjects); }
Example 13
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean canEnable() throws JavaModelException { if (!super.canEnable()) return false; IPackageFragmentRoot[] roots= getPackageFragmentRoots(); for (int i= 0; i < roots.length; i++) { IPackageFragmentRoot root= roots[i]; if (root.isReadOnly() && !root.isArchive() && !root.isExternal()) { final ResourceAttributes attributes= roots[i].getResource().getResourceAttributes(); if (attributes == null || attributes.isReadOnly()) return false; } } return roots.length > 0; }
Example 14
Source File: JavaElementAdapterFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IResource getResource(IJavaElement element) { // can't use IJavaElement.getResource directly as we are interested in the // corresponding resource switch (element.getElementType()) { case IJavaElement.TYPE: // top level types behave like the CU IJavaElement parent= element.getParent(); if (parent instanceof ICompilationUnit) { return ((ICompilationUnit) parent).getPrimary().getResource(); } return null; case IJavaElement.COMPILATION_UNIT: return ((ICompilationUnit) element).getPrimary().getResource(); case IJavaElement.CLASS_FILE: case IJavaElement.PACKAGE_FRAGMENT: // test if in a archive IPackageFragmentRoot root= (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (!root.isArchive() && !root.isExternal()) { return element.getResource(); } return null; case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.JAVA_PROJECT: case IJavaElement.JAVA_MODEL: return element.getResource(); default: return null; } }
Example 15
Source File: PackageBrowseAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
static boolean canAddPackageRoot(IPackageFragmentRoot root) throws JavaModelException{ if (! root.exists()) return false; if (root.isArchive()) return false; if (root.isExternal()) return false; if (root.isReadOnly()) return false; if (! root.isStructureKnown()) return false; return true; }
Example 16
Source File: JavaElementResourceMapping.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static ResourceMapping create(final IPackageFragment pack) { // test if in an archive IPackageFragmentRoot root= (IPackageFragmentRoot)pack.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (!root.isArchive() && !root.isExternal()) { return new PackageFragmentResourceMapping(pack); } return null; }
Example 17
Source File: RefactoringAvailabilityTester.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isRenameAvailable(final IPackageFragmentRoot root) throws JavaModelException { if (root == null) return false; if (!Checks.isAvailable(root)) return false; if (root.isArchive()) return false; if (root.isExternal()) return false; if (!root.isConsistent()) return false; if (root.getResource() instanceof IProject) return false; return true; }
Example 18
Source File: Storage2UriMapperJavaImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private PackageFragmentRootData getData(IPackageFragmentRoot root) { final boolean isCachable = root.isArchive() || root.isExternal(); if (isCachable) { return getCachedData(root); } PackageFragmentRootData data = initializeData(root); return data; }
Example 19
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override protected RefactoringStatus verifyDestination(IJavaElement javaElement) throws JavaModelException { Assert.isNotNull(javaElement); if (!fCheckDestination) { return new RefactoringStatus(); } if (!javaElement.exists()) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_doesnotexist0); } if (javaElement instanceof IJavaModel) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_jmodel); } if (javaElement.isReadOnly()) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_readonly); } if (!javaElement.isStructureKnown()) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_structure); } if (javaElement instanceof IOpenable) { IOpenable openable= (IOpenable) javaElement; if (!openable.isConsistent()) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inconsistent); } } if (javaElement instanceof IPackageFragmentRoot) { IPackageFragmentRoot root= (IPackageFragmentRoot) javaElement; if (root.isArchive()) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_archive); } if (root.isExternal()) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_external); } } if (ReorgUtils.isInsideCompilationUnit(javaElement)) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot); } IContainer destinationAsContainer= getDestinationAsContainer(); if (destinationAsContainer == null || isChildOfOrEqualToAnyFolder(destinationAsContainer)) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource); } if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(javaElement)) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked); } return new RefactoringStatus(); }
Example 20
Source File: JarPackageWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean isInArchiveOrExternal(IJavaElement element) { IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element); return root != null && (root.isArchive() || root.isExternal()); }