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)
Signup
groovy
  • groovy
  • GROOVY-5990 Mixin Issues
  • GROOVY-5298

Easy way to access mixins

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Sub-task Sub-task
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 2.0-beta-2
  • Fix Version/s: 3.0
  • Component/s: groovy-jdk
  • Labels:
    None
  • Environment:
    All
  • Number of attachments :
    0

Description

When we add mixins to a class, the mixins are available through the mixedIn property. We can access a particular mixin by using, for example

mixedIn[ClassA].foo()

This works well if we know what mixins are part of the class.

There are times when we want to be able to

(a) get a list of mixins, and

(b) be able to get a mixin one before the current mixin.

For example, something like

mixedIn.getPrevious(ClassA) would be very useful for method chaining purposes.

Right now, I had to do the following to get to this (if there is a simpler way and I simply don't know it, please correct me):

def invokeOnPreviousMixin(MetaClass currentMixinMetaClass, String method, Object[] args) {
  def previousMixin = getClass()

  for(mixin in mixedIn.mixinClasses) { //Accessing private variable here
    if(mixin.mixinClass.theClass == currentMixinMetaClass.delegate.theClass) break
    previousMixin = mixin.mixinClass.theClass
  }

  mixedIn[previousMixin]."$method"(*args)  
}

Thanks.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Paul King added a comment - 13/Feb/12 5:50 AM

add code tags

Show
Paul King added a comment - 13/Feb/12 5:50 AM add code tags
Hide
Permalink
blackdrag blackdrag added a comment - 13/Feb/12 10:53 AM

The current mixins are quite a bit broken and we are thinking about making a new mixin system for Groovy 3. That means this issue will be open a while if we do it as part of the change. Of course a contribution from you in this direction would allow us to add this feature earlier, but I don't know if your time permits that.

Show
blackdrag blackdrag added a comment - 13/Feb/12 10:53 AM The current mixins are quite a bit broken and we are thinking about making a new mixin system for Groovy 3. That means this issue will be open a while if we do it as part of the change. Of course a contribution from you in this direction would allow us to add this feature earlier, but I don't know if your time permits that.

People

  • Assignee:
    Unassigned
    Reporter:
    Venkat Subramaniam
Vote (0)
Watch (1)

Dates

  • Created:
    12/Feb/12 4:02 PM
    Updated:
    10/Feb/13 12:42 PM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.