eric-milles commented on PR #1997:
URL: https://github.com/apache/groovy/pull/1997#issuecomment-1826873641
Something is missing in the stub generator, because when I try to add a
static method to a groovy interface, it states that the java implementer needs
to implement the abstract method.
Here is my `org.codehaus.groovy.classgen.InterfaceTest` that is updated to
try out the Java interop if these new changes:
```groovy
package org.codehaus.groovy.classgen
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
import org.junit.Test
final class InterfaceTest {
@Test
void testJavaImplementsGroovyInterface() {
def config = new CompilerConfiguration(
targetDirectory: File.createTempDir(),
jointCompilationOptions: [memStub: true]
)
def parentDir = File.createTempDir()
try {
new File(parentDir, 'test').mkdir()
def a = new File(parentDir, 'test/GClass.groovy')
a.write '''package test
class GClass {
}
'''
def b = new File(parentDir, 'test/GInterface.groovy')
b.write '''package test
interface GInterface {
GClass[] getGC()
default String foo() { 'foo' + GInterface.this.bar() }
private String bar() { 'bar' }
// static String baz() { 'baz' }
}
'''
def c = new File(parentDir, 'test/JClass.java')
c.write '''package test;
public class JClass implements GInterface {
public GClass[] getGC() {
return new GClass[0];
}
public String toString() {
return this.foo();
}
}
'''
def d = new File(parentDir, 'Main.groovy')
d.write '''
def jc = new test.JClass()
assert jc.getGC().length == 0
assert jc.toString() == 'foobar'
// assert test.JClass.baz() == 'baz'
'''
def loader = new GroovyClassLoader(this.class.classLoader)
def cu = new JavaAwareCompilationUnit(config, loader)
cu.addSources(a, b, c, d)
cu.compile()
loader.loadClass('Main').main()
} finally {
config.targetDirectory.deleteDir()
parentDir.deleteDir()
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]