當前位置: 首頁>>代碼示例>>Java>>正文


Java GroovyObject.getMetaClass方法代碼示例

本文整理匯總了Java中groovy.lang.GroovyObject.getMetaClass方法的典型用法代碼示例。如果您正苦於以下問題:Java GroovyObject.getMetaClass方法的具體用法?Java GroovyObject.getMetaClass怎麽用?Java GroovyObject.getMetaClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在groovy.lang.GroovyObject的用法示例。


在下文中一共展示了GroovyObject.getMetaClass方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: customize

import groovy.lang.GroovyObject; //導入方法依賴的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);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:GroovyScriptFactoryTests.java

示例2: createPogoMetaClassGetPropertySite

import groovy.lang.GroovyObject; //導入方法依賴的package包/類
private CallSite createPogoMetaClassGetPropertySite(GroovyObject receiver) {
    MetaClass metaClass = receiver.getMetaClass();

    CallSite site;
    if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) {
        site = new PogoMetaClassGetPropertySite(this, metaClass);
    } else {
        final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(this.array.owner, receiver, name, false);
        if (effective != null) {
            if (effective instanceof CachedField)
                site = new GetEffectivePogoFieldSite(this, metaClass, (CachedField) effective);
            else
                site = new GetEffectivePogoPropertySite(this, metaClass, effective);
        } else {
            site = new PogoMetaClassGetPropertySite(this, metaClass);
        }
    }

    array.array[index] = site;
    return site;
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:22,代碼來源:AbstractCallSite.java

示例3: createCallCurrentSite

import groovy.lang.GroovyObject; //導入方法依賴的package包/類
private static CallSite createCallCurrentSite(CallSite callSite, GroovyObject receiver, Object[] args, Class sender) {
    CallSite site;
    if (receiver instanceof GroovyInterceptable)
      site = new PogoInterceptableSite(callSite);
    else {
        MetaClass metaClass = receiver.getMetaClass();
        if (receiver.getClass() != metaClass.getTheClass() && !metaClass.getTheClass().isInterface()) {
            site = new PogoInterceptableSite(callSite);
        }
        else
            if (metaClass instanceof MetaClassImpl) {
                site = ((MetaClassImpl)metaClass).createPogoCallCurrentSite(callSite, sender, args);
            }
            else
              site = new PogoMetaClassSite(callSite, metaClass);
    }

    replaceCallSite(callSite, site);
    return site;
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:21,代碼來源:CallSiteArray.java

示例4: invokeMethodOnSuperN

import groovy.lang.GroovyObject; //導入方法依賴的package包/類
public static Object invokeMethodOnSuperN(Class senderClass, GroovyObject receiver, String messageName, Object[] messageArguments) throws Throwable {
    MetaClass metaClass = receiver.getMetaClass();
    // ignore interception and missing method fallback
    Object result = null;
    try {
        result = metaClass.invokeMethod(senderClass, receiver, messageName, messageArguments, true, true);
    } catch (GroovyRuntimeException gre) {
        throw unwrap(gre);
    }
    return result;
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:12,代碼來源:ScriptBytecodeAdapter.java

示例5: lookupObjectMetaClass

import groovy.lang.GroovyObject; //導入方法依賴的package包/類
private MetaClass lookupObjectMetaClass(Object object) {
    if (object instanceof GroovyObject) {
        GroovyObject go = (GroovyObject) object;
        return go.getMetaClass();
    }
    Class ownerClass = object.getClass();
    if (ownerClass == Class.class) {
        ownerClass = (Class) object;
        return registry.getMetaClass(ownerClass);
    }
    MetaClass metaClass = InvokerHelper.getMetaClass(object);
    return metaClass;
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:14,代碼來源:ClosureMetaClass.java

示例6: testCompile

import groovy.lang.GroovyObject; //導入方法依賴的package包/類
public void testCompile() throws Exception {
    Class groovyClass = loader.parseClass(new File("src/test/org/codehaus/groovy/classgen/Main.groovy"));

    System.out.println("Invoking main...");

    GroovyObject object = (GroovyObject) groovyClass.newInstance();

    assertTrue(object != null);

    MetaClass metaClass = object.getMetaClass();
    System.out.println("Metaclass: " + metaClass);

    Class type = object.getClass();
    System.out.println("Type: " + type);

    // invoke via metaclass
    metaClass.invokeMethod(object, "main", null);

    // invoke directly
    object.invokeMethod("main", null);
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:22,代碼來源:GroovyClassLoaderTest.java


注:本文中的groovy.lang.GroovyObject.getMetaClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。