From 2756368e95ff9c36b1cbe8800cd337892118be6d Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Wed, 21 Jan 2015 18:55:24 +0300 Subject: [PATCH 1/4] temporary disable templates indexing --- .../psi/templateLanguages/TemplateDataElementType.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataElementType.java b/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataElementType.java index 2e814f9f2290..3d5318b6c7e3 100644 --- a/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataElementType.java +++ b/platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataElementType.java @@ -32,7 +32,7 @@ import com.intellij.psi.impl.source.DummyHolder; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.impl.source.tree.*; import com.intellij.psi.tree.IElementType; -import com.intellij.psi.tree.IStubFileElementType; +import com.intellij.psi.tree.IFileElementType; import com.intellij.psi.tree.TokenSet; import com.intellij.testFramework.LightVirtualFile; import com.intellij.util.CharTable; @@ -46,7 +46,7 @@ import javax.swing.*; /** * @author peter */ -public class TemplateDataElementType extends IStubFileElementType implements ITemplateDataElementType { +public class TemplateDataElementType extends IFileElementType implements ITemplateDataElementType { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.templateLanguages.TemplateDataElementType"); public static final LanguageExtension TREE_PATCHER = new LanguageExtension("com.intellij.lang.treePatcher", new SimpleTreePatcher()); From 806d6a4b6579319f4f9c4b8bbb2e4cbc57225bca Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 21 Jan 2015 14:51:12 +0100 Subject: [PATCH 2/4] make RootsProvider.EMPTY_ROOTS unmodifiable --- .../src/com/intellij/ide/projectView/RootsProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/structure-view-api/src/com/intellij/ide/projectView/RootsProvider.java b/platform/structure-view-api/src/com/intellij/ide/projectView/RootsProvider.java index 2f341936fb3d..dc12d1056d7f 100644 --- a/platform/structure-view-api/src/com/intellij/ide/projectView/RootsProvider.java +++ b/platform/structure-view-api/src/com/intellij/ide/projectView/RootsProvider.java @@ -16,15 +16,15 @@ package com.intellij.ide.projectView; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NotNull; import java.util.Collection; +import java.util.Collections; import java.util.Set; public interface RootsProvider { - Set EMPTY_ROOTS = new HashSet(); + Set EMPTY_ROOTS = Collections.emptySet(); @NotNull Collection getRoots(); From adc4e630f1e7e7d1c6a1496613af56047a0e58ff Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 21 Jan 2015 16:08:05 +0100 Subject: [PATCH 3/4] run GroovyDebuggerTest without script compiling when possible --- .../groovy/compiler/GroovyDebuggerTest.groovy | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy index f3fe8a27c670..6e75326f3e7c 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy @@ -14,7 +14,6 @@ * limitations under the License. */ package org.jetbrains.plugins.groovy.compiler - import com.intellij.debugger.DebuggerManagerEx import com.intellij.debugger.SourcePosition import com.intellij.debugger.engine.ContextUtil @@ -33,7 +32,6 @@ import com.intellij.debugger.impl.DebuggerSession import com.intellij.debugger.impl.GenericDebuggerRunner import com.intellij.debugger.ui.impl.watch.WatchItemDescriptor import com.intellij.debugger.ui.tree.render.DescriptorLabelListener -import com.intellij.execution.configurations.RunProfile import com.intellij.execution.executors.DefaultDebugExecutor import com.intellij.execution.process.OSProcessHandler import com.intellij.execution.process.OSProcessManager @@ -48,6 +46,7 @@ import com.intellij.openapi.util.Computable import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.PsiFile import com.intellij.psi.impl.DebugUtil import com.intellij.testFramework.PsiTestUtil import com.intellij.testFramework.builders.JavaModuleFixtureBuilder @@ -55,7 +54,6 @@ import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl import com.intellij.util.SystemProperties import com.intellij.util.concurrency.Semaphore import org.jetbrains.annotations.NotNull - /** * @author peter */ @@ -90,11 +88,8 @@ class GroovyDebuggerTest extends GroovyCompilerTestCase { moduleBuilder.addJdk(StringUtil.trimEnd(StringUtil.trimEnd(javaHome, '/'), '/jre')) } - private void runDebugger(String mainClass, Closure cl) { - runDebugger(createApplicationConfiguration(mainClass, myModule), cl) - } - private void runDebugger(RunProfile configuration, Closure cl) { - make() + private void runDebugger(PsiFile script, Closure cl) { + def configuration = createScriptConfiguration(script.virtualFile.path, myModule) edt { ProgramRunner runner = ProgramRunner.PROGRAM_RUNNER_EP.extensions.find { it.class == GenericDebuggerRunner } def listener = [onTextAvailable: { ProcessEvent evt, type -> /*println evt.text*/}] as ProcessAdapter @@ -118,10 +113,10 @@ class GroovyDebuggerTest extends GroovyCompilerTestCase { } public void testVariableInScript() { - myFixture.addFileToProject("Foo.groovy", """def a = 2 + def file = myFixture.addFileToProject("Foo.groovy", """def a = 2 a"""); addBreakpoint 'Foo.groovy', 1 - runDebugger 'Foo', { + runDebugger file, { waitForBreakpoint() eval 'a', '2' eval '2?:3', '2' @@ -130,7 +125,7 @@ a"""); } public void testVariableInsideClosure() { - myFixture.addFileToProject("Foo.groovy", """def a = 2 + def file = myFixture.addFileToProject("Foo.groovy", """def a = 2 Closure c = { a++; a //3 @@ -138,7 +133,7 @@ Closure c = { c() a++"""); addBreakpoint 'Foo.groovy', 3 - runDebugger 'Foo', { + runDebugger file, { waitForBreakpoint() eval 'a', '3' } @@ -162,7 +157,7 @@ class Foo { }""") - myFixture.addFileToProject("com/Bar.groovy", """package com + def file = myFixture.addFileToProject("com/Bar.groovy", """package com import static com.Goo.* def lst = [new Foo()] as Set @@ -170,7 +165,8 @@ println 2 //4 """) addBreakpoint 'com/Bar.groovy', 4 - runDebugger 'com.Bar', { + make() + runDebugger file, { waitForBreakpoint() eval 'Foo.bar', '2' eval 'mainConstant', '42' @@ -183,7 +179,7 @@ println 2 //4 } public void testCall() { - myFixture.addFileToProject 'B.groovy', '''class B { + def file = myFixture.addFileToProject 'B.groovy', '''class B { def getFoo() {2} def call(Object... args){ @@ -195,7 +191,7 @@ println 2 //4 } }''' addBreakpoint 'B.groovy', 4 - runDebugger 'B', { + runDebugger file, { waitForBreakpoint() eval 'foo', '2' eval 'getFoo()', '2' @@ -209,7 +205,7 @@ println 2 //4 } public void testStaticContext() { - myFixture.addFileToProject 'B.groovy', ''' + def file = myFixture.addFileToProject 'B.groovy', ''' class B { public static void main(String[] args) { def cl = { a -> @@ -221,7 +217,7 @@ class B { }''' addBreakpoint 'B.groovy', 4 addBreakpoint 'B.groovy', 7 - runDebugger 'B', { + runDebugger file, { waitForBreakpoint() eval 'args.size()', '0' eval 'cl.delegate.size()', '6' @@ -237,7 +233,7 @@ class B { } public void "test closures in instance context with delegation"() { - myFixture.addFileToProject 'B.groovy', ''' + def file = myFixture.addFileToProject 'B.groovy', ''' def cl = { a -> hashCode() //2 } @@ -247,7 +243,7 @@ cl(42) // 5 def getFoo() { 13 } ''' addBreakpoint 'B.groovy', 2 - runDebugger 'B', { + runDebugger file, { waitForBreakpoint() eval 'a', '42' eval 'size()', '6' @@ -286,13 +282,12 @@ static def foo(def a) { addBreakpoint(myClass, 5) - myFixture.addFileToProject("Foo.groovy", """ + def file = myFixture.addFileToProject("Foo.groovy", """ def cl = new GroovyClassLoader() cl.parseClass('''$mcText''', 'MyClass.groovy').foo(2) """) - make() - runDebugger 'Foo', { + runDebugger file, { waitForBreakpoint() assert myClass == sourcePosition.file.virtualFile eval 'a', '2' @@ -308,7 +303,7 @@ cl.parseClass('''$mcText''', 'MyClass.groovy').foo(2) } void testAnonymousClassInScript() { - myFixture.addFileToProject('Foo.groovy', '''\ + def file = myFixture.addFileToProject('Foo.groovy', '''\ new Runnable() { void run() { print 'foo' @@ -317,14 +312,14 @@ new Runnable() { ''') addBreakpoint 'Foo.groovy', 2 - runDebugger 'Foo', { + runDebugger file, { waitForBreakpoint() eval '1+1', '2' } } void testEvalInStaticMethod() { - myFixture.addFileToProject('Foo.groovy', '''\ + def file = myFixture.addFileToProject('Foo.groovy', '''\ static def foo() { int x = 5 print x @@ -334,7 +329,7 @@ foo() ''') addBreakpoint 'Foo.groovy', 2 - runDebugger 'Foo', { + runDebugger file, { waitForBreakpoint() eval 'x', '5' } @@ -353,14 +348,14 @@ foo() myFixture.addFileToProject('module2/Scr.groovy', 'println "hello"') addBreakpoint('module1/Scr.groovy', 0) - runDebugger(createScriptConfiguration(scr.virtualFile.path, myModule)) { + runDebugger(scr) { waitForBreakpoint() assert scr == sourcePosition.file } } public void "test in static inner class"() { - myFixture.addFileToProject "Foo.groovy", """ + def file = myFixture.addFileToProject "Foo.groovy", """ class Outer { //1 static class Inner { def x = 1 @@ -385,7 +380,7 @@ public static void main(String[] args) { } """ addBreakpoint('Foo.groovy', 6) - runDebugger 'Foo', { + runDebugger file, { waitForBreakpoint() eval 'x', '1' eval 'this', 'str' From 19458eb3b60d30fdd1f21bfd5db47bf30d22c394 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 21 Jan 2015 16:51:36 +0100 Subject: [PATCH 4/4] groovyc: don't throw errors on GroovyTestCase references in the compiled code (IDEA-135469) --- .../incremental/groovy/InProcessGroovyc.java | 26 ++++++++++++++++--- .../groovy/config/GroovyFacetUtil.java | 16 ++++++------ .../groovy/compiler/GroovyCompilerTest.groovy | 8 ++++++ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/InProcessGroovyc.java b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/InProcessGroovyc.java index 1bb6f0a51169..e1da33e0aa36 100644 --- a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/InProcessGroovyc.java +++ b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/InProcessGroovyc.java @@ -25,7 +25,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.reference.SoftReference; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.lang.*; +import com.intellij.util.lang.UrlClassLoader; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,6 +34,7 @@ import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLClassLoader; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -125,10 +126,27 @@ class InProcessGroovyc { return pair.second; } - ClassLoader result = + UrlClassLoader groovyAllLoader = UrlClassLoader.build().urls(toUrls(Arrays.asList(GroovyBuilder.getGroovyRtRoot().getPath(), groovyAll))).useCache().get(); - ourParentLoaderCache = new SoftReference>(Pair.create(groovyAll, result)); - return result; + ClassLoader wrapper = new URLClassLoader(new URL[0], groovyAllLoader) { + @Override + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + try { + return super.loadClass(name, resolve); + } + catch (NoClassDefFoundError e) { + // We might attempt to load some class in groovy-all.jar that depends on a class from another library + // (e.g. GroovyTestCase extends TestCase). + // We don't want groovyc's resolve to stop at this point. + // Let's try in the child class loader which contains full compilation class with all libraries, including groovy-all. + // For this to happen we should throw ClassNotFoundException + throw new ClassNotFoundException(name, e); + } + } + }; + ; + ourParentLoaderCache = new SoftReference>(Pair.create(groovyAll, wrapper)); + return wrapper; } @NotNull diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyFacetUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyFacetUtil.java index 952916393b02..42db1982b9ce 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyFacetUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyFacetUtil.java @@ -77,15 +77,15 @@ public class GroovyFacetUtil { } public static File getBundledGroovyJar() { - String root; - if (new File(PathUtil.getJarPathForClass(GroovyFacetUtil.class)).isDirectory()) { - root = FileUtil.toCanonicalPath(PluginPathManager.getPluginHomePath("groovy") + "/../../lib/"); - } - else { - root = PathManager.getHomePath() + "/lib/"; - } - final File[] groovyJars = LibrariesUtil.getFilesInDirectoryByPattern(root, GroovyConfigUtils.GROOVY_ALL_JAR_PATTERN); + final File[] groovyJars = LibrariesUtil.getFilesInDirectoryByPattern(getLibDirectory(), GroovyConfigUtils.GROOVY_ALL_JAR_PATTERN); assert groovyJars.length == 1; return groovyJars[0]; } + + public static String getLibDirectory() { + if (new File(PathUtil.getJarPathForClass(GroovyFacetUtil.class)).isDirectory()) { + return FileUtil.toCanonicalPath(PluginPathManager.getPluginHomePath("groovy") + "/../../lib/"); + } + return PathManager.getHomePath() + "/lib/"; + } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy index ad6e529c79c1..b841ac15ae03 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy @@ -43,6 +43,7 @@ import com.intellij.psi.PsiFile import com.intellij.testFramework.PsiTestUtil import com.intellij.testFramework.TestLoggerFactory import org.jetbrains.annotations.NotNull +import org.jetbrains.plugins.groovy.config.GroovyFacetUtil import org.jetbrains.plugins.groovy.lang.psi.GroovyFile /** * @author peter @@ -858,6 +859,13 @@ class AppTest { assertTrue(exceptionFound.get()); } + public void "test extend GroovyTestCase"() { + PsiTestUtil.addLibrary(myModule, "junit", GroovyFacetUtil.libDirectory, "junit.jar"); + + myFixture.addFileToProject("a.groovy", "class Foo extends GroovyTestCase {}") + assertEmpty(make()) + } + static class GroovycTest extends GroovyCompilerTest { public void "test navigate from stub to source"() { GroovyFile groovyFile = (GroovyFile) myFixture.addFileToProject("a.groovy", "class Groovy3 { InvalidType type }")