Java Code Examples for org.eclipse.core.runtime.IPath#segmentCount()
The following examples show how to use
org.eclipse.core.runtime.IPath#segmentCount() .
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: TarLeveledStructureProvider.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Initializes this object's children table based on the contents of the * specified source file. */ protected void initialize() { children = new HashMap<>(1000); children.put(root, new ArrayList<>()); Enumeration<TarArchiveEntry> entries = tarFile.entries(); while (entries.hasMoreElements()) { TarArchiveEntry entry = entries.nextElement(); IPath path = new Path(entry.getName()).addTrailingSeparator(); if (entry.isDirectory()) { createContainer(path); } else { // Ensure the container structure for all levels above this is initialized // Once we hit a higher-level container that's already added we need go no further int pathSegmentCount = path.segmentCount(); if (pathSegmentCount > 1) { createContainer(path.uptoSegment(pathSegmentCount - 1)); } createFile(entry); } } }
Example 2
Source File: ClasspathUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Returns the first index of the specified * {@link IClasspathEntry#CPE_CONTAINER} entry with the specified container ID * or -1 if one could not be found. * * @param classpathEntries array of classpath entries * @param containerId container ID * @return index of the specified {@link IClasspathEntry#CPE_CONTAINER} entry * with the specified container ID or -1 */ public static int indexOfClasspathEntryContainer( IClasspathEntry[] classpathEntries, String containerId) { for (int i = 0; i < classpathEntries.length; ++i) { IClasspathEntry classpathEntry = classpathEntries[i]; if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { // Skip anything that is not a container continue; } IPath containerPath = classpathEntry.getPath(); if (containerPath.segmentCount() > 0 && containerPath.segment(0).equals(containerId)) { return i; } } return -1; }
Example 3
Source File: BuildPathsBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private CPListElement findElement(IClasspathEntry entry) { CPListElement prefixMatch= null; int entryKind= entry.getEntryKind(); for (int i= 0, len= fClassPathList.getSize(); i < len; i++) { CPListElement curr= fClassPathList.getElement(i); if (curr.getEntryKind() == entryKind) { IPath entryPath= entry.getPath(); IPath currPath= curr.getPath(); if (currPath.equals(entryPath)) { return curr; } // in case there's no full match, look for a similar container (same ID segment): if (prefixMatch == null && entryKind == IClasspathEntry.CPE_CONTAINER) { int n= entryPath.segmentCount(); if (n > 0) { IPath genericContainerPath= n == 1 ? entryPath : entryPath.removeLastSegments(n - 1); if (n > 1 && genericContainerPath.isPrefixOf(currPath)) { prefixMatch= curr; } } } } } return prefixMatch; }
Example 4
Source File: LibrariesWorkbookPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IPath[] getUsedContainers(CPListElement existing) { ArrayList<IPath> res= new ArrayList<IPath>(); if (fCurrJProject.exists()) { try { IPath outputLocation= fCurrJProject.getOutputLocation(); if (outputLocation != null && outputLocation.segmentCount() > 1) { // != Project res.add(outputLocation); } } catch (JavaModelException e) { // ignore it here, just log JavaPlugin.log(e.getStatus()); } } List<CPListElement> cplist= fLibrariesList.getElements(); for (int i= 0; i < cplist.size(); i++) { CPListElement elem= cplist.get(i); if (elem.getEntryKind() == IClasspathEntry.CPE_LIBRARY && (elem != existing)) { IResource resource= elem.getResource(); if (resource instanceof IContainer && !resource.equals(existing)) { res.add(resource.getFullPath()); } } } return res.toArray(new IPath[res.size()]); }
Example 5
Source File: WizardFileSystemResourceExportPage2.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * Returns the name of a container with a location that encompasses targetDirectory. Returns null if there is no * conflict. * @param targetDirectory * the path of the directory to check. * @return the conflicting container name or <code>null</code> */ protected String getConflictingContainerNameFor(String targetDirectory) { IPath rootPath = ResourcesPlugin.getWorkspace().getRoot().getLocation(); IPath testPath = new Path(targetDirectory); // cannot export into workspace root if (testPath.equals(rootPath)) return rootPath.lastSegment(); // Are they the same? if (testPath.matchingFirstSegments(rootPath) == rootPath.segmentCount()) { String firstSegment = testPath.removeFirstSegments(rootPath.segmentCount()).segment(0); if (!Character.isLetterOrDigit(firstSegment.charAt(0))) return firstSegment; } return null; }
Example 6
Source File: EditorInputFactory.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Creates an editor input for the passed file. * * If forceExternalFile is True, it won't even try to create a FileEditorInput, otherwise, * it will try to create it with the most suitable type it can * (i.e.: FileEditorInput, FileStoreEditorInput, PydevFileEditorInput, ...) */ public static IEditorInput create(File file, boolean forceExternalFile) { IPath path = Path.fromOSString(FileUtils.getFileAbsolutePath(file)); if (!forceExternalFile) { //May call again to this method (but with forceExternalFile = true) IEditorInput input = new PySourceLocatorBase().createEditorInput(path, false, null, null); if (input != null) { return input; } } IPath zipPath = new Path(""); while (path.segmentCount() > 0) { if (path.toFile().exists()) { break; } zipPath = new Path(path.lastSegment()).append(zipPath); path = path.uptoSegment(path.segmentCount() - 1); } if (zipPath.segmentCount() > 0 && path.segmentCount() > 0) { return new PydevZipFileEditorInput(new PydevZipFileStorage(path.toFile(), zipPath.toPortableString())); } try { URI uri = file.toURI(); return new FileStoreEditorInput(EFS.getStore(uri)); } catch (Throwable e) { //not always available! (only added in eclipse 3.3) return new PydevFileEditorInput(file); } }
Example 7
Source File: TransferServlet.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { traceRequest(req); String pathInfo = req.getPathInfo(); IPath path = pathInfo == null ? Path.ROOT : new Path(pathInfo); String id; //format is /xfer/import/<uuid> if (path.segmentCount() == 2) { id = path.segment(1); ClientImport importOp = new ClientImport(id, getStatusHandler()); importOp.doPut(req, resp); return; } super.doPut(req, resp); }
Example 8
Source File: NewJavaProjectWizardPageOne.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the source class path entries to be added on new projects. * The underlying resource may not exist. * * @return returns the default class path entries */ public IPath getOutputLocation() { IPath outputLocationPath= new Path(getProjectName()).makeAbsolute(); if (fLayoutGroup.isSrcBin()) { IPath binPath= new Path(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); if (binPath.segmentCount() > 0) { outputLocationPath= outputLocationPath.append(binPath); } } return outputLocationPath; }
Example 9
Source File: SarlClassPathDetector.java From sarl with Apache License 2.0 | 5 votes |
private static int computeOrderPriority(IPath path) { final int len = path.segmentCount(); if (len >= 2 && "generated-sources".equals(path.segment(len - 2))) { //$NON-NLS-1$ return 0; } if (len >= 1 && "sarl".equals(path.segment(len - 1))) { //$NON-NLS-1$ return 2; } return 1; }
Example 10
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 11
Source File: FixedFatJarExportPage.java From sarl with Apache License 2.0 | 5 votes |
/** * Stores the widget values in the JAR package. */ @Override protected void updateModel() { super.updateModel(); String comboText= fAntScriptNamesCombo.getText(); IPath path= Path.fromOSString(comboText); if (path.segmentCount() > 0 && ensureAntScriptFileIsValid(path.toFile()) && path.getFileExtension() == null) path= path.addFileExtension(ANTSCRIPT_EXTENSION); fAntScriptLocation= getAbsoluteLocation(path); }
Example 12
Source File: GenerateAll.java From eip-designer with Apache License 2.0 | 5 votes |
/** * Finds the template in the plug-in. Returns the template plug-in URI. * * @param bundleID * is the plug-in ID * @param relativePath * is the relative path of the template in the plug-in * @return the template URI * @throws IOException * @generated */ @SuppressWarnings("unchecked") private URI getTemplateURI(String bundleID, IPath relativePath) throws IOException { Bundle bundle = Platform.getBundle(bundleID); if (bundle == null) { // no need to go any further return URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false); } URL url = bundle.getEntry(relativePath.toString()); if (url == null && relativePath.segmentCount() > 1) { Enumeration<URL> entries = bundle.findEntries("/", "*.emtl", true); if (entries != null) { String[] segmentsRelativePath = relativePath.segments(); while (url == null && entries.hasMoreElements()) { URL entry = entries.nextElement(); IPath path = new Path(entry.getPath()); if (path.segmentCount() > relativePath.segmentCount()) { path = path.removeFirstSegments(path.segmentCount() - relativePath.segmentCount()); } String[] segmentsPath = path.segments(); boolean equals = segmentsPath.length == segmentsRelativePath.length; for (int i = 0; equals && i < segmentsPath.length; i++) { equals = segmentsPath[i].equals(segmentsRelativePath[i]); } if (equals) { url = bundle.getEntry(entry.getPath()); } } } } URI result; if (url != null) { result = URI.createPlatformPluginURI(new Path(bundleID).append(new Path(url.getPath())).toString(), false); } else { result = URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false); } return result; }
Example 13
Source File: Uml2Service.java From uml2solidity with Eclipse Public License 1.0 | 5 votes |
/** * Returns the directory where the junit tests can pickup the contract code. * * @param an * element * @return */ public static String getContractPathForJava(NamedElement clazz) { IPreferenceStore store = getStore(clazz); String co = store.getString(PreferenceConstants.GENERATION_TARGET); Path path = new Path(co); String javaTestDirectory = getJavaSourceDirectory(clazz); Path path2 = new Path(javaTestDirectory); IPath makeRelativeTo = path.makeRelativeTo(path2); //TODO: this is a hack only working in the default test setup if(makeRelativeTo.segmentCount()>2) makeRelativeTo = makeRelativeTo.removeFirstSegments(2); else if(makeRelativeTo.segmentCount()==2) return ""; return makeRelativeTo.toString(); }
Example 14
Source File: GenerateXml.java From eip-designer with Apache License 2.0 | 5 votes |
/** * Finds the template in the plug-in. Returns the template plug-in URI. * * @param bundleID * is the plug-in ID * @param relativePath * is the relative path of the template in the plug-in * @return the template URI * @throws IOException * @generated */ @SuppressWarnings("unchecked") private URI getTemplateURI(String bundleID, IPath relativePath) throws IOException { Bundle bundle = Platform.getBundle(bundleID); if (bundle == null) { // no need to go any further return URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false); } URL url = bundle.getEntry(relativePath.toString()); if (url == null && relativePath.segmentCount() > 1) { Enumeration<URL> entries = bundle.findEntries("/", "*.emtl", true); if (entries != null) { String[] segmentsRelativePath = relativePath.segments(); while (url == null && entries.hasMoreElements()) { URL entry = entries.nextElement(); IPath path = new Path(entry.getPath()); if (path.segmentCount() > relativePath.segmentCount()) { path = path.removeFirstSegments(path.segmentCount() - relativePath.segmentCount()); } String[] segmentsPath = path.segments(); boolean equals = segmentsPath.length == segmentsRelativePath.length; for (int i = 0; equals && i < segmentsPath.length; i++) { equals = segmentsPath[i].equals(segmentsRelativePath[i]); } if (equals) { url = bundle.getEntry(entry.getPath()); } } } } URI result; if (url != null) { result = URI.createPlatformPluginURI(new Path(bundleID).append(new Path(url.getPath())).toString(), false); } else { result = URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(), false); } return result; }
Example 15
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 16
Source File: ImportProjectWizardPage2.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * Returns whether the given project description file path is in the * default location for a project * * @param path * The path to examine * @return Whether the given path is the default location for a project */ private boolean isDefaultLocation(IPath path) { // The project description file must at least be within the project, // which is within the workspace location if (path.segmentCount() < 2) return false; return path.removeLastSegments(2).toFile().equals( Platform.getLocation().toFile()); }
Example 17
Source File: JavaProject.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public boolean contains(IResource resource) { IClasspathEntry[] classpath; IPath output; try { classpath = getResolvedClasspath(); output = getOutputLocation(); } catch (JavaModelException e) { return false; } IPath fullPath = resource.getFullPath(); IPath innerMostOutput = output.isPrefixOf(fullPath) ? output : null; IClasspathEntry innerMostEntry = null; ExternalFoldersManager foldersManager = JavaModelManager.getExternalManager(); for (int j = 0, cpLength = classpath.length; j < cpLength; j++) { IClasspathEntry entry = classpath[j]; IPath entryPath = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IResource linkedFolder = foldersManager.getFolder(entryPath); if (linkedFolder != null) entryPath = linkedFolder.getFullPath(); } if ((innerMostEntry == null || innerMostEntry.getPath().isPrefixOf(entryPath)) && entryPath.isPrefixOf(fullPath)) { innerMostEntry = entry; } IPath entryOutput = classpath[j].getOutputLocation(); if (entryOutput != null && entryOutput.isPrefixOf(fullPath)) { innerMostOutput = entryOutput; } } if (innerMostEntry != null) { // special case prj==src and nested output location if (innerMostOutput != null && innerMostOutput.segmentCount() > 1 // output isn't project && innerMostEntry.getPath().segmentCount() == 1) { // 1 segment must be project name return false; } if (resource instanceof IFolder) { // folders are always included in src/lib entries return true; } switch (innerMostEntry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: // .class files are not visible in source folders return !org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(fullPath.lastSegment()); case IClasspathEntry.CPE_LIBRARY: // .java files are not visible in library folders return !org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(fullPath.lastSegment()); } } if (innerMostOutput != null) { return false; } return true; }
Example 18
Source File: SdkClasspathContainer.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 3 votes |
/** * Returns <code>true</code> if the specified path is a default container path * which means that it has a single segment and that segment matches the * container ID. * * @param containerId container ID that should be associated with the default * path * @param path the path to test */ public static boolean isDefaultContainerPath(String containerId, IPath path) { // NOTE: Technically we should get a ClasspathContainerInitializer and ask // it for the comparison ID, but we have no project to pass to them. // If the path has just one segment, the SDK is default and if the path has another segment, // we check if it is the datanucleus version number. return isContainerPath(containerId, path) && (path.segmentCount() == 1 || path.segment(1).matches("v[0-9]{1,2}")); }
Example 19
Source File: JarManifestWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Creates a file resource handle for the file with the given workspace path. * This method does not create the file resource; this is the responsibility * of <code>createFile</code>. * * @param filePath the path of the file resource to create a handle for * @return the new file resource handle */ protected IFile createFileHandle(IPath filePath) { if (filePath.isValidPath(filePath.toString()) && filePath.segmentCount() >= 2) return JavaPlugin.getWorkspace().getRoot().getFile(filePath); else return null; }
Example 20
Source File: ModuleSpecifierSelectionDialog.java From n4js with Eclipse Public License 1.0 | 3 votes |
/** * Returns true if the path is a module file specifier. * * <p> * Note: A module file specifier doesn't only specify the container of the new class file but also the file in which * the class is contained in. * </p> * * @param path * The path to examine * @return True if the path is a module file specifier */ private static boolean isModuleFileSpecifier(IPath path) { if (path.segmentCount() < 1) { return false; } String stringPath = path.toString(); return stringPath.charAt(stringPath.length() - 1) != '/'; }