jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-22

support new mixin syntax for adding mixin support to Groovy

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: lexer, parser
  • Labels:
    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?

Issue Links

is depended upon by

Task - A task that needs to be done. GROOVY-753 complete parser

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Guillaume Laforge added a comment - 02/Nov/07 4:35 AM

There are various ways to do mixins in Groovy (categories, expando metaclasses, etc).
We may however revisit this issue at some point to offer a more generalized and homogeneous way of supporting mixins.

Show
Guillaume Laforge added a comment - 02/Nov/07 4:35 AM There are various ways to do mixins in Groovy (categories, expando metaclasses, etc). We may however revisit this issue at some point to offer a more generalized and homogeneous way of supporting mixins.

People

  • Assignee:
    Guillaume Laforge
    Reporter:
    james strachan
Vote (1)
Watch (1)

Dates

  • Created:
    06/Oct/03 5:54 AM
    Updated:
    02/Nov/07 4:35 AM
    Resolved:
    02/Nov/07 4:35 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.