groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <>
Subject [jira] [Commented] (GROOVY-7492) Groovy should allow CompileStatic classes to not implement GroovyObject
Date Sun, 05 Jul 2015 09:47:04 GMT


Paul King commented on GROOVY-7492:

Here is a test script:
import groovy.transform.*

class Foo {
  @Delegate List foo //= ['bar']
  Foo() { foo = new ArrayList(); foo.add('bar') }
  static void main(String[] args) { 
    def foo = new Foo()
    System.out.println "foo = " + foo + " (size: " + foo.size() + ")"
Current issues:
LDC [Ljava/lang/Object;.class
INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType (Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
// <= SBA usage
CHECKCAST [Ljava/lang/Object;
INVOKESTATIC java/util/Arrays.asList ([Ljava/lang/Object;)Ljava/util/List;
INVOKEVIRTUAL Foo.addAll (Ljava/util/Collection;)Z
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
INVOKESTATIC org/codehaus/groovy/runtime/DefaultGroovyMethods.println (Ljava/io/PrintStream;Ljava/lang/Object;)V
 // <= DGM usage
public add(Ljava/lang/Object;)Z
  INVOKESTATIC org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.booleanUnbox
(Ljava/lang/Object;)Z  // <= DTT usage

> Groovy should allow CompileStatic classes to not implement GroovyObject
> -----------------------------------------------------------------------
>                 Key: GROOVY-7492
>                 URL:
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: Paul King
>            Assignee: Paul King
>              Labels: experimental
>             Fix For: 2.5.0-beta-1
> Groovy's powerful AST transformation capabilities are extremely useful even in mostly
Java projects but the fact that generated classes implement GroovyObject means that Groovy
must be on the classpath when using any of the generated artifacts. This proposed new feature
allows an opt-out {{@POJO}} marker interface which still applies Groovy's AST transforms but
then leaves them in a much more Java-like state. The mechanism currently is only enabled when
using @CompileStatic since it produces Java-like code. This opens up some of Groovy's powerful
transforms to the wider Java community. Groovy can effectively be used as a Lombok-style pre-processor
for some Java classes. Note that this is still an experimental feature - it isn't guaranteed
at this stage to always produce code which is free from any Groovy jar dependency.

This message was sent by Atlassian JIRA

View raw message