Java Code Examples for com.intellij.openapi.util.io.FileUtil#startsWith()

The following examples show how to use com.intellij.openapi.util.io.FileUtil#startsWith() . 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: HaxelibUtil.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
/**
 * Get the relative path from the SDK's library path to the given path.
 * Trim the library path out of the beginning of path.
 * @return The relative path, or null if the path isn't a library path.
 */
@Nullable
public static String getLibraryRelativeDirectory(@NotNull Sdk sdk, String path) {
  if (null == path || path.isEmpty()) {
    return null;
  }

  VirtualFile haxelibRoot = getLibraryBasePath(sdk);
  String rootName = haxelibRoot.getPath();

  String s = FileUtil.toSystemIndependentName(path);
  if (FileUtil.startsWith(s, rootName)) {
    return FileUtil.getRelativePath(rootName, s, HaxeFileUtil.SEPARATOR);
  }
  return null;
}
 
Example 2
Source File: FileSetCompileScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean belongs(String url) {
  //url = CompilerUtil.normalizePath(url, '/');
  if (getUrls().contains(url)) {
    return true;
  }
  for (String directoryUrl : myDirectoryUrls) {
    if (FileUtil.startsWith(url, directoryUrl)) {
      return true;
    }
  }
  return false;
}
 
Example 3
Source File: NewMappings.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean fileMatchesMapping(@Nonnull VirtualFile file,
                                   final Object matchContext,
                                   final String systemIndependentPath,
                                   final VcsDirectoryMapping mapping) {
  if (mapping.getDirectory().length() == 0) {
    return myDefaultVcsRootPolicy.matchesDefaultMapping(file, matchContext);
  }
  return FileUtil.startsWith(systemIndependentPath, mapping.systemIndependentPath());
}
 
Example 4
Source File: FoldersCutDownWorker.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean addCurrent(final VirtualFile file) {
  for (String path : myPaths) {
    if (FileUtil.startsWith(file.getPath(), path)) {
      return false;
    }
  }

  myPaths.add(file.getPath());
  return true;
}
 
Example 5
Source File: ImportFromWorkspaceProjectViewOption.java    From intellij with Apache License 2.0 4 votes vote down vote up
private void chooseWorkspacePath() {
  FileChooserDescriptor descriptor =
      new FileChooserDescriptor(true, false, false, false, false, false)
          .withShowHiddenFiles(true) // Show root project view file
          .withHideIgnored(false)
          .withTitle("Select Project View File")
          .withDescription("Select a project view file to import.")
          .withFileFilter(
              virtualFile ->
                  ProjectViewStorageManager.isProjectViewFile(new File(virtualFile.getPath())));
  // File filters are broken for the native Mac file chooser.
  descriptor.setForcedToUseIdeaFileChooser(true);
  FileChooserDialog chooser =
      FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);

  WorkspacePathResolver workspacePathResolver =
      builder.getWorkspaceData().workspacePathResolver();
  File fileBrowserRoot = builder.getWorkspaceData().fileBrowserRoot();
  File startingLocation = fileBrowserRoot;
  String projectViewPath = getProjectViewPath();
  if (!projectViewPath.isEmpty()) {
    // If the user has typed part of the path then clicked the '...', try to start from the
    // partial state
    projectViewPath = StringUtil.trimEnd(projectViewPath, '/');
    if (WorkspacePath.isValid(projectViewPath)) {
      File fileLocation = workspacePathResolver.resolveToFile(new WorkspacePath(projectViewPath));
      if (fileLocation.exists() && FileUtil.isAncestor(fileBrowserRoot, fileLocation, true)) {
        startingLocation = fileLocation;
      }
    }
  }
  VirtualFile toSelect =
      LocalFileSystem.getInstance().refreshAndFindFileByPath(startingLocation.getPath());
  VirtualFile[] files = chooser.choose(null, toSelect);
  if (files.length == 0) {
    return;
  }
  VirtualFile file = files[0];

  if (!FileUtil.startsWith(file.getPath(), fileBrowserRoot.getPath())) {
    Messages.showErrorDialog(
        String.format(
            "You must choose a project view file under %s. "
                + "To use an external project view, please use the 'Copy external' option.",
            fileBrowserRoot.getPath()),
        "Cannot Use Project View File");
    return;
  }

  String newWorkspacePath = FileUtil.getRelativePath(fileBrowserRoot, new File(file.getPath()));
  projectViewPathField.setText(newWorkspacePath);
}
 
Example 6
Source File: ModuleRootCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isUrlUnderRoot(final String url, final String root) {
  return (url.length() > root.length()) && url.charAt(root.length()) == '/' && FileUtil.startsWith(url, root);
}
 
Example 7
Source File: ModuleCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isUrlUnderRoot(final String url, final String root) {
  return (url.length() > root.length()) && url.charAt(root.length()) == '/' && FileUtil.startsWith(url, root);
}
 
Example 8
Source File: OneProjectItemCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean belongs(String url) {
  if (myFile.isDirectory()){
    return FileUtil.startsWith(url, myUrl);
  }
  return FileUtil.pathsEqual(url, myUrl);
}
 
Example 9
Source File: CanonicalPathMap.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isApproxParent(@Nonnull String path, @Nonnull String parent) {
  return path.lastIndexOf(File.separatorChar) == parent.length() && FileUtil.startsWith(path, parent);
}
 
Example 10
Source File: FileTemplatesLoader.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean matchesPrefix(String path, String prefix) {
  if (prefix.length() == 0) {
    return !path.contains("/");
  }
  return FileUtil.startsWith(path, prefix) && !path.substring(prefix.length()).contains("/");
}