Java Code Examples for groovy.lang.MissingMethodException#getCause()

The following examples show how to use groovy.lang.MissingMethodException#getCause() . 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: PogoMetaClassSite.java    From groovy with Apache License 2.0 6 votes vote down vote up
public final Object call(final Object receiver, final Object[] args) throws Throwable {
    if (checkCall(receiver)) {
        try {
            try {
                return metaClass.invokeMethod(receiver, name, args);
            } catch (MissingMethodException e) {
                if (e instanceof MissingMethodExecutionFailed) {
                    throw (MissingMethodException)e.getCause();
                } else if (receiver.getClass() == e.getType() && e.getMethod().equals(name)) {
                    // in case there's nothing else, invoke the object's own invokeMethod()
                    return ((GroovyObject)receiver).invokeMethod(name, args);
                } else {
                    throw e;
                }
            }
        } catch (GroovyRuntimeException gre) {
            throw ScriptBytecodeAdapter.unwrap(gre);
        }
    } else {
        return CallSiteArray.defaultCall(this, receiver, args);
    }
}
 
Example 2
Source File: InvokerHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
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;
        }
    }
}
 
Example 3
Source File: PogoMetaClassSite.java    From groovy with Apache License 2.0 5 votes vote down vote up
public final Object callCurrent(final GroovyObject receiver, final Object[] args) throws Throwable {
    if (checkCall(receiver)) {
        try {
            try {
                return metaClass.invokeMethod(array.owner, receiver, name, args, false, true);
            } catch (MissingMethodException e) {
                if (e instanceof MissingMethodExecutionFailed) {
                    throw (MissingMethodException) e.getCause();
                } else if (receiver.getClass() == e.getType() && e.getMethod().equals(name)) {
                    // in case there's nothing else, invoke the receiver's own invokeMethod()
                    try {
                        return receiver.invokeMethod(name, args);
                    } catch (MissingMethodException mme) {
                        if (mme instanceof MissingMethodExecutionFailed)
                            throw (MissingMethodException) mme.getCause();
                        // GROOVY-9387: in rare cases, this form still works
                        return metaClass.invokeMethod(receiver, name, args);
                    }
                } else {
                    throw e;
                }
            }
        } catch (GroovyRuntimeException gre) {
            throw ScriptBytecodeAdapter.unwrap(gre);
        }
    } else {
        return CallSiteArray.defaultCallCurrent(this, receiver, args);
    }
}
 
Example 4
Source File: ScriptBytecodeAdapter.java    From groovy with Apache License 2.0 5 votes vote down vote up
public static Object invokeMethodOnCurrentN(Class senderClass, GroovyObject receiver, String messageName, Object[] messageArguments) throws Throwable {
    Object result = null;
    boolean intercepting = receiver instanceof GroovyInterceptable;
    try {
        try {
            // if it's a pure interceptable object (even intercepting toString(), clone(), ...)
            if (intercepting) {
                result = receiver.invokeMethod(messageName, messageArguments);
            }
            //else if there's a statically typed method or a GDK method
            else {
                result = receiver.getMetaClass().invokeMethod(senderClass, receiver, messageName, messageArguments, false, true);
            }
        } catch (MissingMethodException e) {
            if (e instanceof MissingMethodExecutionFailed) {
                throw (MissingMethodException)e.getCause();
            } else if (!intercepting && receiver.getClass() == e.getType() && e.getMethod().equals(messageName)) {
                // in case there's nothing else, invoke the object's own invokeMethod()
                result = receiver.invokeMethod(messageName, messageArguments);
            } else {
                throw e;
            }
        }
    } catch (GroovyRuntimeException gre) {
        throw unwrap(gre);
    }
    return result;
}
 
Example 5
Source File: IndyGuardsFiltersAndSignatures.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * {@link GroovyObject#invokeMethod(String, Object)} path as fallback.
 * This method is called by the handle as exception handler in case the
 * selected method causes a MissingMethodExecutionFailed, where
 * we will just give through the exception, and a normal
 * MissingMethodException where we call {@link GroovyObject#invokeMethod(String, Object)}
 * if receiver class, the type transported by the exception and the name
 * for the method stored in the exception and our current method name
 * are equal.
 * Should those conditions not apply we just rethrow the exception.
 */
public static Object invokeGroovyObjectInvoker(MissingMethodException e, Object receiver, String name, Object[] args) {
    if (e instanceof MissingMethodExecutionFailed) {
        throw (MissingMethodException) e.getCause();
    } else if (receiver.getClass() == e.getType() && e.getMethod().equals(name)) {
        //TODO: we should consider calling this one directly for MetaClassImpl,
        //      then we save the new method selection

        // in case there's nothing else, invoke the object's own invokeMethod()
        return ((GroovyObject) receiver).invokeMethod(name, args);
    } else {
        throw e;
    }
}