/** * * @param path1 the first path * @param path2 the second path * @return <code>true</code> if path1 is a subfolder of * path2, <code>false</code> otherwise */ private boolean isSubFolderOf(IPath path1, IPath path2) { if (path1 == null || path2 == null) { if (path1 == null && path2 == null) return true; return false; } return path2.matchingFirstSegments(path1) == path2.segmentCount(); }
/** * * @param path1 the first path * @param path2 the second path * @return <code>true</code> if path1 is a subfolder of * path2, <code>false</code> otherwise */ private boolean isSubFolderOf(IPath path1, IPath path2) { if (path1 == null || path2 == null) { if (path1 == null && path2 == null) return true; return false; } return path2.matchingFirstSegments(path1) == path2.segmentCount(); }
@Override public IPath computePath(File source) { IPath result = new Path(source.getAbsolutePath()); IPath rootPath = new Path(root.getAbsolutePath()); result = result.removeFirstSegments(rootPath.matchingFirstSegments(result)); return result.setDevice(null); }
/** * * @param path1 the first path * @param path2 the second path * @return <code>true</code> if path1 is a subfolder of * path2, <code>false</code> otherwise */ private boolean isSubFolderOf(IPath path1, IPath path2) { if (path1 == null || path2 == null) { if (path1 == null && path2 == null) return true; return false; } return path2.matchingFirstSegments(path1) == path2.segmentCount(); }
public void handleEvent(Event e) { if (repositoryToCreate.getText().equals("")) { //$NON-NLS-1$ createRepo.setEnabled(false); return; } IPath fromOSString = Path.fromOSString(repositoryToCreate .getText()); createRepo.setEnabled(minumumPath .matchingFirstSegments(fromOSString) == fromOSString .segmentCount()); } });
public IPath computePath(File source) { IPath result = new Path(source.getAbsolutePath()); IPath rootPath = new Path(root.getAbsolutePath()); result = result.removeFirstSegments(rootPath.matchingFirstSegments(result)); return result.setDevice(null); }
public IPath computePath(File source) { IPath result = new Path(source.getAbsolutePath()); IPath rootPath = new Path(root.getAbsolutePath()); result = result.removeFirstSegments(rootPath.matchingFirstSegments(result)); return result.setDevice(null); }
@Override public IPath computePath(File source) { String prefix = filesMap.get(source); IPath result = null; if (prefix.startsWith(PROVIDED_PATH)) { // the desired path is provided in the map result = new Path(prefix.substring(10)); } else { //else the map contains a prefix which must be stripped from the path result = new Path(source.getAbsolutePath()); IPath rootPath = new Path(prefix); result = result.removeFirstSegments(rootPath.matchingFirstSegments(result)); } return result.setDevice(null); }
public IPath computePath(File source) { IPath result = new Path(source.getAbsolutePath()); IPath rootPath = new Path(root.getAbsolutePath()); result = result.removeFirstSegments(rootPath.matchingFirstSegments(result)); return result.setDevice(null); }
public IPath computePath(File source) { String prefix = filesMap.get(source); IPath result = null; if (prefix.startsWith(PROVIDED_PATH)) { // the desired path is provided in the map result = new Path(prefix.substring(10)); } else { //else the map contains a prefix which must be stripped from the path result = new Path(source.getAbsolutePath()); IPath rootPath = new Path(prefix); result = result.removeFirstSegments(rootPath.matchingFirstSegments(result)); } return result.setDevice(null); }
public IPath computePath(File source) { String prefix = filesMap.get(source); IPath result = null; if (prefix.startsWith(PROVIDED_PATH)) { // the desired path is provided in the map result = new Path(prefix.substring(10)); } else { //else the map contains a prefix which must be stripped from the path result = new Path(source.getAbsolutePath()); IPath rootPath = new Path(prefix); result = result.removeFirstSegments(rootPath.matchingFirstSegments(result)); } return result.setDevice(null); }
protected IFile getFileForMatchingPath(IPath containerPath, IPath sourcePath, IContainer container) { int matches = 0; matches = containerPath.matchingFirstSegments(sourcePath); if (matches > 0 && matches == sourcePath.segmentCount()) { IPath loadPath = containerPath.removeFirstSegments(matches); return primGetFile(container, loadPath); } return null; }
protected FileListener(AFileManager<T> fileManager) { this.fileManager = fileManager; IPath absolutePath2 = new org.eclipse.core.runtime.Path(fileManager.getAbsolutePath()); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IPath rootLocation = root.getLocation(); if (absolutePath2.matchingFirstSegments(rootLocation) != rootLocation.segmentCount()) { try { final IFile[] filesOfLocation = root.findFilesForLocationURI(URI.create("file:/" + absolutePath2.toString().replace(" ", "%20"))); absolutePath2 = filesOfLocation[0].getFullPath().makeRelativeTo(rootLocation); } catch (final IndexOutOfBoundsException e) { Logger.logError(e); eclipseFile = null; return; } } this.eclipseFile = absolutePath2.makeRelativeTo(rootLocation); }
/** * Returns a path which is equivalent to the given location relative to the * specified base path. */ public static IPath makeRelative(IPath base, IPath location) { if (location.getDevice() != null && !location.getDevice().equalsIgnoreCase(base.getDevice())) return location; int baseCount = base.segmentCount(); int count = base.matchingFirstSegments(location); String temp = ""; //$NON-NLS-1$ for (int j = 0; j < baseCount - count; j++) temp += "../"; //$NON-NLS-1$ return new Path(temp).append(location.removeFirstSegments(count)); }
private void addExtraLibrary(IPath path, IPluginModelBase model, ArrayList entries) throws CoreException { IPath srcPath = null; if (model != null) { IPath shortPath = path.removeFirstSegments(path.matchingFirstSegments(new Path(model.getInstallLocation()))); srcPath = ClasspathUtilCore.getSourceAnnotation(model, shortPath.toString()); } else { String filename = ClasspathUtilCore.getSourceZipName(path.lastSegment()); IPath candidate = path.removeLastSegments(1).append(filename); if (PDECore.getWorkspace().getRoot().getFile(candidate).exists()) srcPath = candidate; } IClasspathEntry clsEntry = JavaCore.newLibraryEntry( path, srcPath, null); if (!entries.contains(clsEntry)) entries.add(clsEntry); } }
private IPath getPath(Object entry) { IPath path = null; if (entry instanceof IClasspathEntry) { IClasspathEntry cpes = (IClasspathEntry) entry; path = cpes.getPath(); } else if (entry instanceof IPath) { path = (IPath) entry; } if (path != null && path.matchingFirstSegments(fProject.getFullPath()) > 0) { path = path.removeFirstSegments(1); } if (path != null) { return path.addTrailingSeparator(); } return null; }
private void addExtraLibrary(IPath path, IPluginModelBase model, ArrayList<IClasspathEntry> entries) { if (path.segmentCount() > 1) { IPath srcPath = null; if (model != null) { IPath shortPath = path.removeFirstSegments(path.matchingFirstSegments(new Path(model.getInstallLocation()))); srcPath = ClasspathUtilCore.getSourceAnnotation(model, shortPath.toString()); } else { String filename = ClasspathUtilCore.getSourceZipName(path.lastSegment()); IPath candidate = path.removeLastSegments(1).append(filename); if (PDECore.getWorkspace().getRoot().getFile(candidate).exists()) srcPath = candidate; } IClasspathEntry clsEntry = JavaCore.newLibraryEntry(path, srcPath, null); if (!entries.contains(clsEntry)) entries.add(clsEntry); } } }
private void updateClasspath(IPath newPath, IProgressMonitor monitor) throws JavaModelException { IClasspathEntry[] classpath= fProject.getRawClasspath(); IPath jreContainerPath= new Path(JavaRuntime.JRE_CONTAINER); for (int i= 0; i < classpath.length; i++) { IClasspathEntry curr= classpath[i]; if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER && curr.getPath().matchingFirstSegments(jreContainerPath) > 0) { classpath[i]= JavaCore.newContainerEntry(newPath, curr.getAccessRules(), curr.getExtraAttributes(), curr.isExported()); } } fProject.setRawClasspath(classpath, monitor); }
private boolean updateClasspath(IPath newPath, IProgressMonitor monitor) throws JavaModelException { boolean updated= false; IClasspathEntry[] classpath= fProject.getRawClasspath(); IPath jreContainerPath= new Path(JavaRuntime.JRE_CONTAINER); for (int i= 0; i < classpath.length; i++) { IClasspathEntry curr= classpath[i]; if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER && curr.getPath().matchingFirstSegments(jreContainerPath) > 0) { if (! newPath.equals(curr.getPath())) { updated= true; classpath[i]= JavaCore.newContainerEntry(newPath, curr.getAccessRules(), curr.getExtraAttributes(), curr.isExported()); } } } if (updated) { fProject.setRawClasspath(classpath, monitor); } return updated; }
public static boolean updateClasspath(IPath newPath, IJavaProject project, IProgressMonitor monitor) throws JavaModelException { boolean updated= false; IClasspathEntry[] classpath= project.getRawClasspath(); IPath jreContainerPath= new Path(JavaRuntime.JRE_CONTAINER); for (int i= 0; i < classpath.length; i++) { IClasspathEntry curr= classpath[i]; if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER && curr.getPath().matchingFirstSegments(jreContainerPath) > 0) { if (!newPath.equals(curr.getPath())) { updated= true; classpath[i]= JavaCore.newContainerEntry(newPath, curr.getAccessRules(), curr.getExtraAttributes(), curr.isExported()); } } } if (updated) { project.setRawClasspath(classpath, monitor); } return updated; } }