本文整理汇总了Java中groovy.lang.MetaClassRegistry类的典型用法代码示例。如果您正苦于以下问题:Java MetaClassRegistry类的具体用法?Java MetaClassRegistry怎么用?Java MetaClassRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetaClassRegistry类属于groovy.lang包,在下文中一共展示了MetaClassRegistry类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMetaClassUnderLock
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
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;
}
示例2: setMetaClass
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
/**
* 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);
}
}
}
示例3: createAndRegister
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
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;
}
示例4: isValidWeakMetaClass
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
/**
* 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);
}
示例5: getMetaClass
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
/**
* 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);
}
}
示例6: getInstance
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
/**
* 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;
}
}
示例7: addAssociationToTarget
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
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);
}
示例8: MockProxyMetaClass
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
/**
* @param adaptee the MetaClass to decorate with interceptability
*/
public MockProxyMetaClass(MetaClassRegistry registry, Class theClass, MetaClass adaptee) {
this(registry, theClass, adaptee, false);
}
示例9: make
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
/**
* 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);
}
示例10: ClosureMetaClass
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
public ClosureMetaClass(MetaClassRegistry registry, Class theClass) {
super(registry, theClass);
}
示例11: getMetaRegistry
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
public static MetaClassRegistry getMetaRegistry() {
return metaRegistry;
}
示例12: createNormalMetaClass
import groovy.lang.MetaClassRegistry; //导入依赖的package包/类
@Override
protected synchronized MetaClass createNormalMetaClass(Class theClass, MetaClassRegistry registry) {
VertxExtensionMethodBoostrap.install(registry);
return super.createNormalMetaClass(theClass, registry);
}