groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Mallette <>
Subject Usage of MetaClassRegistry.removeMetaClass()
Date Tue, 12 May 2015 12:37:42 GMT
At TinkerPop, one of the things that we use Groovy for is to help provide
some syntactic sugar to the Gremlin graph traversal language.  Users can
statically turn "sugar" on using this class:

As part of our unit testing we'd like to be able to "turn off" the effects
of the SugarLoader.  To accomplish this, we tried using the
MetaClassRegistry as follows:

def metaRegistry = GroovySystem.metaClassRegistry
def metaClassesToRemove = metaRegistry.iterator()
metaClassesToRemove.collect { (Class) it.theClass }.each {
metaRegistry.removeMetaClass(it) }

We found that for some reason that didn't completely work and we had to
hard-code some classes to explicitly pass them to the
MetaClassRegistry.removeMetaClass(hardCodedClass) directly.

Could someone please explain why we need that extra step?  I suppose the
follow-up question would then be, how do we avoid that step (i.e. how do we
clearly undo everything SugarLoader added via changes to metaClass,
mixin(), etc.)?



View raw message