GROOVY-8364: add test cases
diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index 3f4393e..b221d99 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -19,8 +19,11 @@
package gls.innerClass
import groovy.test.NotYetImplemented
+import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.codehaus.groovy.control.CompilationFailedException
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
import org.junit.Test
import static groovy.test.GroovyAssert.assertScript
@@ -1019,19 +1022,104 @@
'''
}
- @Test // GROOVY-5989
- void testReferenceToOuterClassNestedInterface() {
+ @Test // GROOVY-5754
+ void testResolveInnerOfSuperType() {
assertScript '''
- interface Koo { class Inner { } }
+ interface I { class C { } }
- class Usage implements Koo {
- static class MyInner extends Inner { }
+ class Outer implements I {
+ static class Inner extends C {}
}
- assert new Usage() != null
+ print I.C
'''
}
+ @Test // GROOVY-5989
+ void testResolveInnerOfSuperType2() {
+ assertScript '''
+ interface I { class C { } }
+
+ class Outer implements I {
+ static class Inner extends C { }
+ }
+
+ new Outer()
+ new Outer.Inner()
+ '''
+ }
+
+ @Test // GROOVY-8364
+ void testResolveInnerOfSuperType3() {
+ assertScript '''
+ abstract class A { static class C { } }
+
+ class B extends A {
+ static m() {
+ C
+ }
+ }
+
+ assert B.m() == A.C
+ '''
+ }
+
+ @Test // GROOVY-8364
+ void testResolveInnerOfSuperType4() {
+ assertScript '''
+ abstract class A { interface I { } }
+
+ class B extends A {
+ static m() {
+ I
+ }
+ }
+
+ assert B.m() == A.I
+ '''
+ }
+
+ @CompileDynamic @Test // GROOVY-8364
+ void testResolveInnerOfSuperType5() {
+ def config = new CompilerConfiguration(
+ targetDirectory: File.createTempDir(),
+ jointCompilationOptions: [memStub: true]
+ )
+ def parentDir = File.createTempDir()
+ try {
+ new File(parentDir, 'p').mkdir()
+ new File(parentDir, 'q').mkdir()
+
+ def a = new File(parentDir, 'p/A.Java')
+ a.write '''
+ package p;
+ public abstract class A {
+ public interface I { }
+ }
+ '''
+ def b = new File(parentDir, 'q/B.groovy')
+ b.write '''
+ package q
+ import p.A
+ class B extends A {
+ static m() {
+ I
+ }
+ }
+ '''
+
+ def loader = new GroovyClassLoader(this.class.classLoader)
+ def cu = new JavaAwareCompilationUnit(config, loader)
+ cu.addSources(a, b)
+ cu.compile()
+
+ assert loader.loadClass('q.B').m() instanceof Class
+ } finally {
+ config.targetDirectory.deleteDir()
+ parentDir.deleteDir()
+ }
+ }
+
@Test // GROOVY-5679, GROOVY-5681
void testEnclosingMethodIsSet() {
assertScript '''
diff --git a/src/test/gls/innerClass/InnerInterfaceTest.groovy b/src/test/gls/innerClass/InnerInterfaceTest.groovy
index 4021c42..bf91ad2 100644
--- a/src/test/gls/innerClass/InnerInterfaceTest.groovy
+++ b/src/test/gls/innerClass/InnerInterfaceTest.groovy
@@ -26,7 +26,7 @@
class InnerInterfaceTest extends GroovyTestCase {
void testStaticInnerInterfaceInAClass() {
- assertScript """
+ assertScript '''
class Foo4422V1 {
static class Bar {
def bar(){}
@@ -36,7 +36,7 @@
def baz()
}
}
-
+
class BazImpl implements Foo4422V1.Baz {
def baz(){}
}
@@ -46,29 +46,29 @@
assert Foo4422V1.Baz.getMethod('baz') != null
assert Foo4422V1.Baz.getField('TEST') != null
assert BazImpl != null
- """
+ '''
}
void testStaticInnerInterfaceInAnInterface() {
- assertScript """
+ assertScript '''
interface Foo4422V2 {
static interface Baz {}
}
-
+
assert Foo4422V2.Baz != null
- """
+ '''
}
-
+
void testNonStaticInnerInterfaceInAClass() {
- assertScript """
+ assertScript '''
class Foo4422V3 {
class Bar {}
interface Baz {}
}
-
+
assert Foo4422V3.Bar != null
assert Foo4422V3.Baz != null
- """
+ '''
}
// GROOVY-5989
@@ -85,19 +85,4 @@
}
'''
}
-
- // GROOVY-5754
- void testResolveInnerInterface() {
- assertScript '''
- class Usage implements Koo {
- static class MyInner extends Inner {}
- }
-
- interface Koo {
- class Inner {
- }
- }
- Koo.Inner
- '''
- }
-}
\ No newline at end of file
+}