Java 类groovy.lang.MetaClassRegistry 实例源码

项目:groovy    文件:ClassInfo.java   
private MetaClass getMetaClassUnderLock() {
    MetaClass answer = getStrongMetaClass();
    if (answer!=null) return answer;

    answer = getWeakMetaClass();
    final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
    MetaClassRegistry.MetaClassCreationHandle mccHandle = metaClassRegistry.getMetaClassCreationHandler();

    if (isValidWeakMetaClass(answer, mccHandle)) {
        return answer;
    }

    answer = mccHandle.create(classRef.get(), metaClassRegistry);
    answer.initialize();

    if (GroovySystem.isKeepJavaMetaClasses()) {
        setStrongMetaClass(answer);
    } else {
        setWeakMetaClass(answer);
    }
    return answer;
}
项目:groovy    文件:DefaultGroovyMethods.java   
/**
 * Sets the metaclass for a given class.
 *
 * @param self the class whose metaclass we wish to set
 * @param metaClass the new MetaClass
 * @since 1.6.0
 */
public static void setMetaClass(Class self, MetaClass metaClass) {
    final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
    if (metaClass == null)
        metaClassRegistry.removeMetaClass(self);
    else {
        if (metaClass instanceof HandleMetaClass) {
            metaClassRegistry.setMetaClass(self, ((HandleMetaClass)metaClass).getAdaptee());
        } else {
            metaClassRegistry.setMetaClass(self, metaClass);
        }
        if (self==NullObject.class) {
            NullObject.getNullObject().setMetaClass(metaClass);
        }
    }
}
项目:HeliosStreams    文件:MetaClassRegistryCleaner.java   
public static MetaClassRegistryCleaner createAndRegister() {

        MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
        MetaClassRegistryChangeEventListener[] listeners = metaClassRegistry.getMetaClassRegistryChangeEventListeners();
        boolean registered = false;
        for (MetaClassRegistryChangeEventListener listener : listeners) {
            if (listener == INSTANCE) {
                registered = true;break;
            }
        }
        if (!registered) {
            GroovySystem.getMetaClassRegistry().addMetaClassRegistryChangeEventListener(INSTANCE);
        }
        return INSTANCE;
    }
项目:groovy    文件:ClassInfo.java   
/**
 * if EMC.enableGlobally() is OFF, return whatever the cached answer is.
 * but if EMC.enableGlobally() is ON and the cached answer is not an EMC, come up with a fresh answer
 */
private static boolean isValidWeakMetaClass(MetaClass metaClass, MetaClassRegistry.MetaClassCreationHandle mccHandle) {
    if(metaClass==null) return false;
    boolean enableGloballyOn = (mccHandle instanceof ExpandoMetaClassCreationHandle);
    boolean cachedAnswerIsEMC = (metaClass instanceof ExpandoMetaClass);
    return (!enableGloballyOn || cachedAnswerIsEMC);
}
项目:groovy    文件:DefaultGroovyMethods.java   
/**
 * Adds a "metaClass" property to all class objects so you can use the syntax
 * <code>String.metaClass.myMethod = { println "foo" }</code>
 *
 * @param c The java.lang.Class instance
 * @return An MetaClass instance
 * @since 1.5.0
 */
public static MetaClass getMetaClass(Class c) {
    MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
    MetaClass mc = metaClassRegistry.getMetaClass(c);
    if (mc instanceof ExpandoMetaClass
            || mc instanceof DelegatingMetaClass && ((DelegatingMetaClass) mc).getAdaptee() instanceof ExpandoMetaClass)
        return mc;
    else {
        return new HandleMetaClass(mc);
    }
}
项目:groovy    文件:MetaClassRegistryImpl.java   
/**
 * Singleton of MetaClassRegistry. 
 *
 * @param includeExtension
 * @return the registry
 */
public static synchronized MetaClassRegistry getInstance(int includeExtension) {
    if (includeExtension != DONT_LOAD_DEFAULT) {
        if (instanceInclude == null) {
            instanceInclude = new MetaClassRegistryImpl();
        }
        return instanceInclude;
    } else {
        if (instanceExclude == null) {
            instanceExclude = new MetaClassRegistryImpl(DONT_LOAD_DEFAULT);
        }
        return instanceExclude;
    }
}
项目:AlgoTrader    文件:GrailsDataBinder.java   
private void addAssociationToTarget(String name, Object target, Object obj) {
    if (obj == null) {
        return;
    }

    MetaClassRegistry reg = GroovySystem.getMetaClassRegistry();
    MetaClass mc = reg.getMetaClass(target.getClass());
    final String addMethodName = "addTo" + GrailsNameUtils.getClassNameRepresentation(name);
    mc.invokeMethod(target, addMethodName, obj);
}
项目:groovy    文件:MockProxyMetaClass.java   
/**
 * @param adaptee the MetaClass to decorate with interceptability
 */
public MockProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee) {
    this(registry, theClass, adaptee, false);
}
项目:groovy    文件:MockProxyMetaClass.java   
/**
 * @param adaptee the MetaClass to decorate with interceptability
 */
public MockProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee, boolean interceptConstruction) {
    super(registry, theClass, adaptee);
    this.interceptConstruction = interceptConstruction;
}
项目:groovy    文件:MockProxyMetaClass.java   
/**
 * convenience factory method allowing interceptConstruction to be set.
 */
public static MockProxyMetaClass make(Class theClass, boolean interceptConstruction) {
    MetaClassRegistry metaRegistry = GroovySystem.getMetaClassRegistry();
    MetaClass meta = metaRegistry.getMetaClass(theClass);
    return new MockProxyMetaClass(metaRegistry, theClass, meta, interceptConstruction);
}
项目:groovy    文件:ClosureMetaClass.java   
public ClosureMetaClass(MetaClassRegistry registry, Class theClass) {
    super(registry, theClass);
}
项目:groovy    文件:InvokerHelper.java   
public static MetaClassRegistry getMetaRegistry() {
    return metaRegistry;
}
项目:vertx-lang-groovy    文件:CustomMetaClassCreationHandle.java   
@Override
protected synchronized MetaClass createNormalMetaClass(Class theClass, MetaClassRegistry registry) {
  VertxExtensionMethodBoostrap.install(registry);
  return super.createNormalMetaClass(theClass, registry);
}