Java Code Examples for org.codehaus.groovy.runtime.ScriptBytecodeAdapter#unwrap()
The following examples show how to use
org.codehaus.groovy.runtime.ScriptBytecodeAdapter#unwrap() .
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: GroovyAssert.java From groovy with Apache License 2.0 | 6 votes |
/** * Asserts that the given code closure fails when it is evaluated * and that a particular type of exception is thrown. * * @param clazz the class of the expected exception * @param code the closure that should fail * @return the caught exception */ public static Throwable shouldFail(Class clazz, Closure code) { Throwable th = null; try { code.call(); } catch (GroovyRuntimeException gre) { th = ScriptBytecodeAdapter.unwrap(gre); } catch (Throwable e) { th = e; } if (th == null) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName()); } else if (!clazz.isInstance(th)) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName() + ", instead got Exception " + th); } return th; }
Example 2
Source File: GroovyAssert.java From groovy with Apache License 2.0 | 6 votes |
/** * Asserts that the given script fails when it is evaluated * and that a particular type of exception is thrown. * * @param clazz the class of the expected exception * @param script the script that should fail * @return the caught exception */ public static Throwable shouldFail(Class clazz, String script) { Throwable th = null; try { GroovyShell shell = new GroovyShell(); shell.evaluate(script, genericScriptName()); } catch (GroovyRuntimeException gre) { th = ScriptBytecodeAdapter.unwrap(gre); } catch (Throwable e) { th = e; } if (th == null) { fail("Script should have failed with an exception of type " + clazz.getName()); } else if (!clazz.isInstance(th)) { fail("Script should have failed with an exception of type " + clazz.getName() + ", instead got Exception " + th); } return th; }
Example 3
Source File: GroovyAssert.java From groovy with Apache License 2.0 | 6 votes |
/** * Asserts that the given script fails when it is evaluated * * @param script the script expected to fail * @return the caught exception */ public static Throwable shouldFail(String script) { boolean failed = false; Throwable th = null; try { GroovyShell shell = new GroovyShell(); shell.evaluate(script, genericScriptName()); } catch (GroovyRuntimeException gre) { failed = true; th = ScriptBytecodeAdapter.unwrap(gre); } catch (Throwable e) { failed = true; th = e; } assertTrue("Script should have failed", failed); return th; }
Example 4
Source File: PogoMetaClassSite.java From groovy with Apache License 2.0 | 6 votes |
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 5
Source File: ConstructorMetaClassSite.java From groovy with Apache License 2.0 | 5 votes |
public Object callConstructor(Object receiver, Object[] args) throws Throwable { if (receiver == metaClass.getTheClass()) { try { return metaClass.invokeConstructor(args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else { return CallSiteArray.defaultCallConstructor(this, receiver, args); } }
Example 6
Source File: PogoMetaMethodSite.java From groovy with Apache License 2.0 | 5 votes |
public Object callCurrent(GroovyObject receiver, Object[] args) throws Throwable { if(checkCall(receiver, args)) { try { return invoke(receiver,args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else { return CallSiteArray.defaultCallCurrent(this, receiver, args); } }
Example 7
Source File: StaticMetaMethodSite.java From groovy with Apache License 2.0 | 5 votes |
public final Object invoke(Object receiver, Object[] args) throws Throwable { try { return metaMethod.doMethodInvoke(receiver, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } }
Example 8
Source File: PojoMetaMethodSite.java From groovy with Apache License 2.0 | 5 votes |
public final Object invoke(Object receiver, Object[] args) throws Throwable { try { return metaMethod.invoke(receiver, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } }
Example 9
Source File: NullCallSite.java From groovy with Apache License 2.0 | 5 votes |
public Object call(Object receiver, Object[] args) throws Throwable { if (receiver == null) { try{ return CallSiteArray.defaultCall(this, NullObject.getNullObject(), args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else { return CallSiteArray.defaultCall(this, receiver, args); } }
Example 10
Source File: NullCallSite.java From groovy with Apache License 2.0 | 5 votes |
public Object getProperty(Object receiver) throws Throwable { if (receiver == null) { try{ return InvokerHelper.getProperty(NullObject.getNullObject(), name); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else { return acceptGetProperty(receiver).getProperty(receiver); } }
Example 11
Source File: ConstructorMetaMethodSite.java From groovy with Apache License 2.0 | 5 votes |
public final Object invoke(Object receiver, Object [] args) throws Throwable{ MetaClassHelper.unwrap(args); try { return metaMethod.doMethodInvoke(metaClass.getTheClass(), args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } }
Example 12
Source File: StaticMetaClassSite.java From groovy with Apache License 2.0 | 5 votes |
public final Object call(Object receiver, Object[] args) throws Throwable { if (checkCall(receiver)) { try { return metaClass.invokeStaticMethod(receiver, name, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else { return CallSiteArray.defaultCall(this, receiver, args); } }
Example 13
Source File: PerInstancePojoMetaClassSite.java From groovy with Apache License 2.0 | 5 votes |
public Object call(Object receiver, Object[] args) throws Throwable { if (receiver != null && info.hasPerInstanceMetaClasses()) { try { return InvokerHelper.getMetaClass(receiver).invokeMethod(receiver, name, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else { return CallSiteArray.defaultCall(this, receiver, args); } }
Example 14
Source File: PogoMetaClassSite.java From groovy with Apache License 2.0 | 5 votes |
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 15
Source File: ConstructorSite.java From groovy with Apache License 2.0 | 5 votes |
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 16
Source File: PogoMetaMethodSite.java From groovy with Apache License 2.0 | 5 votes |
public final Object invoke(Object receiver, Object[] args) throws Throwable { try { return metaMethod.doMethodInvoke(receiver, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } }
Example 17
Source File: PogoInterceptableSite.java From groovy with Apache License 2.0 | 5 votes |
public final Object call(Object receiver, Object[] args) throws Throwable { if(receiver instanceof GroovyObject) { try { return ((GroovyObject) receiver).invokeMethod(name, InvokerHelper.asUnwrappedArray(args)); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else { return CallSiteArray.defaultCall(this, receiver, args); } }
Example 18
Source File: ConstructorSite.java From groovy with Apache License 2.0 | 5 votes |
public Object callConstructor(Object receiver, Object[] args) throws Throwable { if (checkCall(receiver, args)) { try { return constructor.invoke(args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else return CallSiteArray.defaultCallConstructor(this, receiver, args); }
Example 19
Source File: ClassMetaClassGetPropertySite.java From groovy with Apache License 2.0 | 5 votes |
public final Object getProperty(Object receiver) throws Throwable{ try { return metaClass.getProperty(aClass, name); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } }
Example 20
Source File: IndyGuardsFiltersAndSignatures.java From groovy with Apache License 2.0 | 2 votes |
/** * Unwraps a {@link GroovyRuntimeException}. * This method is called by the handle to unwrap internal exceptions * of the runtime. */ public static Object unwrap(GroovyRuntimeException gre) throws Throwable { throw ScriptBytecodeAdapter.unwrap(gre); }