當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtil.isAncestor方法代碼示例

本文整理匯總了Java中com.intellij.openapi.util.io.FileUtil.isAncestor方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.isAncestor方法的具體用法?Java FileUtil.isAncestor怎麽用?Java FileUtil.isAncestor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.openapi.util.io.FileUtil的用法示例。


在下文中一共展示了FileUtil.isAncestor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: defaultExportDirectory

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
/** Try to find a checked-in project view file. Otherwise, fall back to the workspace root. */
@Nullable
private static File defaultExportDirectory(Project project) {
  WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProjectSafe(project);
  if (workspaceRoot == null) {
    return null;
  }
  ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
  if (projectViewSet != null) {
    for (ProjectViewFile projectViewFile : projectViewSet.getProjectViewFiles()) {
      File file = projectViewFile.projectViewFile;
      if (file != null && FileUtil.isAncestor(workspaceRoot.directory(), file, false)) {
        return file.getParentFile();
      }
    }
  }
  return workspaceRoot.directory();
}
 
開發者ID:bazelbuild,項目名稱:intellij,代碼行數:19,代碼來源:ExportRunConfigurationDialog.java

示例2: removeIncompatibleRoots

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static void removeIncompatibleRoots(DetectedProjectRoot root, Map<File, DetectedRootData> rootData) {
  DetectedRootData[] allRoots = rootData.values().toArray(new DetectedRootData[rootData.values().size()]);
  for (DetectedRootData child : allRoots) {
    final File childDirectory = child.getDirectory();
    if (FileUtil.isAncestor(root.getDirectory(), childDirectory, true)) {
      for (DetectedProjectRoot projectRoot : child.getAllRoots()) {
        if (!root.canContainRoot(projectRoot)) {
          child.removeRoot(projectRoot);
        }
      }
      if (child.isEmpty()) {
        rootData.remove(childDirectory);
      }
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:RootDetectionProcessor.java

示例3: getPackageFromDirectory

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
/**
 * Calculate the package name from the given target directory. Returns the package name or null if no package name could
 * be calculated.
 */
@Nullable
public static String getPackageFromDirectory(@NotNull VirtualFile directory,
                                             @NotNull SourceProvider sourceProvider,
                                             @NotNull Module module, @NotNull String srcDir) {
  File javaSourceRoot;
  File javaDir = findSrcDirectory(sourceProvider);
  if (javaDir == null) {
    javaSourceRoot = new File(AndroidRootUtil.getModuleDirPath(module), srcDir);
  }
  else {
    javaSourceRoot = new File(javaDir.getPath());
  }

  File javaSourcePackageRoot = VfsUtilCore.virtualToIoFile(directory);
  if (!FileUtil.isAncestor(javaSourceRoot, javaSourcePackageRoot, true)) {
    return null;
  }

  String relativePath = FileUtil.getRelativePath(javaSourceRoot, javaSourcePackageRoot);
  String packageName = relativePath != null ? FileUtil.toSystemIndependentName(relativePath).replace('/', '.') : null;
  if (packageName == null || !AndroidUtils.isValidJavaPackageName(packageName)) {
    return null;
  }
  return packageName;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:30,代碼來源:AddAndroidActivityPath.java

示例4: detectRoots

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@NotNull
@Override
public DirectoryProcessingResult detectRoots(@NotNull File dir,
                                             @NotNull File[] children,
                                             @NotNull File base,
                                             @NotNull List<DetectedProjectRoot> result) {
  detectApplicationRoot(dir, result);

  for (DetectedProjectRoot projectRoot : result) {
    if ((projectRoot instanceof CloudGitProjectRoot) && FileUtil.isAncestor(projectRoot.getDirectory(), dir, true)) {
      return detectJavaRoots(((CloudGitProjectRoot)projectRoot).getJavaSourceRootTypeName(), dir, children, base, result);
    }
  }

  return DirectoryProcessingResult.PROCESS_CHILDREN;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:CloudGitProjectStructureDetector.java

示例5: removeCoverageSuite

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public void removeCoverageSuite(final CoverageSuite suite) {
  final String fileName = suite.getCoverageDataFileName();

  boolean deleteTraces = suite.isTracingEnabled();
  if (!FileUtil.isAncestor(PathManager.getSystemPath(), fileName, false)) {
    String message = "Would you like to delete file \'" + fileName + "\' ";
    if (deleteTraces) {
      message += "and traces directory \'" + FileUtil.getNameWithoutExtension(new File(fileName)) + "\' ";
    }
    message += "on disk?";
    if (Messages.showYesNoDialog(myProject, message, CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == Messages.YES) {
      deleteCachedCoverage(fileName, deleteTraces);
    }
  } else {
    deleteCachedCoverage(fileName, deleteTraces);
  }

  myCoverageSuites.remove(suite);
  if (myCurrentSuitesBundle != null && myCurrentSuitesBundle.contains(suite)) {
    CoverageSuite[] suites = myCurrentSuitesBundle.getSuites();
    suites = ArrayUtil.remove(suites, suite);
    chooseSuitesBundle(suites.length > 0 ? new CoverageSuitesBundle(suites) : null);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:25,代碼來源:CoverageDataManagerImpl.java

示例6: fileDeleted

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Override
public void fileDeleted(@NotNull VirtualFileEvent event) {
  VirtualFile removedFile = event.getFile();
  String path = removedFile.getPath();
  if (path.contains(CCUtils.GENERATED_FILES_FOLDER)) {
    return;
  }

  if (myProject == null) {
    return;
  }
  if (myProject.getBasePath() !=null && !FileUtil.isAncestor(myProject.getBasePath(), removedFile.getPath(), true)) {
    return;
  }
  Course course = StudyTaskManager.getInstance(myProject).getCourse();
  if (course == null) {
    return;
  }
  final TaskFile taskFile = StudyUtils.getTaskFile(myProject, removedFile);
  if (taskFile != null) {
    deleteTaskFile(removedFile, taskFile);
    return;
  }
  if (removedFile.getName().contains(EduNames.TASK)) {
    deleteTask(course, removedFile);
  }
  if (removedFile.getName().contains(EduNames.LESSON)) {
    deleteLesson(course, removedFile, myProject);
  }
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:31,代碼來源:CCVirtualFileListener.java

示例7: isInContent

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static boolean isInContent(@NotNull ContentEntry[] contentEntries, @NotNull PhpNamespaceRootInfo info) {
    for (ContentEntry entry : contentEntries) {
        VirtualFile file = entry.getFile();

        if (file != null &&
            FileUtil.isAncestor(file.getPath(), info.getSourcePath(), false) &&
            !existsSource(entry.getSourceFolders(), info)
        ) {
            return true;
        }
    }

    return false;
}
 
開發者ID:aurimasniekis,項目名稱:idea-php-psr4-namespace-detector,代碼行數:15,代碼來源:PhpPsr4NamespaceRootDetector.java

示例8: computeRootExcludes

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@NotNull
protected Set<File> computeRootExcludes(File root, ModuleExcludeIndex index) {
  final Collection<File> moduleExcludes = index.getModuleExcludes(getModule());
  if (moduleExcludes.isEmpty()) {
    return Collections.emptySet();
  }
  final Set<File> excludes = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY);
  for (File excluded : moduleExcludes) {
    if (FileUtil.isAncestor(root, excluded, true)) {
      excludes.add(excluded);
    }
  }
  return excludes;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:15,代碼來源:JVMModuleBuildTarget.java

示例9: backupFiles

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public static void backupFiles(Collection<File> files, File parentDir, File backupDir) throws IOException {
  backupDir.mkdirs();
  for (File file : files) {
    final File target;
    if (FileUtil.isAncestor(parentDir, file, true)) {
      final String relativePath = FileUtil.getRelativePath(parentDir, file);
      target = new File(backupDir.getAbsolutePath() + File.separator + relativePath);
      FileUtil.createParentDirs(target);
    }
    else {
      target = new File(backupDir, file.getName());
    }
    FileUtil.copy(file, target);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:ProjectConversionUtil.java

示例10: isNested

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public static boolean isNested(final Collection<FilePath> roots, final File root) {
  for (FilePath filePath : roots) {
    final File ioFile = filePath.getIOFile();

    if (FileUtil.isAncestor(ioFile, root, true)) {
      return true;
    }
  }
  return false;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:FilePathUtil.java

示例11: findBuildFileForFile

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Nullable
public File findBuildFileForFile(File file) {
  if (fileOperationProvider.isFile(file)) {
    file = file.getParentFile();
    if (file == null) {
      return null;
    }
  }

  final File directory = file;
  File root =
      importRoots
          .rootDirectories()
          .stream()
          .map(workspaceRoot::fileForPath)
          .filter(potentialRoot -> FileUtil.isAncestor(potentialRoot, directory, false))
          .findFirst()
          .orElse(null);
  if (root == null) {
    return null;
  }

  File currentDirectory = directory;
  do {
    File buildFile = buildSystemProvider.findBuildFileInDirectory(currentDirectory);
    if (buildFile != null) {
      return buildFile;
    }
    currentDirectory = currentDirectory.getParentFile();
  } while (currentDirectory != null && FileUtil.isAncestor(root, currentDirectory, false));

  return null;
}
 
開發者ID:bazelbuild,項目名稱:intellij,代碼行數:34,代碼來源:BuildTargetFinder.java

示例12: customizeCellRenderer

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Override
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
  if (value instanceof MapInfo) {
    MapInfo info = (MapInfo)value;

    if (!selected && (info == MapInfo.SEPARATOR || info.type == MapInfo.Type.UNREGISTERED)) {
      setBackground(getUnregisteredRootBackground());
    }

    if (info == MapInfo.SEPARATOR) {
      append("Unregistered roots:", getAttributes(info));
      return;
    }

    if (info.mapping.isDefaultMapping()) {
      append(VcsDirectoryMapping.PROJECT_CONSTANT, getAttributes(info));
      return;
    }

    String directory = info.mapping.getDirectory();
    VirtualFile baseDir = myProject.getBaseDir();
    if (baseDir != null) {
      final File directoryFile = new File(StringUtil.trimEnd(UriUtil.trimTrailingSlashes(directory), "\\") + "/");
      File ioBase = new File(baseDir.getPath());
      if (directoryFile.isAbsolute() && !FileUtil.isAncestor(ioBase, directoryFile, false)) {
        append(new File(directory).getPath(), getAttributes(info));
        return;
      }
      String relativePath = FileUtil.getRelativePath(ioBase, directoryFile);
      if (".".equals(relativePath) || relativePath == null) {
        append(ioBase.getPath(), getAttributes(info));
      }
      else {
        append(relativePath, getAttributes(info));
        append(" (" + ioBase + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
      }
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:40,代碼來源:VcsDirectoryConfigurationPanel.java

示例13: checkProjectRoots

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private void checkProjectRoots() {
  LocalFileSystem fs = LocalFileSystem.getInstance();
  if (!(fs instanceof LocalFileSystemImpl)) return;
  FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher();
  if (!watcher.isOperational()) return;
  List<String> manualWatchRoots = watcher.getManualWatchRoots();
  if (manualWatchRoots.isEmpty()) return;
  VirtualFile[] roots = ProjectRootManager.getInstance(myProject).getContentRoots();
  if (roots.length == 0) return;

  List<String> nonWatched = new SmartList<String>();
  for (VirtualFile root : roots) {
    if (!(root.getFileSystem() instanceof LocalFileSystem)) continue;
    String rootPath = root.getPath();
    for (String manualWatchRoot : manualWatchRoots) {
      if (FileUtil.isAncestor(manualWatchRoot, rootPath, false)) {
        nonWatched.add(rootPath);
      }
    }
  }

  if (!nonWatched.isEmpty()) {
    String message = ApplicationBundle.message("watcher.non.watchable.project");
    watcher.notifyOnFailure(message, null);
    LOG.info("unwatched roots: " + nonWatched);
    LOG.info("manual watches: " + manualWatchRoots);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:29,代碼來源:StartupManagerImpl.java

示例14: fileCreated

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
  VirtualFile createdFile = event.getFile();
  if (createdFile.isDirectory()) {
    return;
  }
  if (createdFile.getPath().contains(CCUtils.GENERATED_FILES_FOLDER)) {
    return;
  }
  if (myProject.getBasePath() !=null && !FileUtil.isAncestor(myProject.getBasePath(), createdFile.getPath(), true)) {
    return;
  }
  Course course = StudyTaskManager.getInstance(myProject).getCourse();
  if (course == null) {
    return;
  }
  TaskFile taskFile = StudyUtils.getTaskFile(myProject, createdFile);
  if (taskFile != null) {
    return;
  }

  String taskRelativePath = StudyUtils.pathRelativeToTask(createdFile);

  EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(course.getLanguageById());
  if (configurator != null && configurator.excludeFromArchive(createdFile.getPath())) {
    return;
  }

  if (CCUtils.isTestsFile(myProject, createdFile)
      || taskRelativePath.contains(EduNames.WINDOW_POSTFIX)
      || taskRelativePath.contains(EduNames.WINDOWS_POSTFIX)
      || taskRelativePath.contains(EduNames.ANSWERS_POSTFIX)) {
    return;
  }
  VirtualFile taskVF = StudyUtils.getTaskDir(createdFile);
  if (taskVF == null) {
    return;
  }
  Task task = StudyUtils.getTask(myProject, taskVF);
  if (task == null) {
    return;
  }

  task.addTaskFile(taskRelativePath, task.getTaskFiles().size()+1);
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:46,代碼來源:CCVirtualFileListener.java

示例15: cleanup

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Override
public void cleanup(@NotNull File result) {
  if (result.isFile() && FileUtil.isAncestor(result, myContext.getTempDirectory(), false)) {
    FileUtil.delete(result);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:7,代碼來源:DownloadOperation.java


注:本文中的com.intellij.openapi.util.io.FileUtil.isAncestor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。