Search in sources :

Example 1 with ExpandoMetaClassCreationHandle

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;
}
Also used : MetaClassRegistry(groovy.lang.MetaClassRegistry) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) MetaClass(groovy.lang.MetaClass) AdaptingMetaClass(groovy.lang.AdaptingMetaClass) ExpandoMetaClassCreationHandle(groovy.lang.ExpandoMetaClassCreationHandle) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) AdaptingMetaClass(groovy.lang.AdaptingMetaClass)

Aggregations

AdaptingMetaClass (groovy.lang.AdaptingMetaClass)1 ExpandoMetaClass (groovy.lang.ExpandoMetaClass)1 ExpandoMetaClassCreationHandle (groovy.lang.ExpandoMetaClassCreationHandle)1 MetaClass (groovy.lang.MetaClass)1 MetaClassRegistry (groovy.lang.MetaClassRegistry)1