org.eclipse.core.runtime.Path.segmentCount()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中org.eclipse.core.runtime.Path.segmentCount()方法的一些代码示例,展示了Path.segmentCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.segmentCount()方法的具体详情如下:
包路径:org.eclipse.core.runtime.Path
类名称:Path
方法名:segmentCount

Path.segmentCount介绍

暂无

代码示例

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.equinox.p2.core

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();
  }
});

代码示例来源:origin: org.eclipse.equinox.p2/core

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();
  }
});

代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.equinox.p2.core

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();
  }
});

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.pde.core

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);
}

代码示例来源:origin: org.eclipse/org.eclipse.pde.core

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);
}

代码示例来源:origin: org.eclipse/org.eclipse.wst.css.core

/**
 * 
 * @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;
}

代码示例来源:origin: org.eclipse.equinox/common

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;
}

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.equinox.common

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;
}

代码示例来源:origin: sdbg/sdbg

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;
}

代码示例来源:origin: org.eclipse.equinox/common

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;
}

代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.equinox.common

@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;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.equinox.common

@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;
}

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.equinox.common

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;
}

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.equinox.common

/**
 * {@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);
}

代码示例来源:origin: org.eclipse.equinox/common

/**
 * {@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);
}

代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.equinox.common

/**
 * {@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));
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench

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);
  }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.team.core

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;
}

代码示例来源:origin: infinitest/infinitest

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;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.pde.core

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;
}

相关文章