use of groovy.lang.ExpandoMetaClassCreationHandle in project grails-core by grails.
the class GrailsClassUtils method getExpandoMetaClass.
@SuppressWarnings("rawtypes")
public static MetaClass getExpandoMetaClass(Class clazz) {
MetaClassRegistry registry = GroovySystem.getMetaClassRegistry();
Assert.isTrue(registry.getMetaClassCreationHandler() instanceof ExpandoMetaClassCreationHandle, "Grails requires an instance of [ExpandoMetaClassCreationHandle] to be set in Groovy's MetaClassRegistry! (current is : " + registry.getMetaClassCreationHandler() + ")");
MetaClass mc = registry.getMetaClass(clazz);
AdaptingMetaClass adapter = null;
if (mc instanceof AdaptingMetaClass) {
adapter = (AdaptingMetaClass) mc;
mc = ((AdaptingMetaClass) mc).getAdaptee();
}
if (!(mc instanceof ExpandoMetaClass)) {
// removes cached version
registry.removeMetaClass(clazz);
mc = registry.getMetaClass(clazz);
if (adapter != null) {
adapter.setAdaptee(mc);
}
}
Assert.isTrue(mc instanceof ExpandoMetaClass, "BUG! Method must return an instance of [ExpandoMetaClass]!");
return mc;
}
Aggregations