public int compare(File arg0, File arg1) { Path a = new Path(arg0.getAbsolutePath()); Path b = new Path(arg1.getAbsolutePath()); if (a.segmentCount() == b.segmentCount()) { if (arg0.isDirectory() && arg1.isFile()) return 1; else if (arg0.isDirectory() && arg1.isDirectory()) return 0; else if (arg0.isFile() && arg1.isDirectory()) return -1; else return 0; } return a.segmentCount() - b.segmentCount(); } });
public int compare(File arg0, File arg1) { Path a = new Path(arg0.getAbsolutePath()); Path b = new Path(arg1.getAbsolutePath()); if (a.segmentCount() == b.segmentCount()) { if (arg0.isDirectory() && arg1.isFile()) return 1; else if (arg0.isDirectory() && arg1.isDirectory()) return 0; else if (arg0.isFile() && arg1.isDirectory()) return -1; else return 0; } return a.segmentCount() - b.segmentCount(); } });
public int compare(File arg0, File arg1) { Path a = new Path(arg0.getAbsolutePath()); Path b = new Path(arg1.getAbsolutePath()); if (a.segmentCount() == b.segmentCount()) { if (arg0.isDirectory() && arg1.isFile()) return 1; else if (arg0.isDirectory() && arg1.isDirectory()) return 0; else if (arg0.isFile() && arg1.isDirectory()) return -1; else return 0; } return a.segmentCount() - b.segmentCount(); } });
public void save(String filename, Map<String, String> map, HashSet<?> selected) { Properties properties = getTracingOptions(map); for (Enumeration<?> keys = properties.keys(); keys.hasMoreElements();) { String key = keys.nextElement().toString(); Path path = new Path(key); if (path.segmentCount() < 1 || !selected.contains(path.segment(0).toString())) { properties.remove(key); } } save(filename, properties); }
public void save(String filename, Map map, HashSet selected) { Properties properties = getTracingOptions(map); for (Enumeration keys = properties.keys(); keys.hasMoreElements();) { String key = keys.nextElement().toString(); Path path = new Path(key); if (path.segmentCount() < 1 || !selected.contains(path.segment(0).toString())) { properties.remove(key); } } save(filename, properties); }
/** * * @return org.eclipse.core.resources.IFile * @param location * java.lang.String */ public static IFile location2File(String location) { Path path = new Path(location); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); if (file == null && path.segmentCount() > 1) file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); return file; }
public boolean isValidPath(String path) { Path test = new Path(path); for (int i = 0, max = test.segmentCount(); i < max; i++) if (!isValidSegment(test.segment(i))) return false; return true; }
public boolean isValidPath(String path) { Path test = new Path(path); for (int i = 0, max = test.segmentCount(); i < max; i++) if (!isValidSegment(test.segment(i))) return false; return true; }
private Object[] findResource(String name, IProject project) { Path path = new Path(name); for (int i = path.segmentCount() - 1; i >= 0; i--) { IResource resource = project.findMember(path.removeFirstSegments(i)); if (resource != null) { return new Object[] {resource}; } } return EMPTY; }
public IPath makeAbsolute() { if (isAbsolute()) { return this; } Path result = new Path(device, segments, separators | HAS_LEADING); //may need canonicalizing if it has leading ".." or "." segments if (result.segmentCount() > 0) { String first = result.segment(0); if (first.equals("..") || first.equals(".")) { //$NON-NLS-1$ //$NON-NLS-2$ result.canonicalize(); } } return result; }
@Override public IPath makeAbsolute() { if (isAbsolute()) { return this; } Path result = new Path(device, segments, flags | HAS_LEADING); //may need canonicalizing if it has leading ".." or "." segments if (result.segmentCount() > 0) { String first = result.segment(0); if (first.equals("..") || first.equals(".")) { //$NON-NLS-1$ //$NON-NLS-2$ result.canonicalize(); } } return result; }
@Override public IPath makeAbsolute() { if (isAbsolute()) { return this; } Path result = new Path(device, segments, flags | HAS_LEADING); //may need canonicalizing if it has leading ".." or "." segments if (result.segmentCount() > 0) { String first = result.segment(0); if (first.equals("..") || first.equals(".")) { //$NON-NLS-1$ //$NON-NLS-2$ result.canonicalize(); } } return result; }
public IPath makeAbsolute() { if (isAbsolute()) { return this; } Path result = new Path(device, segments, separators | HAS_LEADING); //may need canonicalizing if it has leading ".." or "." segments if (result.segmentCount() > 0) { String first = result.segment(0); if (first.equals("..") || first.equals(".")) { //$NON-NLS-1$ //$NON-NLS-2$ result.canonicalize(); } } return result; }
/** * {@inheritDoc} * @since org.eclipse.equinox.common 3.5 */ public IPath makeRelativeTo(IPath base) { //can't make relative if devices are not equal if (device != base.getDevice() && (device == null || !device.equalsIgnoreCase(base.getDevice()))) return this; int commonLength = matchingFirstSegments(base); final int differenceLength = base.segmentCount() - commonLength; final int newSegmentLength = differenceLength + segmentCount() - commonLength; if (newSegmentLength == 0) return Path.EMPTY; String[] newSegments = new String[newSegmentLength]; //add parent references for each segment different from the base Arrays.fill(newSegments, 0, differenceLength, ".."); //$NON-NLS-1$ //append the segments of this path not in common with the base System.arraycopy(segments, commonLength, newSegments, differenceLength, newSegmentLength - differenceLength); return new Path(null, newSegments, separators & HAS_TRAILING); }
/** * {@inheritDoc} * @since org.eclipse.equinox.common 3.5 */ public IPath makeRelativeTo(IPath base) { //can't make relative if devices are not equal if (device != base.getDevice() && (device == null || !device.equalsIgnoreCase(base.getDevice()))) return this; int commonLength = matchingFirstSegments(base); final int differenceLength = base.segmentCount() - commonLength; final int newSegmentLength = differenceLength + segmentCount() - commonLength; if (newSegmentLength == 0) return Path.EMPTY; String[] newSegments = new String[newSegmentLength]; //add parent references for each segment different from the base Arrays.fill(newSegments, 0, differenceLength, ".."); //$NON-NLS-1$ //append the segments of this path not in common with the base System.arraycopy(segments, commonLength, newSegments, differenceLength, newSegmentLength - differenceLength); return new Path(null, newSegments, separators & HAS_TRAILING); }
/** * {@inheritDoc} * @since org.eclipse.equinox.common 3.5 */ @Override public IPath makeRelativeTo(IPath base) { //can't make relative if devices are not equal if (device != base.getDevice() && (device == null || !device.equalsIgnoreCase(base.getDevice()))) return this; int commonLength = matchingFirstSegments(base); final int differenceLength = base.segmentCount() - commonLength; final int newSegmentLength = differenceLength + segmentCount() - commonLength; if (newSegmentLength == 0) return Path.EMPTY; String[] newSegments = new String[newSegmentLength]; //add parent references for each segment different from the base Arrays.fill(newSegments, 0, differenceLength, ".."); //$NON-NLS-1$ //append the segments of this path not in common with the base System.arraycopy(segments, commonLength, newSegments, differenceLength, newSegmentLength - differenceLength); return new Path(null, newSegments, flags & (HAS_TRAILING | IS_FOR_WINDOWS)); }
MElementContainer<MMenuElement> findMenuFromPath(MElementContainer<MMenuElement> menu, Path menuPath, int segment) { int idx = ContributionsAnalyzer.indexForId(menu, menuPath.segment(segment)); if (idx == -1) { if (segment + 1 < menuPath.segmentCount() || !menuPath.hasTrailingSeparator()) { return null; } return menu; } MElementContainer<MMenuElement> item = (MElementContainer<MMenuElement>) menu.getChildren() .get(idx); if (item.getChildren().isEmpty()) { if (segment + 1 == menuPath.segmentCount()) { return menu; } return null; } return findMenuFromPath(item, menuPath, segment + 1); } }
private IResource getResource(IWorkspaceRoot root, String next) { IResource resource = root.findMember(next); if (resource == null) { // May be an outgoing deletion Path path = new Path(null, next); if (next.charAt(next.length()-1) == IPath.SEPARATOR) { if (path.segmentCount() == 1) { // resource is a project resource = root.getProject(path.lastSegment()); } else { // resource is a folder resource = root.getFolder(path); } } else { // resource is a file resource = root.getFile(path); } } return resource; }
private IResource findMostSpecific(String sourceFile) throws CoreException { IResource resolved = null; int shortestPath = Integer.MAX_VALUE; for (ISourceContainer container : sourceContainer.getSourceContainers()) { Object[] paths = container.findSourceElements(sourceFile); for (Object path : paths) { if (path instanceof IFile) { IFile file = (IFile) path; IPath p = file.getFullPath(); if (p instanceof Path) { int count = ((Path) p).segmentCount(); if (count < shortestPath) { shortestPath = count; resolved = file; } } } } } return resolved; }
private IStatus copy(String src, IFileStore destinationParent, IFileSystem fileSystem, IProgressMonitor monitor) throws CoreException { Path srcPath = new Path(src); IFileStore source = fileSystem.getStore(srcPath); String elementName = srcPath.segment(srcPath.segmentCount() - 1); IFileStore destination = destinationParent.getChild(elementName); SubMonitor subMonitor = SubMonitor.convert(monitor, 1); if (destination.fetchInfo().exists()) { return Status.OK_STATUS; } if (source.fetchInfo().isDirectory()) { destination.mkdir(EFS.NONE, new NullProgressMonitor()); } source.copy(destination, EFS.OVERWRITE, subMonitor.split(1)); return Status.OK_STATUS; }