Java Code Examples for org.eclipse.jdt.core.IPackageFragmentRoot#isArchive()
The following examples show how to use
org.eclipse.jdt.core.IPackageFragmentRoot#isArchive() .
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: JavadocTreeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Receives of list of elements selected by the user and passes them to the CheckedTree. List * can contain multiple projects and elements from different projects. If the list of seletected * elements is empty a default project is selected. * * @param sourceElements an array with the source elements */ private void setTreeChecked(IJavaElement[] sourceElements) { for (int i= 0; i < sourceElements.length; i++) { IJavaElement curr= sourceElements[i]; if (curr instanceof ICompilationUnit) { fInputGroup.initialCheckListItem(curr); } else if (curr instanceof IPackageFragment) { fInputGroup.initialCheckTreeItem(curr); } else if (curr instanceof IJavaProject) { fInputGroup.initialCheckTreeItem(curr); } else if (curr instanceof IPackageFragmentRoot) { IPackageFragmentRoot root= (IPackageFragmentRoot) curr; if (!root.isArchive()) fInputGroup.initialCheckTreeItem(curr); } } }
Example 2
Source File: ModuleUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Scans the package fragments (including jars if includeJars is true) invoking the visitor * callback. * * Stops if the callback returns a non-null result, and passes that result back to the caller. */ private static <T> T visitFragments(IJavaProject project, boolean includeJars, IPackageFragmentVisitor<T> visitor) { try { for (IPackageFragmentRoot pckgRoot : project.getPackageFragmentRoots()) { if (pckgRoot.isArchive() && !includeJars) { continue; } for (IJavaElement elem : pckgRoot.getChildren()) { T result = visitor.visit((IPackageFragment) elem); if (result != null) { return result; } } } } catch (JavaModelException e) { GWTPluginLog.logError(e); } return null; }
Example 3
Source File: JavaSearchScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public boolean encloses(IJavaElement element) { if (this.elements != null) { for (int i = 0, length = this.elements.size(); i < length; i++) { IJavaElement scopeElement = (IJavaElement)this.elements.get(i); IJavaElement searchedElement = element; while (searchedElement != null) { if (searchedElement.equals(scopeElement)) return true; searchedElement = searchedElement.getParent(); } } return false; } IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null && root.isArchive()) { // external or internal jar IPath rootPath = root.getPath(); String rootPathToString = rootPath.getDevice() == null ? rootPath.toString() : rootPath.toOSString(); IPath relativePath = getPath(element, true/*relative path*/); return indexOf(rootPathToString, relativePath.toString()) >= 0; } // resource in workspace String fullResourcePathString = getPath(element, false/*full path*/).toString(); return indexOf(fullResourcePathString) >= 0; }
Example 4
Source File: LibraryFilter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean select(Viewer viewer, Object parentElement, Object element) { if (element instanceof IPackageFragmentRoot) { IPackageFragmentRoot root= (IPackageFragmentRoot)element; if (root.isArchive()) { // don't filter out JARs contained in the project itself IResource resource= root.getResource(); if (resource != null) { IProject jarProject= resource.getProject(); IProject container= root.getJavaProject().getProject(); return container.equals(jarProject); } return false; } } else if (element instanceof ClassPathContainer.RequiredProjectWrapper) { return false; } return true; }
Example 5
Source File: PackagesViewHierarchicalContentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private Object getHierarchicalParent(IPackageFragment fragment) { IJavaElement parent= fragment.getParent(); if ((parent instanceof IPackageFragmentRoot) && parent.exists()) { IPackageFragmentRoot root= (IPackageFragmentRoot) parent; if (root.isArchive() || root.isExternal() || !fragment.exists()) { return findNextLevelParentByElementName(fragment); } else { IResource resource= fragment.getResource(); if ((resource != null) && (resource instanceof IFolder)) { IFolder folder= (IFolder) resource; IResource res= folder.getParent(); IJavaElement el= JavaCore.create(res); if (el != null) { return el; } else { return res; } } } } return parent; }
Example 6
Source File: XbaseResourceForEditorInputFactoryTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testValidationIsDisabled_03() throws Exception { IProject project = AbstractXbaseUITestCase.createPluginProject("my.plugin.project"); IJavaProject jp = JavaCore.create(project); boolean wasTested = false; for (IPackageFragmentRoot pfr : jp.getAllPackageFragmentRoots()) { if (pfr.isArchive()) { for (Object o : pfr.getNonJavaResources()) { if (o instanceof IStorage) { assertTrue(isValidationDisabled((IStorage) o)); wasTested = true; } } } } assertTrue(wasTested); }
Example 7
Source File: JarEntryLocator.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @return a URI for the given jarEntry, can be <code>null</code>. */ public URI getURI(IPackageFragmentRoot root, IJarEntryResource jarEntry, TraversalState state) { if (root.isArchive()) { URI jarURI = JarEntryURIHelper.getUriForPackageFragmentRoot(root); URI storageURI = URI.createURI(jarEntry.getFullPath().toString()); return createJarURI(root.isArchive(), jarURI, storageURI); } else if (root instanceof ExternalPackageFragmentRoot) { IResource resource = ((ExternalPackageFragmentRoot) root).resource(); IPath result = resource.getFullPath(); for(int i = 1; i < state.getParents().size(); i++) { Object obj = state.getParents().get(i); if (obj instanceof IPackageFragment) { result = result.append(new Path(((IPackageFragment) obj).getElementName().replace('.', '/'))); } else if (obj instanceof IJarEntryResource) { result = result.append(((IJarEntryResource) obj).getName()); } } result = result.append(jarEntry.getName()); return URI.createPlatformResourceURI(result.toString(), true); } else { throw new IllegalStateException("Unexpeced root type: " + root.getClass().getName()); } }
Example 8
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 9
Source File: JavaDeleteProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean skipDeletingReferencedRoot(IConfirmQuery query, IPackageFragmentRoot root, List<IJavaProject> referencingProjects) throws OperationCanceledException { if (referencingProjects.isEmpty() || root == null || ! root.exists() ||! root.isArchive()) return false; String label= JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT); String question= referencingProjects.size() == 1 ? Messages.format(RefactoringCoreMessages.DeleteRefactoring_3_singular, label) : Messages.format( RefactoringCoreMessages.DeleteRefactoring_3_plural, label); return ! query.confirm(question, referencingProjects.toArray()); }
Example 10
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 11
Source File: JavaElementResourceMapping.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static ResourceMapping create(IClassFile classFile) { // test if in a archive IPackageFragmentRoot root= (IPackageFragmentRoot)classFile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (!root.isArchive() && !root.isExternal()) { return new ClassFileResourceMapping(classFile); } return null; }
Example 12
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 13
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isClasspathDelete(IPackageFragmentRoot pkgRoot) { IResource res= pkgRoot.getResource(); if (res == null) return true; IProject definingProject= res.getProject(); if (res.getParent() != null && pkgRoot.isArchive() && ! res.getParent().equals(definingProject)) return true; IProject occurringProject= pkgRoot.getJavaProject().getProject(); return !definingProject.equals(occurringProject); }
Example 14
Source File: JavaElementResourceMapping.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static ResourceMapping create(LogicalPackage logicalPackage) { IPackageFragment[] fragments= logicalPackage.getFragments(); List<IPackageFragment> toProcess= new ArrayList<IPackageFragment>(fragments.length); for (int i= 0; i < fragments.length; i++) { // only add if not part of an archive IPackageFragmentRoot root= (IPackageFragmentRoot)fragments[i].getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (!root.isArchive() && !root.isExternal()) { toProcess.add(fragments[i]); } } if (toProcess.size() == 0) return null; return new LogicalPackageResourceMapping(toProcess.toArray(new IPackageFragment[toProcess.size()])); }
Example 15
Source File: TypeParameterPattern.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor progressMonitor) { IPackageFragmentRoot root = (IPackageFragmentRoot) this.typeParameter.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); String documentPath; String relativePath; if (root.isArchive()) { IType type = (IType) this.typeParameter.getAncestor(IJavaElement.TYPE); relativePath = (type.getFullyQualifiedName('$')).replace('.', '/') + SuffixConstants.SUFFIX_STRING_class; documentPath = root.getPath() + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + relativePath; } else { IPath path = this.typeParameter.getPath(); documentPath = path.toString(); relativePath = Util.relativePath(path, 1/*remove project segment*/); } if (scope instanceof JavaSearchScope) { JavaSearchScope javaSearchScope = (JavaSearchScope) scope; // Get document path access restriction from java search scope // Note that requestor has to verify if needed whether the document violates the access restriction or not AccessRuleSet access = javaSearchScope.getAccessRuleSet(relativePath, index.containerPath); if (access != JavaSearchScope.NOT_ENCLOSED) { // scope encloses the path if (!requestor.acceptIndexMatch(documentPath, this, participant, access)) throw new OperationCanceledException(); } } else if (scope.encloses(documentPath)) { if (!requestor.acceptIndexMatch(documentPath, this, participant, null)) throw new OperationCanceledException(); } }
Example 16
Source File: JavaElementResourceMapping.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static ResourceMapping create(IClassFile classFile) { // test if in a archive IPackageFragmentRoot root= (IPackageFragmentRoot)classFile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (!root.isArchive() && !root.isExternal()) { return new ClassFileResourceMapping(classFile); } return null; }
Example 17
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 18
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 19
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 20
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(); }