本文整理汇总了Java中groovy.lang.DelegatingMetaClass类的典型用法代码示例。如果您正苦于以下问题:Java DelegatingMetaClass类的具体用法?Java DelegatingMetaClass怎么用?Java DelegatingMetaClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DelegatingMetaClass类属于groovy.lang包,在下文中一共展示了DelegatingMetaClass类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customize
import groovy.lang.DelegatingMetaClass; //导入依赖的package包/类
@Override
public void customize(GroovyObject goo) {
DelegatingMetaClass dmc = new DelegatingMetaClass(goo.getMetaClass()) {
@Override
public Object invokeMethod(Object arg0, String mName, Object[] arg2) {
if (mName.contains("Missing")) {
throw new IllegalStateException("Gotcha");
}
else {
return super.invokeMethod(arg0, mName, arg2);
}
}
};
dmc.initialize();
goo.setMetaClass(dmc);
}
示例2: getMetaClass
import groovy.lang.DelegatingMetaClass; //导入依赖的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);
}
}
示例3: setMetaClass
import groovy.lang.DelegatingMetaClass; //导入依赖的package包/类
private static void setMetaClass(final MetaClass metaClass) {
final MetaClass newMetaClass = new DelegatingMetaClass(metaClass) {
@Override
public Object invokeStaticMethod(Object object, String methodName, Object[] arguments) {
return InvokerHelper.invokeMethod(INSTANCE, methodName, arguments);
}
};
GroovySystem.getMetaClassRegistry().setMetaClass(ProxyGenerator.class, newMetaClass);
}