You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by "Daniel.Sun" <su...@apache.org> on 2019/02/12 16:35:44 UTC

About the native interface default method for Groovy 3

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

Re: About the native interface default method for Groovy 3

Posted by "Daniel.Sun" <su...@apache.org>.
Hi Paul,

> 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.
      Agreed. As Java interface can not contain all fields/methods generated
by groovy compiler, it's better to get rid of most of them.

      In addition, I wish Jochen could give us more advice on the native
implementation.

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

Re: About the native interface default method for Groovy 3

Posted by Paul King <pa...@asert.com.au>.
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
>