mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
test for not building stubs for java files in module but not under source roots, in library but not in class root
This commit is contained in:
@@ -0,0 +1 @@
|
||||
class Foo {}
|
||||
@@ -15,11 +15,13 @@
|
||||
*/
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user