public DirectoryNode(
      VirtualFile aDirectory,
      Project project,
      boolean compactPackages,
      boolean showFQName,
      VirtualFile baseDir,
      final VirtualFile[] contentRoots) {
    super(project);
    myVDirectory = aDirectory;
    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
    final ProjectFileIndex index = projectRootManager.getFileIndex();
    String dirName = aDirectory.getName();
    if (showFQName) {
      final VirtualFile contentRoot = index.getContentRootForFile(myVDirectory);
      if (contentRoot != null) {
        if (Comparing.equal(myVDirectory, contentRoot)) {
          myFQName = dirName;
        } else {
          final VirtualFile sourceRoot = index.getSourceRootForFile(myVDirectory);
          if (Comparing.equal(myVDirectory, sourceRoot)) {
            myFQName = VfsUtilCore.getRelativePath(myVDirectory, contentRoot, '/');
          } else if (sourceRoot != null) {
            myFQName = VfsUtilCore.getRelativePath(myVDirectory, sourceRoot, '/');
          } else {
            myFQName = VfsUtilCore.getRelativePath(myVDirectory, contentRoot, '/');
          }
        }

        if (contentRoots.length > 1
            && ProjectRootsUtil.isModuleContentRoot(myVDirectory, project)) {
          myFQName = getContentRootName(baseDir, myFQName);
        }
      } else {
        myFQName = FilePatternPackageSet.getLibRelativePath(myVDirectory, index);
      }
      dirName = myFQName;
    } else {
      if (contentRoots.length > 1 && ProjectRootsUtil.isModuleContentRoot(myVDirectory, project)) {
        dirName = getContentRootName(baseDir, dirName);
      }
    }
    myDirName = dirName;
    myCompactPackages = compactPackages;
  }
예제 #2
0
 private boolean isNavigatableLibraryRoot() {
   VirtualFile jarRoot = getJarRoot();
   final Project project = getProject();
   if (jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
     final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
     return orderEntry != null
         && ProjectSettingsService.getInstance(project).canOpenLibraryOrSdkSettings(orderEntry);
   }
   return false;
 }
 @Nullable
 private static Map<PsiFile, PsiClass[]> convertToTopLevelClasses(
     final PsiElement[] elements,
     final boolean fromUpdate,
     String relativePath,
     Map<PsiFile, String> relativeMap) {
   final Map<PsiFile, PsiClass[]> result = new HashMap<PsiFile, PsiClass[]>();
   for (PsiElement element : elements) {
     final PsiElement navigationElement = element.getNavigationElement();
     LOG.assertTrue(navigationElement != null, element);
     final PsiFile containingFile = navigationElement.getContainingFile();
     if (!(containingFile instanceof PsiClassOwner
         && ProjectRootsUtil.isOutsideSourceRoot(containingFile))) {
       PsiClass[] topLevelClasses = getTopLevelClasses(element);
       if (topLevelClasses == null) {
         if (element instanceof PsiDirectory) {
           if (!fromUpdate) {
             final String name = ((PsiDirectory) element).getName();
             final String path =
                 relativePath != null
                     ? (relativePath.length() > 0 ? (relativePath + "/") : "") + name
                     : null;
             final Map<PsiFile, PsiClass[]> map =
                 convertToTopLevelClasses(element.getChildren(), fromUpdate, path, relativeMap);
             if (map == null) return null;
             for (Map.Entry<PsiFile, PsiClass[]> entry : map.entrySet()) {
               fillResultsMap(result, entry.getKey(), entry.getValue());
             }
           }
           continue;
         }
         if (!(element instanceof PsiFileSystemItem)) return null;
       }
       fillResultsMap(result, containingFile, topLevelClasses);
       if (relativeMap != null) {
         relativeMap.put(containingFile, relativePath);
       }
     }
   }
   if (result.isEmpty()) {
     return null;
   } else {
     boolean hasClasses = false;
     for (PsiClass[] classes : result.values()) {
       if (classes != null) {
         hasClasses = true;
         break;
       }
     }
     return hasClasses ? result : null;
   }
 }
예제 #4
0
  @Override
  public void navigate(boolean requestFocus) {
    final VirtualFile jarRoot = getJarRoot();
    final Project project = getProject();
    if (requestFocus && jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
      final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
      if (orderEntry != null) {
        ProjectSettingsService.getInstance(project).openLibraryOrSdkSettings(orderEntry);
        return;
      }
    }

    super.navigate(requestFocus);
  }