inheritance transitivity with several versions of same library in classpath (IDEA...
[idea/community.git] / java / java-tests / testSrc / com / intellij / psi / resolve / ResolveInLibrariesTest.groovy
index ceb2bbd93df6fe43525f21d15a92488bc8a4347d..2f7fe69025d027a05ae9292ec53b9014eb529cd2 100644 (file)
@@ -51,4 +51,39 @@ class ResolveInLibrariesTest extends JavaCodeInsightFixtureTestCase {
 
   }
 
+  public void "test inheritance transitivity"() {
+    def lib = LocalFileSystem.getInstance().refreshAndFindFileByPath(PathManagerEx.getTestDataPath() + "/../../../lib")
+    def protoJar = lib.children.find { it.name.startsWith("protobuf") }
+
+    def jarCopy = myFixture.copyFileToProject(protoJar.path, 'lib/protoJar.jar')
+
+    PsiTestUtil.addLibrary(myModule, 'proto1', lib.path, ["/$protoJar.name!/"] as String[], [] as String[])
+    PsiTestUtil.addLibrary(myModule, 'proto2', jarCopy.parent.path, ["/$jarCopy.name!/"] as String[], [] as String[])
+
+    def scope = GlobalSearchScope.allScope(project)
+
+    def bottoms = JavaPsiFacade.getInstance(project).findClasses('com.google.protobuf.AbstractMessage', scope)
+    assert bottoms.size() == 2
+
+    def middles = JavaPsiFacade.getInstance(project).findClasses('com.google.protobuf.AbstractMessageLite', scope)
+    assert middles.size() == 2
+
+    def intfs = JavaPsiFacade.getInstance(project).findClasses('com.google.protobuf.MessageLite', scope)
+    assert intfs.size() == 2
+
+    for (i in 0..1) {
+      assert middles[i].isInheritor(intfs[i], true)
+      assert bottoms[i].isInheritor(intfs[i], true)
+      assert bottoms[i].isInheritor(middles[i], true)
+    }
+
+    for (deep in [false, true]) {
+      for (i in 0..1) {
+        assert !middles[i].isInheritor(intfs[1-i], deep)
+        assert !bottoms[i].isInheritor(intfs[1-i], deep)
+        assert !bottoms[i].isInheritor(middles[1-i], deep)
+      }
+    }
+  }
+
 }