Search in sources :

Example 6 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 7 with MetaClassImpl

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

the class CallSiteArray method createCallConstructorSite.

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

Example 8 with MetaClassImpl

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

the class Selector method getMetaClassImpl.

/**
     * Returns the MetaClassImpl if the given MetaClass is one of
     * MetaClassImpl, AdaptingMetaClass or ClosureMetaClass. If
     * none of these cases matches, this method returns null.
     */
private static MetaClassImpl getMetaClassImpl(MetaClass mc, boolean includeEMC) {
    Class mcc = mc.getClass();
    boolean valid = mcc == MetaClassImpl.class || mcc == AdaptingMetaClass.class || mcc == ClosureMetaClass.class || (includeEMC && mcc == ExpandoMetaClass.class);
    if (!valid) {
        if (LOG_ENABLED)
            LOG.info("meta class is neither MetaClassImpl, nor AdoptingMetaClass, nor ClosureMetaClass, normal method selection path disabled.");
        return null;
    }
    if (LOG_ENABLED)
        LOG.info("meta class is a recognized MetaClassImpl");
    return (MetaClassImpl) mc;
}
Also used : CachedSAMClass(org.codehaus.groovy.reflection.stdclasses.CachedSAMClass) AdaptingMetaClass(groovy.lang.AdaptingMetaClass) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) ClosureMetaClass(org.codehaus.groovy.runtime.metaclass.ClosureMetaClass) MetaClass(groovy.lang.MetaClass) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) MetaClassImpl(groovy.lang.MetaClassImpl) AdaptingMetaClass(groovy.lang.AdaptingMetaClass)

Example 9 with MetaClassImpl

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

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 10 with MetaClassImpl

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

the class Selector method getMetaClassImpl.

/**
     * Returns the MetaClassImpl if the given MetaClass is one of
     * MetaClassImpl, AdaptingMetaClass or ClosureMetaClass. If
     * none of these cases matches, this method returns null.
     */
private static MetaClassImpl getMetaClassImpl(MetaClass mc, boolean includeEMC) {
    Class mcc = mc.getClass();
    boolean valid = mcc == MetaClassImpl.class || mcc == AdaptingMetaClass.class || mcc == ClosureMetaClass.class || (includeEMC && mcc == ExpandoMetaClass.class);
    if (!valid) {
        if (LOG_ENABLED)
            LOG.info("meta class is neither MetaClassImpl, nor AdoptingMetaClass, nor ClosureMetaClass, normal method selection path disabled.");
        return null;
    }
    if (LOG_ENABLED)
        LOG.info("meta class is a recognized MetaClassImpl");
    return (MetaClassImpl) mc;
}
Also used : CachedSAMClass(org.codehaus.groovy.reflection.stdclasses.CachedSAMClass) AdaptingMetaClass(groovy.lang.AdaptingMetaClass) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) ClosureMetaClass(org.codehaus.groovy.runtime.metaclass.ClosureMetaClass) MetaClass(groovy.lang.MetaClass) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) MetaClassImpl(groovy.lang.MetaClassImpl) AdaptingMetaClass(groovy.lang.AdaptingMetaClass)

Aggregations

MetaClass (groovy.lang.MetaClass)10 MetaClassImpl (groovy.lang.MetaClassImpl)10 AdaptingMetaClass (groovy.lang.AdaptingMetaClass)2 ExpandoMetaClass (groovy.lang.ExpandoMetaClass)2 GroovyInterceptable (groovy.lang.GroovyInterceptable)2 ClassInfo (org.codehaus.groovy.reflection.ClassInfo)2 CachedSAMClass (org.codehaus.groovy.reflection.stdclasses.CachedSAMClass)2 ClosureMetaClass (org.codehaus.groovy.runtime.metaclass.ClosureMetaClass)2