Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-22

support new mixin syntax for adding mixin support to Groovy

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • None
    • None
    • lexer, parser
    • None

    Description

      The mixin keyword should look, from the parser, like a class declaration. The only difference is you create a MixinNode rather than a ClassNode in the AST.

      mixin Foo {
      private x

      bar()

      { return "hello" }

      }

      A MixinNode is-a ClassNode.

      The other part of this fix is that a normal class declaration needs to be able to specify one or more mixins which apply to the class.

      We could just use the mixins inside a normal 'implements' syntax.

      class X extends SomeBaseClass implements Foo, SomeOtherMixin, Someinterface {
      }

      Basically at runtime the Mixin gets compiled down to a Java interface, so in Java-land a mixin is an interface which you can cast to & use. Though the implementation code of the mixin gets copied into the class to implement the interface.

      At the AST level a mixin is different to an interface (they are separated on the ClassNode constructor). I wonder if the compiler can detect the MixinNode in the implements list and pass this directly into the AST?

      Attachments

        Issue Links

          Activity

            People

              guillaume Guillaume Sauthier
              jstrachan James Strachan
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: