Java Code Examples for org.eclipse.jdt.core.IPackageFragmentRoot#getPath()
The following examples show how to use
org.eclipse.jdt.core.IPackageFragmentRoot#getPath() .
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.4 */ @Override public Pair<URI, URI> getURIMapping(IPackageFragmentRoot root) throws JavaModelException { PackageFragmentRootData data = getData(root); if (data.uriPrefix == null) return null; IPath path = root.isExternal() ? root.getPath() : root.getUnderlyingResource().getLocation(); URI physical = null; if (root.isArchive()) { String archiveScheme = "zip".equalsIgnoreCase(root.getPath().getFileExtension()) ? "zip" : "jar"; physical = URI.createURI(archiveScheme+":file:"+path.toFile().getPath()+"!/"); } else { physical = URI.createFileURI(path.toFile().getPath()+"/"); } return Tuples.create(data.uriPrefix, physical); }
Example 2
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 3
Source File: TraceForTypeRootProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected IPath getSourcePath(final ITypeRoot derivedJavaType) { IJavaElement current = derivedJavaType.getParent(); while (current != null) { if (current instanceof IPackageFragmentRoot) { IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot) current; try { IPath attachmentPath = fragmentRoot.getSourceAttachmentPath(); if (attachmentPath != null) return attachmentPath; } catch (JavaModelException e) { } if (current instanceof JarPackageFragmentRoot) return fragmentRoot.getPath(); } current = current.getParent(); } return null; }
Example 4
Source File: FixedFatJarExportPage.java From sarl with Apache License 2.0 | 6 votes |
private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) { try { IClasspathEntry cpe= root.getRawClasspathEntry(); if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation= cpe.getOutputLocation(); if (outputLocation == null) outputLocation= root.getJavaProject().getOutputLocation(); IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation(); if (entry.equals(location)) return true; } } catch (JavaModelException e) { JavaPlugin.log(e); } IResource resource= root.getResource(); if (resource != null && entry.equals(resource.getLocation())) return true; IPath path= root.getPath(); if (path != null && entry.equals(path)) return true; return false; }
Example 5
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 6
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 7
Source File: FatJarPackageWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) { try { IClasspathEntry cpe= root.getRawClasspathEntry(); if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation= cpe.getOutputLocation(); if (outputLocation == null) outputLocation= root.getJavaProject().getOutputLocation(); IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation(); if (entry.equals(location)) return true; } } catch (JavaModelException e) { JavaPlugin.log(e); } IResource resource= root.getResource(); if (resource != null && entry.equals(resource.getLocation())) return true; IPath path= root.getPath(); if (path != null && entry.equals(path)) return true; return false; }
Example 8
Source File: EclipseResourceTypeDetector.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the given resource is a test resource according to the Java or Maven standard. * * @param resource the resource to test. * @return {@link Boolean#TRUE} if the resource is a test resource. {@link Boolean#FALSE} * if the resource is not a test resource. {@code null} if the detector cannot determine * the type of the resource. */ @SuppressWarnings("checkstyle:nestedifdepth") protected static Boolean isJavaOrMavenTestResource(Resource resource) { final URI uri = resource.getURI(); if (uri.isPlatformResource()) { final String platformString = uri.toPlatformString(true); final IResource iresource = ResourcesPlugin.getWorkspace().getRoot().findMember(platformString); if (iresource != null) { final IProject project = iresource.getProject(); final IJavaProject javaProject = JavaCore.create(project); try { final IPackageFragment packageFragment = javaProject.findPackageFragment(iresource.getParent().getFullPath()); final IPackageFragmentRoot root = (IPackageFragmentRoot) packageFragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null) { final IPath rootPath = root.getPath(); String name = null; if (root.isExternal()) { name = rootPath.toOSString(); } else if (javaProject.getElementName().equals(rootPath.segment(0))) { if (rootPath.segmentCount() != 1) { name = rootPath.removeFirstSegments(1).makeRelative().toString(); } } else { name = rootPath.toString(); } if (name != null && name.startsWith(SARLConfig.FOLDER_MAVEN_TEST_PREFIX)) { return Boolean.TRUE; } } } catch (JavaModelException e) { // } } } return null; }
Example 9
Source File: XtextProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void completeGrammar_Name(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { Resource resource = model.eResource(); URI uri = resource.getURI(); if (uri.isPlatformResource()) { IPath path = new Path(uri.toPlatformString(true)); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); IProject project = file.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { try { for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) { IPath packageFragmentRootPath = packageFragmentRoot.getPath(); if (packageFragmentRootPath.isPrefixOf(path)) { IPath relativePath = path.makeRelativeTo(packageFragmentRootPath); relativePath = relativePath.removeFileExtension(); String result = relativePath.toString(); result = result.replace('/', '.'); acceptor.accept(createCompletionProposal(result, context)); return; } } } catch (JavaModelException ex) { // nothing to do } } } }
Example 10
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 11
Source File: JavaElementLabelComposer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) { IPath path; IClasspathEntry classpathEntry= null; try { classpathEntry= JavaModelUtil.getClasspathEntry(root); IPath rawPath= classpathEntry.getPath(); if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute()) path= rawPath; else path= root.getPath(); } catch (JavaModelException e) { path= root.getPath(); } if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { int segements= path.segmentCount(); if (segements > 0) { fBuffer.append(path.segment(segements - 1)); int offset= fBuffer.length(); if (segements > 1 || path.getDevice() != null) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); } if (classpathEntry != null) { IClasspathEntry referencingEntry= classpathEntry.getReferencingEntry(); if (referencingEntry != null) { fBuffer.append(Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() })); } } if (getFlag(flags, JavaElementLabels.COLORIZE)) { fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); } } else { fBuffer.append(path.toOSString()); } } else { fBuffer.append(path.toOSString()); } }
Example 12
Source File: JavaElementComparator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private int getClassPathIndex(IPackageFragmentRoot root) { try { IPath rootPath= root.getPath(); IPackageFragmentRoot[] roots= root.getJavaProject().getPackageFragmentRoots(); for (int i= 0; i < roots.length; i++) { if (roots[i].getPath().equals(rootPath)) { return i; } } } catch (JavaModelException e) { } return Integer.MAX_VALUE; }
Example 13
Source File: RenameSourceFolderChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public RenameSourceFolderChange(IPackageFragmentRoot sourceFolder, String newName) { this(sourceFolder.getPath(), sourceFolder.getElementName(), newName, IResource.NULL_STAMP); Assert.isTrue(!sourceFolder.isReadOnly(), "should not be read only"); //$NON-NLS-1$ Assert.isTrue(!sourceFolder.isArchive(), "should not be an archive"); //$NON-NLS-1$ Assert.isTrue(!sourceFolder.isExternal(), "should not be an external folder"); //$NON-NLS-1$ setValidationMethod(VALIDATE_NOT_DIRTY); }
Example 14
Source File: NewModuleWizardPage.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
protected IPath getModulePath() { IPackageFragmentRoot root = getPackageFragmentRoot(); IPath rootPath = root.getPath(); String packageName = getModulePackageName(); if (packageName != null && packageName.length() > 0) { rootPath = rootPath.append(packageName.replace('.', '/')); } IPath moduleFilePath = rootPath.append(getModuleName()); moduleFilePath = moduleFilePath.addFileExtension("gwt.xml"); return moduleFilePath; }
Example 15
Source File: JavaElementLabelComposer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) { IPath path; IClasspathEntry classpathEntry= null; try { classpathEntry= JavaModelUtil.getClasspathEntry(root); IPath rawPath= classpathEntry.getPath(); if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute()) { path= rawPath; } else { path= root.getPath(); } } catch (JavaModelException e) { path= root.getPath(); } if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { int segments= path.segmentCount(); if (segments > 0) { fBuilder.append(path.segment(segments - 1)); if (segments > 1 || path.getDevice() != null) { fBuilder.append(JavaElementLabels.CONCAT_STRING); fBuilder.append(path.removeLastSegments(1).toOSString()); } if (classpathEntry != null) { IClasspathEntry referencingEntry= classpathEntry.getReferencingEntry(); if (referencingEntry != null) { fBuilder.append(NLS.bind(" (from {0} of {1})", new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() })); } } } else { fBuilder.append(path.toOSString()); } } else { fBuilder.append(path.toOSString()); } }
Example 16
Source File: MavenBuildSupport.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void discoverSource(IClassFile classFile, IProgressMonitor monitor) throws CoreException { if (classFile == null) { return; } IJavaElement element = classFile; while (element.getParent() != null) { element = element.getParent(); if (element instanceof IPackageFragmentRoot) { final IPackageFragmentRoot fragment = (IPackageFragmentRoot) element; IPath attachmentPath = fragment.getSourceAttachmentPath(); if (attachmentPath != null && !attachmentPath.isEmpty() && attachmentPath.toFile().exists()) { break; } if (fragment.isArchive()) { IPath path = fragment.getPath(); Boolean downloaded = downloadRequestsCache.getIfPresent(path.toString()); if (downloaded == null) { downloadRequestsCache.put(path.toString(), true); IClasspathManager buildpathManager = MavenJdtPlugin.getDefault().getBuildpathManager(); buildpathManager.scheduleDownload(fragment, true, true); JobHelpers.waitForDownloadSourcesJobs(MAX_TIME_MILLIS); } break; } } } }
Example 17
Source File: NewTypeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * A hook method that gets called when the package field has changed. The method * validates the package name and returns the status of the validation. The validation * also updates the package fragment model. * <p> * Subclasses may extend this method to perform their own validation. * </p> * * @return the status of the validation */ protected IStatus packageChanged() { StatusInfo status= new StatusInfo(); IPackageFragmentRoot root= getPackageFragmentRoot(); fPackageDialogField.enableButton(root != null); IJavaProject project= root != null ? root.getJavaProject() : null; String packName= getPackageText(); if (packName.length() > 0) { IStatus val= validatePackageName(packName, project); if (val.getSeverity() == IStatus.ERROR) { status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage())); // continue } } else { status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged); } if (project != null) { if (project.exists() && packName.length() > 0) { try { IPath rootPath= root.getPath(); IPath outputPath= project.getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, don't allow to name a package // like the bin folder IPath packagePath= rootPath.append(packName.replace('.', '/')); if (outputPath.isPrefixOf(packagePath)) { status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation); return status; } } } catch (JavaModelException e) { JavaPlugin.log(e); // let pass } } fCurrPackage= root.getPackageFragment(packName); IResource resource= fCurrPackage.getResource(); if (resource != null){ if (resource.isVirtual()){ status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageIsVirtual); return status; } if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) { status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageNameFiltered); return status; } } } else { status.setError(""); //$NON-NLS-1$ } return status; }
Example 18
Source File: NewPackageWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Validates the package name and returns the status of the validation. * * @param packName the package name * * @return the status of the validation */ private IStatus getPackageStatus(String packName) { StatusInfo status= new StatusInfo(); if (packName.length() > 0) { IStatus val= validatePackageName(packName); if (val.getSeverity() == IStatus.ERROR) { status.setError(Messages.format(NewWizardMessages.NewPackageWizardPage_error_InvalidPackageName, val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(Messages.format(NewWizardMessages.NewPackageWizardPage_warning_DiscouragedPackageName, val.getMessage())); } } else { status.setError(NewWizardMessages.NewPackageWizardPage_error_EnterName); return status; } IPackageFragmentRoot root= getPackageFragmentRoot(); if (root != null && root.getJavaProject().exists()) { IPackageFragment pack= root.getPackageFragment(packName); try { IPath rootPath= root.getPath(); IPath outputPath= root.getJavaProject().getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, don't allow to name a package // like the bin folder IPath packagePath= pack.getPath(); if (outputPath.isPrefixOf(packagePath)) { status.setError(NewWizardMessages.NewPackageWizardPage_error_IsOutputFolder); return status; } } if (pack.exists()) { // it's ok for the package to exist as long we want to create package level documentation // and the package level documentation doesn't exist if (!isCreatePackageDocumentation() || packageDocumentationAlreadyExists(pack)) { if (pack.containsJavaResources() || !pack.hasSubpackages()) { status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageExists); } else { status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageNotShown); } } } else { IResource resource= pack.getResource(); if (resource != null && !ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) { status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageNameFiltered); return status; } URI location= pack.getResource().getLocationURI(); if (location != null) { IFileStore store= EFS.getStore(location); if (store.fetchInfo().exists()) { status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageExistsDifferentCase); } } } } catch (CoreException e) { JavaPlugin.log(e); } } return status; }
Example 19
Source File: NewModuleWizardPage.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
private IStatus packageChanged() { String packName = modulePackageField.getText(); IStatus validatePackageStatus = Util.validatePackageName(packName); if (validatePackageStatus.getSeverity() == IStatus.ERROR) { return validatePackageStatus; } if (packName.length() == 0) { modulePackageField.setStatus(NewWizardMessages.NewTypeWizardPage_default); } else { modulePackageField.setStatus(""); } IJavaProject project = getJavaProject(); IPackageFragmentRoot root = getPackageFragmentRoot(); if (project != null && root != null) { if (project.exists() && packName.length() > 0) { try { IPath rootPath = root.getPath(); IPath outputPath = project.getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, don't allow to name a // package like the bin folder IPath packagePath = rootPath.append(packName.replace('.', '/')); if (outputPath.isPrefixOf(packagePath)) { return Util.newErrorStatus(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation); } } } catch (JavaModelException e) { // Not a critical exception at this juncture; we'll just log it // and move on. GWTPluginLog.logError(e); } } } return validatePackageStatus; }