groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Mallette <spmalle...@gmail.com>
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:

https://github.com/apache/incubator-tinkerpop/blob/410ff6565b043597e339386f915da1d3d1c4632a/gremlin-groovy/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoader.groovy

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.)?

Thanks,

Stephen

Mime
View raw message