From 7683276ed8492d124abc419ec62dd3a29c10942b Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 1 Apr 2015 13:32:20 +0200 Subject: [PATCH] findClass should correctly sort compiled classes located inside project content (IDEA-101806) --- .../interJarDependencies/lib1/A.class | Bin 0 -> 333 bytes .../codeInsight/interJarDependencies/lib2.jar | Bin 0 -> 699 bytes .../psi/resolve/ResolveInLibrariesTest.groovy | 22 +++++++++++++++++- .../scopes/ModuleWithDependenciesScope.java | 6 ++--- 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/interJarDependencies/lib1/A.class create mode 100644 java/java-tests/testData/codeInsight/interJarDependencies/lib2.jar diff --git a/java/java-tests/testData/codeInsight/interJarDependencies/lib1/A.class b/java/java-tests/testData/codeInsight/interJarDependencies/lib1/A.class new file mode 100644 index 0000000000000000000000000000000000000000..146dde51c6e13c06acc782535ad5ea929198608f GIT binary patch literal 333 zcmYjL%}T>S5dLP9CN-wEP5S`#)(UMvkBSfkPr)84y>H@Dx5N!3sn4aSf(IYKhZ1K~ zu`cX<%=gE9eSdrcxWYJqi$NDdACZp{!Mo8$H@5_5I$IOmyYfj9`l&YRVfT`$>QQC| zGf`URvRKPX+x?exn`d2fG)=AvLS7Qa(^+1gi3b`}+ literal 0 HcmV?d00001 diff --git a/java/java-tests/testData/codeInsight/interJarDependencies/lib2.jar b/java/java-tests/testData/codeInsight/interJarDependencies/lib2.jar new file mode 100644 index 0000000000000000000000000000000000000000..d2af10ba7803f07f944f98d1b50d31e218afb8bd GIT binary patch literal 699 zcmWIWW@Zs#;Nak3P)mq(Vn71y3@i+eddWG7#l`3vtge8V!k>GN9TY8vdOSV%W}J^#S}`Tu9$&A)HeG3_{H z(bOK;F`2=$A-KstJZh^sOSx6F;GWyh0)^UkUiwt`ImY9&Lf5RhD*0Z4>stcL-ubSt z4btyE?`}dz#!oZ!V4PG;Hwa*xY$(vX_M2 z1VOj@FN;>B+H!2PLs(vhL zzk8(ew)5Qj6~DXX%1?ff4)A8@Q2H=^!gF9qcrY?B1mFoD1_mcc_yEHu>yU$p>wE7c zq03utyZsN8-&_8LPr?aN)jNcXC?-`%@ zS!Bal;b7m;yskf*e`34b!MR?lt0fQ0^@g*g$K@3{sZZ6ax7?GuGp=h*g1Xn~tr}rY z-kZ&r1@Ap&yEyZc$AX><^1YYmR)`lWUNMUciCU%WesGb^i_(8Oyie4=FB4kCI{kq< z^GY`Bg+Cix-V3*F_}Tv~LLoTmYejdZ(D`e3#b0dhs}0+3#+iHV!}11(@U7yHb~UQ= z=D1%wZhz%h^R4|aeCL+zV*~}uyXBLnJ^}`dB{*0ZnM4>62?sgIKnVvGASI&!Z&Z!Q dhO(pRQUF>54c`E7RyL3v6A%qJ4*=6-0?GgY literal 0 HcmV?d00001 diff --git a/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveInLibrariesTest.groovy b/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveInLibrariesTest.groovy index f7be145206bf..a0c761a12f89 100644 --- a/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveInLibrariesTest.groovy +++ b/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveInLibrariesTest.groovy @@ -160,7 +160,7 @@ class ResolveInLibrariesTest extends JavaCodeInsightFixtureTestCase { @Override protected boolean toAddSourceRoot() { - return false; + return name != "test do not build stubs in source jars"; } public void "test do not build stubs in source jars"() { @@ -197,4 +197,24 @@ class ResolveInLibrariesTest extends JavaCodeInsightFixtureTestCase { assert !StubTreeLoader.instance.canHaveStub(vfile) assert file.stub // from text } + + public void "test directory with class files inside project content"() { + def testData = PathManagerEx.getTestDataPath() + "/codeInsight/interJarDependencies" + myFixture.setTestDataPath(testData) + PsiTestUtil.addLibrary(myModule, "lib2", testData, "lib2.jar"); + + myFixture.copyDirectoryToProject("lib1", "lib1") + PsiTestUtil.addLibrary(myModule, "lib1", myFixture.tempDirFixture.getFile("").path, "lib1"); + + myFixture.configureFromExistingVirtualFile(myFixture.addFileToProject("TestCase.java", """ +class Testcase { + public static void main( String[] args ) { + new B().a(); // should not work, because the A in lib1 has no method a + new B().a2(); // should work, because the A with this method is in lib1 + } +} +""").virtualFile) + myFixture.checkHighlighting() + } + } diff --git a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependenciesScope.java b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependenciesScope.java index 05b0ef34be7e..bfc6114a0f16 100644 --- a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependenciesScope.java +++ b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependenciesScope.java @@ -176,10 +176,8 @@ public class ModuleWithDependenciesScope extends GlobalSearchScope { @Nullable private VirtualFile getFileRoot(@NotNull VirtualFile file) { - if (myProjectFileIndex.isInContent(file)) { - return myProjectFileIndex.getSourceRootForFile(file); - } - return myProjectFileIndex.getClassRootForFile(file); + VirtualFile root = myProjectFileIndex.getClassRootForFile(file); + return root != null ? root : myProjectFileIndex.getSourceRootForFile(file); } @TestOnly