@Nullable
  public static PsiDirectory selectDirectory(
      Project project,
      PsiDirectory[] packageDirectories,
      PsiDirectory defaultDirectory,
      String postfixToShow) {
    ProjectFileIndex projectFileIndex = getInstance(project).getFileIndex();

    ArrayList<PsiDirectory> possibleDirs = new ArrayList<>();
    for (PsiDirectory dir : packageDirectories) {
      if (!dir.isValid()) continue;
      if (!dir.isWritable()) continue;
      if (possibleDirs.contains(dir)) continue;
      if (!projectFileIndex.isInContent(dir.getVirtualFile())) continue;
      possibleDirs.add(dir);
    }

    if (possibleDirs.isEmpty()) return null;
    if (possibleDirs.size() == 1) return possibleDirs.get(0);

    if (getApplication().isUnitTestMode()) return possibleDirs.get(0);

    DirectoryChooser chooser = new DirectoryChooser(project);
    chooser.setTitle(message("title.choose.destination.directory"));
    chooser.fillList(
        possibleDirs.toArray(new PsiDirectory[possibleDirs.size()]),
        defaultDirectory,
        project,
        postfixToShow);
    return chooser.showAndGet() ? chooser.getSelectedDirectory() : null;
  }
예제 #2
0
 private static boolean isWritablePackage(PsiPackage aPackage) {
   PsiDirectory[] directories = aPackage.getDirectories();
   for (PsiDirectory directory : directories) {
     if (directory.isValid() && directory.isWritable()) {
       return true;
     }
   }
   return false;
 }
예제 #3
0
 private static PsiDirectory getWritableModuleDirectory(
     @NotNull Query<VirtualFile> vFiles, @NotNull Module module, PsiManager manager) {
   for (VirtualFile vFile : vFiles) {
     if (ModuleUtil.findModuleForFile(vFile, module.getProject()) != module) continue;
     PsiDirectory directory = manager.findDirectory(vFile);
     if (directory != null && directory.isValid() && directory.isWritable()) {
       return directory;
     }
   }
   return null;
 }
  @NotNull
  @Override
  public PsiClass[] getClasses(@NotNull PsiDirectory dir) {
    LOG.assertTrue(dir.isValid());

    boolean onlyCompiled =
        FileIndexFacade.getInstance(dir.getProject()).isInLibraryClasses(dir.getVirtualFile());

    List<PsiClass> classes = null;
    for (PsiFile file : dir.getFiles()) {
      if (onlyCompiled && !(file instanceof ClsFileImpl)) {
        continue;
      }
      if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
        PsiClass[] psiClasses = ((PsiClassOwner) file).getClasses();
        if (psiClasses.length == 0) continue;
        if (classes == null) classes = new ArrayList<PsiClass>();
        ContainerUtil.addAll(classes, psiClasses);
      }
    }
    return classes == null ? PsiClass.EMPTY_ARRAY : classes.toArray(new PsiClass[classes.size()]);
  }