Search in sources :

Example 1 with MetaClassImpl

use of groovy.lang.MetaClassImpl in project groovy-core by groovy.

the class CallSiteArray method createPojoSite.

// for MetaClassImpl we try to pick meta method,
// otherwise or if method doesn't exist we make call via POJO meta class
private static CallSite createPojoSite(CallSite callSite, Object receiver, Object[] args) {
    final Class klazz = receiver.getClass();
    MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
    if (!GroovyCategorySupport.hasCategoryInCurrentThread() && metaClass instanceof MetaClassImpl) {
        final MetaClassImpl mci = (MetaClassImpl) metaClass;
        final ClassInfo info = mci.getTheCachedClass().classInfo;
        if (info.hasPerInstanceMetaClasses()) {
            return new PerInstancePojoMetaClassSite(callSite, info);
        } else {
            return mci.createPojoCallSite(callSite, receiver, args);
        }
    }
    ClassInfo info = ClassInfo.getClassInfo(klazz);
    if (info.hasPerInstanceMetaClasses())
        return new PerInstancePojoMetaClassSite(callSite, info);
    else
        return new PojoMetaClassSite(callSite, metaClass);
}
Also used : MetaClass(groovy.lang.MetaClass) MetaClass(groovy.lang.MetaClass) MetaClassImpl(groovy.lang.MetaClassImpl) ClassInfo(org.codehaus.groovy.reflection.ClassInfo)

Example 2 with MetaClassImpl

use of groovy.lang.MetaClassImpl in project groovy-core by groovy.

the class CallSiteArray method createCallStaticSite.

private static CallSite createCallStaticSite(CallSite callSite, final Class receiver, Object[] args) {
    CallSite site;
    AccessController.doPrivileged(new PrivilegedAction<Void>() {

        public Void run() {
            try {
                Class.forName(receiver.getName(), true, receiver.getClassLoader());
            } catch (Exception e) {
            // force <clinit>
            }
            return null;
        }
    });
    MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
    if (metaClass instanceof MetaClassImpl) {
        site = ((MetaClassImpl) metaClass).createStaticSite(callSite, args);
    } else
        site = new StaticMetaClassSite(callSite, metaClass);
    replaceCallSite(callSite, site);
    return site;
}
Also used : MetaClass(groovy.lang.MetaClass) MetaClassImpl(groovy.lang.MetaClassImpl)

Example 3 with MetaClassImpl

use of groovy.lang.MetaClassImpl in project groovy-core by groovy.

the class CallSiteArray method createCallCurrentSite.

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;
}
Also used : MetaClass(groovy.lang.MetaClass) GroovyInterceptable(groovy.lang.GroovyInterceptable) MetaClassImpl(groovy.lang.MetaClassImpl)

Example 4 with MetaClassImpl

use of groovy.lang.MetaClassImpl in project groovy by apache.

the class AbstractCallSite method createPogoMetaClassGetPropertySite.

private CallSite createPogoMetaClassGetPropertySite(final 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;
}
Also used : MetaClass(groovy.lang.MetaClass) MetaProperty(groovy.lang.MetaProperty) CachedField(org.codehaus.groovy.reflection.CachedField) MetaClassImpl(groovy.lang.MetaClassImpl)

Example 5 with MetaClassImpl

use of groovy.lang.MetaClassImpl in project groovy by apache.

the class CallSiteArray method createCallConstructorSite.

private static CallSite createCallConstructorSite(CallSite callSite, Class receiver, Object[] args) {
    MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
    CallSite site = metaClass instanceof MetaClassImpl ? ((MetaClassImpl) metaClass).createConstructorSite(callSite, args) : new MetaClassConstructorSite(callSite, metaClass);
    replaceCallSite(callSite, site);
    return site;
}
Also used : MetaClass(groovy.lang.MetaClass) MetaClassImpl(groovy.lang.MetaClassImpl)

Aggregations

MetaClassImpl (groovy.lang.MetaClassImpl)18 MetaClass (groovy.lang.MetaClass)17 ExpandoMetaClass (groovy.lang.ExpandoMetaClass)7 CachedClass (org.codehaus.groovy.reflection.CachedClass)4 ClosureMetaClass (org.codehaus.groovy.runtime.metaclass.ClosureMetaClass)4 GroovyInterceptable (groovy.lang.GroovyInterceptable)3 MetaMethod (groovy.lang.MetaMethod)3 ProxyMetaClass (groovy.lang.ProxyMetaClass)3 AdaptingMetaClass (groovy.lang.AdaptingMetaClass)2 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)2 MetaProperty (groovy.lang.MetaProperty)2 CachedField (org.codehaus.groovy.reflection.CachedField)2 ClassInfo (org.codehaus.groovy.reflection.ClassInfo)2 CachedSAMClass (org.codehaus.groovy.reflection.stdclasses.CachedSAMClass)2 GroovyObject (groovy.lang.GroovyObject)1 MetaBeanProperty (groovy.lang.MetaBeanProperty)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1