Search in sources :

Example 1 with GroovyInterceptable

use of groovy.lang.GroovyInterceptable 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 2 with GroovyInterceptable

use of groovy.lang.GroovyInterceptable 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 3 with GroovyInterceptable

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

the class InvokerHelper method invokePogoMethod.

static Object invokePogoMethod(Object object, String methodName, Object arguments) {
    GroovyObject groovy = (GroovyObject) object;
    boolean intercepting = groovy instanceof GroovyInterceptable;
    try {
        // if it's a pure interceptable object (even intercepting toString(), clone(), ...)
        if (intercepting) {
            return groovy.invokeMethod(methodName, asUnwrappedArray(arguments));
        }
        //else try a statically typed method or a GDK method
        return groovy.getMetaClass().invokeMethod(object, methodName, asArray(arguments));
    } catch (MissingMethodException e) {
        if (e instanceof MissingMethodExecutionFailed) {
            throw (MissingMethodException) e.getCause();
        } else if (!intercepting && e.getMethod().equals(methodName) && object.getClass() == e.getType()) {
            // in case there's nothing else, invoke the object's own invokeMethod()
            return groovy.invokeMethod(methodName, asUnwrappedArray(arguments));
        } else {
            throw e;
        }
    }
}
Also used : MissingMethodException(groovy.lang.MissingMethodException) GroovyInterceptable(groovy.lang.GroovyInterceptable) GroovyObject(groovy.lang.GroovyObject) MissingMethodExecutionFailed(org.codehaus.groovy.runtime.metaclass.MissingMethodExecutionFailed)

Aggregations

GroovyInterceptable (groovy.lang.GroovyInterceptable)3 MetaClass (groovy.lang.MetaClass)2 MetaClassImpl (groovy.lang.MetaClassImpl)2 GroovyObject (groovy.lang.GroovyObject)1 MissingMethodException (groovy.lang.MissingMethodException)1 MissingMethodExecutionFailed (org.codehaus.groovy.runtime.metaclass.MissingMethodExecutionFailed)1