Java Code Examples for org.codehaus.groovy.runtime.MetaClassHelper#unwrap()
The following examples show how to use
org.codehaus.groovy.runtime.MetaClassHelper#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: MetaClassImpl.java From groovy with Apache License 2.0 | 6 votes |
private CachedConstructor createCachedConstructor(Object[] arguments) { if (arguments == null) arguments = EMPTY_ARGUMENTS; Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments); MetaClassHelper.unwrap(arguments); CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses); if (constructor == null) { constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses); } if (constructor == null) { throw new GroovyRuntimeException( "Could not find matching constructor for: " + theClass.getName() + "(" + InvokerHelper.toTypeString(arguments) + ")"); } return constructor; }
Example 2
Source File: MetaClassImpl.java From groovy with Apache License 2.0 | 6 votes |
/** * This is a helper method added in Groovy 2.1.0, which is used only by indy. * This method is for internal use only. * * @since Groovy 2.1.0 */ public MetaMethod retrieveConstructor(Object[] arguments) { checkInitalised(); if (arguments == null) arguments = EMPTY_ARGUMENTS; Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments); MetaClassHelper.unwrap(arguments); Object res = chooseMethod("<init>", constructors, argClasses); if (res instanceof MetaMethod) return (MetaMethod) res; CachedConstructor constructor = (CachedConstructor) res; if (constructor != null) return new MetaConstructor(constructor, false); if (arguments.length == 1 && arguments[0] instanceof Map) { res = chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY); } else if ( arguments.length == 2 && arguments[1] instanceof Map && theClass.getEnclosingClass() != null && theClass.getEnclosingClass().isAssignableFrom(argClasses[0])) { res = chooseMethod("<init>", constructors, new Class[]{argClasses[0]}); } if (res instanceof MetaMethod) return (MetaMethod) res; constructor = (CachedConstructor) res; if (constructor != null) return new MetaConstructor(constructor, true); return null; }
Example 3
Source File: MetaClassImpl.java From groovy with Apache License 2.0 | 6 votes |
private Object invokeConstructor(Class at, Object[] arguments) { checkInitalised(); if (arguments == null) arguments = EMPTY_ARGUMENTS; Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments); MetaClassHelper.unwrap(arguments); CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses); if (constructor != null) { return constructor.doConstructorInvoke(arguments); } if (arguments.length == 1) { Object firstArgument = arguments[0]; if (firstArgument instanceof Map) { constructor = (CachedConstructor) chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY); if (constructor != null) { Object bean = constructor.doConstructorInvoke(MetaClassHelper.EMPTY_ARRAY); setProperties(bean, ((Map) firstArgument)); return bean; } } } throw new GroovyRuntimeException( "Could not find matching constructor for: " + theClass.getName() + "(" + InvokerHelper.toTypeString(arguments) + ")"); }
Example 4
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 5
Source File: ConstructorMetaMethodSite.java From groovy with Apache License 2.0 | 5 votes |
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 6
Source File: StaticMetaMethodSite.java From groovy with Apache License 2.0 | 5 votes |
public Object invoke(Object receiver, Object[] args) throws Throwable { MetaClassHelper.unwrap(args); try { return metaMethod.doMethodInvoke(receiver, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } }
Example 7
Source File: PogoMetaMethodSite.java From groovy with Apache License 2.0 | 5 votes |
public Object invoke(Object receiver, Object[] args) throws Throwable { MetaClassHelper.unwrap(args); try { return metaMethod.doMethodInvoke(receiver, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } }
Example 8
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)) { MetaClassHelper.unwrap(args); try { return constructor.doConstructorInvoke(args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else return CallSiteArray.defaultCallConstructor(this, receiver, args); }
Example 9
Source File: MetaClassImpl.java From groovy with Apache License 2.0 | 5 votes |
private MetaMethod getMetaMethod(Class sender, Object object, String methodName, boolean isCallToSuper, Object... arguments) { MetaMethod method = null; if (CLOSURE_CALL_METHOD.equals(methodName) && object instanceof GeneratedClosure) { method = getMethodWithCaching(sender, "doCall", arguments, isCallToSuper); } if (method == null) { method = getMethodWithCaching(sender, methodName, arguments, isCallToSuper); } MetaClassHelper.unwrap(arguments); if (method == null) method = tryListParamMetaMethod(sender, methodName, isCallToSuper, arguments); return method; }
Example 10
Source File: ExpandoMetaClass.java From groovy with Apache License 2.0 | 5 votes |
/** * Overrides default implementation just in case invokeMethod has been overridden by ExpandoMetaClass * * @see groovy.lang.MetaClassImpl#invokeMethod(Class, Object, String, Object[], boolean, boolean) */ public Object invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass) { if (invokeMethodMethod != null) { MetaClassHelper.unwrap(originalArguments); return invokeMethodMethod.invoke(object, new Object[]{methodName, originalArguments}); } return super.invokeMethod(sender, object, methodName, originalArguments, isCallToSuper, fromInsideClass); }
Example 11
Source File: ExpandoMetaClass.java From groovy with Apache License 2.0 | 5 votes |
/** * Overrides default implementation just in case a static invoke method has been set on ExpandoMetaClass * * @see MetaClassImpl#invokeStaticMethod(Object, String, Object[]) */ public Object invokeStaticMethod(Object object, String methodName, Object[] arguments) { if (invokeStaticMethodMethod != null) { MetaClassHelper.unwrap(arguments); return invokeStaticMethodMethod.invoke(object, new Object[]{methodName, arguments}); } return super.invokeStaticMethod(object, methodName, arguments); }
Example 12
Source File: PojoMetaMethodSite.java From groovy with Apache License 2.0 | 4 votes |
public Object invoke(Object receiver, Object[] args) throws Throwable { MetaClassHelper.unwrap(args); return metaMethod.doMethodInvoke(receiver, args); }
Example 13
Source File: PojoMetaMethodSite.java From groovy with Apache License 2.0 | 4 votes |
public Object invoke(Object receiver, Object[] args) throws Throwable { MetaClassHelper.unwrap(args); args = metaMethod.coerceArgumentsToClasses(args); return doInvoke(receiver, args, reflect); }
Example 14
Source File: PogoMetaMethodSite.java From groovy with Apache License 2.0 | 4 votes |
public Object invoke(Object receiver, Object[] args) throws Throwable { MetaClassHelper.unwrap(args); args = metaMethod.coerceArgumentsToClasses(args); return doInvoke(receiver, args, reflect); }