You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2023/11/26 11:27:07 UTC
[PR] GROOVY-10060: Support static & private interface methods [groovy]
paulk-asert opened a new pull request, #1997:
URL: https://github.com/apache/groovy/pull/1997
(no comment)
--
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: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-10060: Support static & private interface methods [groovy]
Posted by "eric-milles (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-10060: Support static & private interface methods [groovy]
Posted by "eric-milles (via GitHub)" <gi...@apache.org>.
eric-milles commented on PR #1997:
URL: https://github.com/apache/groovy/pull/1997#issuecomment-1826876769
@blackdrag @paulk-asert I was able to implement a groovy `interface` with both `default` and `private` methods in it using a java `class` (test case above). Very encouraging progress!
--
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: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-10060: Support static & private interface methods [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on PR #1997:
URL: https://github.com/apache/groovy/pull/1997#issuecomment-1826883479
I'll split the issue up since I don't think I will get static finished for alpha-3. There is still some more testing and doco to come too.
--
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: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-10060: Support static & private interface methods [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on PR #1997:
URL: https://github.com/apache/groovy/pull/1997#issuecomment-1826883539
Merged the private methods commits.
--
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: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-10060: Support static & private interface methods [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert closed pull request #1997: GROOVY-10060: Support static & private interface methods
URL: https://github.com/apache/groovy/pull/1997
--
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: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-10060: Support static & private interface methods [groovy]
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun commented on PR #1997:
URL: https://github.com/apache/groovy/pull/1997#issuecomment-1826790758
+1
--
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: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-10060: Support static & private interface methods [groovy]
Posted by "eric-milles (via GitHub)" <gi...@apache.org>.
eric-milles commented on PR #1997:
URL: https://github.com/apache/groovy/pull/1997#issuecomment-1826862454
Now `private` methods are supported in interfaces. Are `static` also supported? It was less clear from the changes if this is the case. Also, are there tests for `protected` and `@PackageScope` method errors? I can't quite find them among the tests. Is there a statement about property support -- I assume now "def foo" is a `static final` constant -- or any other differences from the Groovy 4 trait solution?
Regarding `InterfaceName.this.method()`, is that an issue of the method indexing or the access restriction or the `invokeinterface` instruction? Just curious what that's about and if there is some implication to an implementer calling the interface's private method from outside the interface's own methods.
--
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: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-10060: Support static & private interface methods [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on PR #1997:
URL: https://github.com/apache/groovy/pull/1997#issuecomment-1826880815
Yes, statics are still a work in progress. The `InterfaceName.this.method()` is a hook to allow us to hardcode the interface as receiver.
--
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: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org