org.codehaus.groovy.runtime.callsite.CallSite Java Examples

The following examples show how to use org.codehaus.groovy.runtime.callsite.CallSite. 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: MetaClassImpl.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Create a CallSite
 */
public CallSite createPogoCallSite(CallSite site, Object[] args) {
    if (!GroovyCategorySupport.hasCategoryInCurrentThread() && !(this instanceof AdaptingMetaClass)) {
        Class[] params = MetaClassHelper.convertToTypeArray(args);
        CallSite tempSite = site;
        if (site.getName().equals("call") && GeneratedClosure.class.isAssignableFrom(theClass)) {
            // here, we want to point to a method named "doCall" instead of "call"
            // but we don't want to replace the original call site name, otherwise
            // we loose the fact that the original method name was "call" so instead
            // we will point to a metamethod called "doCall"
            // see GROOVY-5806 for details
            tempSite = new AbstractCallSite(site.getArray(), site.getIndex(), "doCall");
        }
        MetaMethod metaMethod = getMethodWithCachingInternal(theClass, tempSite, params);
        if (metaMethod != null)
            return PogoMetaMethodSite.createPogoMetaMethodSite(site, this, metaMethod, params, args);
    }
    return new PogoMetaClassSite(site, this);
}
 
Example #2
Source File: MetaClassImpl.java    From groovy with Apache License 2.0 6 votes vote down vote up
private MetaMethod getMethodWithCachingInternal(Class sender, CallSite site, Class[] params) {
    if (GroovyCategorySupport.hasCategoryInCurrentThread())
        return getMethodWithoutCaching(sender, site.getName(), params, false);

    final MetaMethodIndex.Entry e = metaMethodIndex.getMethods(sender, site.getName());
    if (e == null) {
        return null;
    }

    MetaMethodIndex.CacheEntry cacheEntry;
    final Object methods = e.methods;
    if (methods == null)
        return null;

    cacheEntry = e.cachedMethod;
    if (cacheEntry != null && (sameClasses(cacheEntry.params, params))) {
        return cacheEntry.method;
    }

    cacheEntry = new MetaMethodIndex.CacheEntry(params, (MetaMethod) chooseMethod(e.name, methods, params));
    e.cachedMethod = cacheEntry;
    return cacheEntry.method;
}
 
Example #3
Source File: GroovyJavaMethods.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T invokeMethodOnMetaClass(Object target, String methodName, Object args) {
    try {
        CallSite[] callSiteArray = getCallSiteArray();
        Object metaClass = callSiteArray[0].callGetProperty(target);
        return (T) callSiteArray[1].call(metaClass, target, methodName, args);
    } catch (Throwable e) {
        throw Exceptions.propagate(e);
    }
}
 
Example #4
Source File: MetaClassImpl.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Create a CallSite
 */
public CallSite createPogoCallCurrentSite(CallSite site, Class sender, Object[] args) {
    if (!GroovyCategorySupport.hasCategoryInCurrentThread() && !(this instanceof AdaptingMetaClass)) {
        Class[] params = MetaClassHelper.convertToTypeArray(args);
        MetaMethod metaMethod = getMethodWithCachingInternal(sender, site, params);
        if (metaMethod != null)
            return PogoMetaMethodSite.createPogoMetaMethodSite(site, this, metaMethod, params, args);
    }
    return new PogoMetaClassSite(site, this);
}
 
Example #5
Source File: NumberNumberDiv.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createLongLong(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return createNumberNumber(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #6
Source File: NumberNumberDiv.java    From groovy with Apache License 2.0 4 votes vote down vote up
public LongDouble(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
 
Example #7
Source File: NumberNumberMetaMethod.java    From groovy with Apache License 2.0 4 votes vote down vote up
public NumberNumberCallSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Number receiver, Number arg) {
    super(site, metaClass, metaMethod, params);
    math = NumberMath.getMath(receiver,arg);
}
 
Example #8
Source File: NumberNumberPlus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public FloatInteger(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
 
Example #9
Source File: NumberNumberPlus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createDoubleFloat(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new DoubleFloat(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #10
Source File: NumberNumberPlus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public FloatDouble(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: NumberNumberDiv.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 #12
Source File: NumberNumberDiv.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 createNumberNumber(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #13
Source File: NumberNumberDiv.java    From groovy with Apache License 2.0 4 votes vote down vote up
public DoubleLong(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    super(site, metaClass, metaMethod, params, (Number) receiver, (Number) args[0]);
}
 
Example #14
Source File: NumberNumberDiv.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 #15
Source File: NumberNumberDiv.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createLongDouble(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new LongDouble(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #16
Source File: NumberNumberDiv.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 #17
Source File: NumberNumberMinus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public NumberNumber(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: NumberNumberMinus.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 #19
Source File: NumberNumberPlus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createDoubleLong(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new DoubleLong(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #20
Source File: NumberNumberMultiply.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createLongInteger(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new LongInteger(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #21
Source File: ExpandoMetaClass.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createPogoCallCurrentSite(CallSite site, Class sender, String name, Object[] args) {
    if (invokeMethodMethod != null)
        return new PogoMetaClassSite(site, this);
    return super.createPogoCallCurrentSite(site, sender, args);
}
 
Example #22
Source File: NumberNumberPlus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createDoubleDouble(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new DoubleDouble(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #23
Source File: NumberNumberMinus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createDoubleInteger(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new DoubleInteger(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #24
Source File: NumberNumberMinus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createFloatDouble(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new FloatDouble(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #25
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 #26
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 #27
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 #28
Source File: NumberNumberMinus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createLongLong(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new LongLong(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #29
Source File: NumberNumberMinus.java    From groovy with Apache License 2.0 4 votes vote down vote up
public CallSite createLongInteger(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod, Class[] params, Object receiver, Object[] args) {
    return new LongInteger(site, metaClass, metaMethod, params, receiver, args);
}
 
Example #30
Source File: NumberNumberMultiply.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]);
}