groovy.lang.MetaClassImpl Java Examples

The following examples show how to use groovy.lang.MetaClassImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCallSite.java    From groovy with Apache License 2.0 6 votes vote down vote up
private CallSite createPojoMetaClassGetPropertySite(final Object receiver) {
    final MetaClass metaClass = InvokerHelper.getMetaClass(receiver);

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

    array.array[index] = site;
    return site;
}
 
Example #2
Source File: Selector.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: PojoMetaMethodSite.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static CallSite createCachedMethodSite(CallSite site, MetaClassImpl metaClass, CachedMethod metaMethod, Class[] params, Object[] args) {
    if (metaMethod.correctArguments(args) == args) {
        if (noWrappers(args)) {
            if (noCoerce(metaMethod,args))
                return new PojoCachedMethodSiteNoUnwrap(site, metaClass, metaMethod, params);
            else
                return metaMethod.createPojoMetaMethodSite(site, metaClass, params);
        }
    }
    return new PojoCachedMethodSite(site, metaClass, metaMethod, params);
}
 
Example #4
Source File: CallSiteArray.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static CallSite createPogoSite(CallSite callSite, Object receiver, Object[] args) {
    if (receiver instanceof GroovyInterceptable) {
        return new PogoInterceptableSite(callSite);
    }

    MetaClass metaClass = ((GroovyObject)receiver).getMetaClass();

    if (metaClass instanceof MetaClassImpl) {
        return ((MetaClassImpl)metaClass).createPogoCallSite(callSite, args);
    }

    return new PogoMetaClassSite(callSite, metaClass);
}
 
Example #5
Source File: PojoMetaMethodSite.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static CallSite createPojoMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    if (metaMethod instanceof CallSiteAwareMetaMethod) {
        return ((CallSiteAwareMetaMethod)metaMethod).createPojoCallSite(site, metaClass, metaMethod, params, receiver, args);
    }

    if (metaMethod.getClass() == CachedMethod.class)
      return createCachedMethodSite (site, metaClass, (CachedMethod) metaMethod, params, args);

    return createNonAwareCallSite(site, metaClass, metaMethod, params, args);
}
 
Example #6
Source File: ConstructorSite.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static ConstructorSite createConstructorSite(CallSite site, MetaClassImpl metaClass, CachedConstructor constructor, Class[] params, Object[] args) {
    if (constructor.correctArguments(args) == args) {
        if (noWrappers(args)) {
            if (noCoerce(constructor, args))
                return new ConstructorSiteNoUnwrap(site, metaClass, constructor, params);
            else
                return new ConstructorSiteNoUnwrapNoCoerce(site, metaClass, constructor, params);
        }
    }
    return new ConstructorSite(site, metaClass, constructor, params);
}
 
Example #7
Source File: ConstructorMetaMethodSite.java    From groovy with Apache License 2.0 5 votes vote down vote up
public final Object callConstructor(Object receiver, Object[] args) throws Throwable {
    if (receiver == metaClass.getTheClass() // meta class match receiver
       && ((MetaClassImpl)metaClass).getVersion() == version // metaClass still be valid
       && MetaClassHelper.sameClasses(params, args) )  
    {
        MetaClassHelper.unwrap(args);
        try {
            return metaMethod.doMethodInvoke(metaClass.getTheClass(), args);
        } catch (GroovyRuntimeException gre) {
            throw ScriptBytecodeAdapter.unwrap(gre);
        }
    } else {
      return CallSiteArray.defaultCallConstructor(this, receiver, args);
    }
}
 
Example #8
Source File: ConstructorSite.java    From groovy with Apache License 2.0 5 votes vote down vote up
public final Object callConstructor(Object receiver, Object[] args) throws Throwable {
    if (checkCall(receiver, args)) {
        final Object bean = constructor.invoke(NO_ARGS);
        try {
            ((MetaClassImpl) metaClass).setProperties(bean, (Map) args[0]);
        } catch (GroovyRuntimeException gre) {
            throw ScriptBytecodeAdapter.unwrap(gre);
        }
        return bean;
    } else
        return CallSiteArray.defaultCallConstructor(this, receiver, args);
}
 
Example #9
Source File: NumberNumberPlus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createIntegerLong(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new IntegerLong(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #10
Source File: NumberNumberMultiply.java    From groovy with Apache License 2.0 4 votes vote down vote up
public IntegerDouble(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
 
Example #11
Source File: BooleanArrayPutAtMetaMethod.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createPojoCallSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    if (!(args[0] instanceof Integer) || !(args[1] instanceof Boolean))
        return PojoMetaMethodSite.createNonAwareCallSite(site, metaClass, metaMethod, params, args);
    else
        return new MyPojoMetaMethodSite(site, metaClass, metaMethod, params);
}
 
Example #12
Source File: FloatArrayGetAtMetaMethod.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createPojoCallSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    if (!(args[0] instanceof Integer))
        return PojoMetaMethodSite.createNonAwareCallSite(site, metaClass, metaMethod, params, args);
    else
        return new MyPojoMetaMethodSite(site, metaClass, metaMethod, params);
}
 
Example #13
Source File: IntegerArrayGetAtMetaMethod.java    From groovy with Apache License 2.0 4 votes vote down vote up
public MyPojoMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params) {
    super(site, metaClass, metaMethod, params);
}
 
Example #14
Source File: NumberNumberMinus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createFloatLong(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new FloatLong(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #15
Source File: NumberNumberMinus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createFloatFloat(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new FloatFloat(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #16
Source File: ShortArrayPutAtMetaMethod.java    From groovy with Apache License 2.0 4 votes vote down vote up
public MyPojoMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params) {
    super(site, metaClass, metaMethod, params);
}
 
Example #17
Source File: NumberNumberPlus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public LongFloat(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
 
Example #18
Source File: NumberNumberMultiply.java    From groovy with Apache License 2.0 4 votes vote down vote up
public IntegerFloat(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
 
Example #19
Source File: NumberNumberMinus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public LongLong(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
 
Example #20
Source File: CharacterArrayGetAtMetaMethod.java    From groovy with Apache License 2.0 4 votes vote down vote up
public MyPojoMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params) {
    super(site, metaClass, metaMethod, params);
}
 
Example #21
Source File: IntegerArrayPutAtMetaMethod.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createPojoCallSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    if (!(args[0] instanceof Integer) || !(args[1] instanceof Integer))
        return PojoMetaMethodSite.createNonAwareCallSite(site, metaClass, metaMethod, params, args);
    else
        return new MyPojoMetaMethodSite(site, metaClass, metaMethod, params);
}
 
Example #22
Source File: GetEffectivePojoFieldSite.java    From groovy with Apache License 2.0 4 votes vote down vote up
public GetEffectivePojoFieldSite(CallSite site, MetaClassImpl metaClass, CachedField effective) {
    super(site);
    this.metaClass = metaClass;
    this.effective = effective.getCachedField();
    version = metaClass.getVersion();
}
 
Example #23
Source File: NumberNumberMultiply.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createIntegerFloat(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new IntegerFloat(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #24
Source File: NumberNumberPlus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public IntegerDouble(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
 
Example #25
Source File: ConstructorSite.java    From groovy with Apache License 2.0 4 votes vote down vote up
public NoParamSite(CallSite site, MetaClassImpl metaClass, CachedConstructor constructor, Class[] params) {
    super(site, metaClass, constructor, params);
}
 
Example #26
Source File: NumberNumberMultiply.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createIntegerDouble(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new IntegerDouble(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #27
Source File: ConstructorSite.java    From groovy with Apache License 2.0 4 votes vote down vote up
public ConstructorSiteNoUnwrap(CallSite site, MetaClassImpl metaClass, CachedConstructor constructor, Class[] params) {
    super(site, metaClass, constructor, params);
}
 
Example #28
Source File: ConstructorSite.java    From groovy with Apache License 2.0 4 votes vote down vote up
public ConstructorSite(CallSite site, MetaClassImpl metaClass, CachedConstructor constructor, Class[] params) {
    super(site, metaClass);
    this.constructor = constructor;
    this.params = params;
    this.version = metaClass.getVersion();
}
 
Example #29
Source File: NumberNumberMultiply.java    From groovy with Apache License 2.0 4 votes vote down vote up
public DoubleFloat(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
 
Example #30
Source File: NumberNumberMinus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public LongFloat(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}