Details
-
Type:
Sub-task
-
Status:
Open
-
Priority:
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 :
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.
add code tags