test for not building stubs for java files in module but not under source roots,...
authorMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Fri, 11 Oct 2013 16:59:51 +0000 (18:59 +0200)
committerMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Fri, 11 Oct 2013 17:01:09 +0000 (19:01 +0200)
java/java-tests/testData/libResolve/classesAndSources/Foo.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/psi/resolve/ResolveInLibrariesTest.groovy
java/testFramework/src/com/intellij/testFramework/fixtures/JavaCodeInsightFixtureTestCase.java
platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java

diff --git a/java/java-tests/testData/libResolve/classesAndSources/Foo.java b/java/java-tests/testData/libResolve/classesAndSources/Foo.java
new file mode 100644 (file)
index 0000000..f72abf3
--- /dev/null
@@ -0,0 +1 @@
+class Foo {}
\ No newline at end of file
index df43e5b4f9803dafa8395e8236aed8f34fc01eea..8e3a64a504055b0cc16ede5f79fb397e4253d578 100644 (file)
  */
 package com.intellij.psi.resolve
 import com.intellij.openapi.application.ex.PathManagerEx
+import com.intellij.openapi.vfs.JarFileSystem
 import com.intellij.openapi.vfs.LocalFileSystem
 import com.intellij.openapi.vfs.VirtualFile
 import com.intellij.psi.JavaPsiFacade
 import com.intellij.psi.PsiClass
 import com.intellij.psi.PsiFile
+import com.intellij.psi.PsiManager
 import com.intellij.psi.PsiMethod
 import com.intellij.psi.search.GlobalSearchScope
 import com.intellij.psi.search.searches.ClassInheritorsSearch
@@ -158,4 +160,41 @@ class ResolveInLibrariesTest extends JavaCodeInsightFixtureTestCase {
     assert !javaSrc.node.parsed
   }
 
+  @Override
+  protected boolean toAddSourceRoot() {
+    return false;
+  }
+
+  public void "test do not build stubs in source jars"() {
+    def facade = JavaPsiFacade.getInstance(project)
+    def scope = GlobalSearchScope.allScope(project)
+
+    String testDataPathForTest = PathManagerEx.getTestDataPath() + "/libResolve/classesAndSources"
+    def lib = LocalFileSystem.getInstance().refreshAndFindFileByPath(testDataPathForTest)
+    def localFile = myFixture.copyFileToProject(testDataPathForTest + File.separator + "Foo.java", 'Foo.java')
+    assert localFile != null
+
+    checkFileIsNotLoadedAndHasNoStub(localFile)
+    assert facade.findClasses('Foo', scope).size() == 0
+    PsiTestUtil.addLibrary(myModule, 'cas', lib.path, [] as String[], ["/classesAndSources.jar!/"] as String[])
+
+    def vfile = lib.findChild("classesAndSources.jar")
+    assert vfile != null
+    vfile = JarFileSystem.getInstance().getJarRootForLocalFile(vfile);
+    assert vfile != null
+    vfile = vfile.findChild('LibraryClass.java');
+    assert vfile != null
+
+    assert facade.findClasses('LibraryClass', scope).size() == 0
+
+    checkFileIsNotLoadedAndHasNoStub(vfile)
+  }
+
+  private void checkFileIsNotLoadedAndHasNoStub(VirtualFile vfile) {
+    def file = PsiManager.getInstance(project).findFile(vfile);
+    assert file != null
+
+    assert !file.contentsLoaded
+    assert !file.stub
+  }
 }
index d811f49e33585a4eee51115d88bc97afd2628377..2b9939e6b3978a149f5d00f65d3e31d8544bff7a 100644 (file)
@@ -47,7 +47,11 @@ public abstract class JavaCodeInsightFixtureTestCase extends UsefulTestCase{
     final TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
     myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
     final JavaModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
-    moduleFixtureBuilder.addSourceContentRoot(myFixture.getTempDirPath());
+    if (toAddSourceRoot()) {
+      moduleFixtureBuilder.addSourceContentRoot(myFixture.getTempDirPath());
+    } else {
+      moduleFixtureBuilder.addContentRoot(myFixture.getTempDirPath());
+    }
     tuneFixture(moduleFixtureBuilder);    
 
     myFixture.setUp();
@@ -55,6 +59,10 @@ public abstract class JavaCodeInsightFixtureTestCase extends UsefulTestCase{
     myModule = moduleFixtureBuilder.getFixture().getModule();
   }
 
+  protected boolean toAddSourceRoot() {
+    return true;
+  }
+
   @Override
   protected void tearDown() throws Exception {
     myModule = null;
index 7d3567902f1475f05ce3b498b4d9a14c6902b11a..fd1e91d428eb9535bacb8f0b2e239bc805cc9ef0 100644 (file)
@@ -333,7 +333,7 @@ public class PsiTestUtil {
                                 final String[] classRoots,
                                 final String[] sourceRoots) {
     final String parentUrl =
-      VirtualFileManager.constructUrl(classRoots[0].endsWith(".jar!/") ? JarFileSystem.PROTOCOL : LocalFileSystem.PROTOCOL, libDir);
+      VirtualFileManager.constructUrl((classRoots.length > 0 ? classRoots[0]:sourceRoots[0]).endsWith(".jar!/") ? JarFileSystem.PROTOCOL : LocalFileSystem.PROTOCOL, libDir);
     List<String> classesUrls = new ArrayList<String>();
     List<String> sourceUrls = new ArrayList<String>();
     for (String classRoot : classRoots) {