groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <pa...@asert.com.au>
Subject Re: About the native interface default method for Groovy 3
Date Thu, 14 Feb 2019 00:30:37 GMT
I'd be inclined to leave the current implementation for dynamic Groovy and
have a native implementation just with @CS. That gives us some scope for
leaving out some of those fields/methods.

On Wed., 13 Feb. 2019, 2:39 am Daniel.Sun <sunlan@apache.org wrote:

> Hi all,
>
>         I'm trying to find a solution to implement the native interface
> default method for Groovy 3 and encounter the following problems. Any
> advice
> is appreciated!
>
> 1) [Generating Fields]
> No matter whether STC is enabled or not, the following fields need to be
> generated, but `private`, `transient ` are invalid modifier for field in
> interface declaration. In addition, field `metaClass`  is not `static` so
> `metaClass` can not be generated in interface either...
>
>     private static org.codehaus.groovy.reflection.ClassInfo
> $staticClassInfo
>     public static transient boolean __$stMC
>     private transient groovy.lang.MetaClass metaClass
>
>
> 2) [Generating Methods]
> `protected` can not be used to define interface method.
>
> protected synthetic $getStaticMetaClass()Lgroovy/lang/MetaClass;
> public getMetaClass()Lgroovy/lang/MetaClass;
> public setMetaClass(Lgroovy/lang/MetaClass;)V
> public invokeMethod(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
> public getProperty(Ljava/lang/String;)Ljava/lang/Object;
> public setProperty(Ljava/lang/String;Ljava/lang/Object;)V
>
> // when STC is disabled, the following additional methods will be generated
> private static synthetic $createCallSiteArray_1([Ljava/lang/String;)V
> private static synthetic
> $createCallSiteArray()Lorg/codehaus/groovy/runtime/callsite/CallSiteArray;
> private static synthetic
> $getCallSiteArray()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
>
>
>         As for all of the above `public` instance methods, we can transform
> them to `default` instance methods.
>
>         At last, I have a crazy idea, maybe we can generate all of the
> above
> fields and methods with traits, but the default method is generated in a
> native way, e.g.
>
> ```
> // native interface
> interface SomeInterfaceWithDefaultMethod {
>         // native interface default method
>         default void helloWorld() {
>                  // generate bytecode here to use traits to invoke MOP
> methods
>          }
> }
> ```
>
> Cheers,
> Daniel.Sun
>
>
>
> -----
> Apache Groovy committer
> Blog: http://blog.sunlan.me
> Twitter: @daniel_sun
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>

Mime
View raw message