analyze dependencies: display lib root name (IDEA-203484)
authorAnna.Kozlova <anna.kozlova@jetbrains.com>
Mon, 3 Dec 2018 14:19:11 +0000 (15:19 +0100)
committerAnna.Kozlova <anna.kozlova@jetbrains.com>
Mon, 3 Dec 2018 14:21:12 +0000 (15:21 +0100)
java/java-tests/testData/dependencies/dependencies/src/com/package1/Class2.java
java/java-tests/testSrc/com/intellij/java/dependencies/DependenciesPanelTest.java
platform/analysis-api/src/com/intellij/psi/search/scope/packageSet/FilePatternPackageSet.java
platform/lang-impl/src/com/intellij/packageDependencies/ui/DirectoryNode.java

index 58f58a44dfac84df9e89b61dbf7a64d9ffeb8bca..03a3c251236e301a44b498aaee553060e299d1b9 100644 (file)
@@ -1,4 +1,5 @@
 package com.package1;
 
 public class Class2 {
+  String s;
 }
\ No newline at end of file
index 325de79c9df67becb95b6745450b10549ce9c84e..c96e62e5123307564027ebec8b002026f9f3fef5 100644 (file)
@@ -77,7 +77,11 @@ public class DependenciesPanelTest extends TestSourceBasedTestCase {
                                                          "    -dependencies\n" +
                                                          "     -src\n" +
                                                          "      com/package1\n",
-                            "Root\n");
+                            "-Root\n" +
+                            " -External Dependencies\n" +
+                            "  -src.zip\n" +
+                            "   -java/lang\n" +
+                            "    String.java");
   }
 
   private void doTestDependenciesTrees(AnalysisScope scope, String expectedLeftTree, String expectedRightTree) {
index 04fa91eee2b62ec904241a4b1b7f4d10214bf424..5b2c46ca8c838e739812cf804be65ee258607e9b 100644 (file)
@@ -26,10 +26,14 @@ import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.ArrayUtil;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.regex.Pattern;
 
 public class FilePatternPackageSet extends PatternBasedPackageSet {
@@ -196,13 +200,14 @@ public class FilePatternPackageSet extends PatternBasedPackageSet {
   }
 
   public static String getLibRelativePath(final VirtualFile virtualFile, final ProjectFileIndex index) {
-    StringBuilder relativePath = new StringBuilder(100);
+    List<String> path = new ArrayList<>();
     VirtualFile directory = virtualFile;
-    while (directory != null && index.isInLibraryClasses(directory)) {
-      relativePath.insert(0, '/');
-      relativePath.insert(0, directory.getName());
+    while (directory != null && index.isInLibrary(directory)) {
+      path.add(directory.getName());
       directory = directory.getParent();
     }
-    return relativePath.toString();
+    if (path.isEmpty()) return "";
+    Collections.reverse(path);
+    return StringUtil.join(ArrayUtil.toStringArray(path), 1, path.size(), "/");
   }
 }
index 71bf8e741d51a49f2d088728ca8a92414356b844..e913dcff625890fe5a6a55098facfbef7bc7af18 100644 (file)
@@ -71,7 +71,12 @@ public class DirectoryNode extends PackageDependenciesNode {
         }
       }
       else {
-        myFQName = FilePatternPackageSet.getLibRelativePath(myVDirectory, index);
+        if (myVDirectory.equals(index.getSourceRootForFile(myVDirectory)) || myVDirectory.equals(index.getClassRootForFile(myVDirectory))) {
+          myFQName = dirName;
+        }
+        else {
+          myFQName = FilePatternPackageSet.getLibRelativePath(myVDirectory, index);
+        }
       }
       dirName = myFQName;
     } else {