当前位置: 首页>>代码示例>>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;未经允许,请勿转载。