public CachedConstructor[] initValue() { final Constructor[] declaredConstructors = (Constructor[]) AccessController.doPrivileged(new PrivilegedAction/*<Constructor[]>*/() { public /*Constructor[]*/ Object run() { return getTheClass().getDeclaredConstructors(); } }); CachedConstructor [] constructors = new CachedConstructor[declaredConstructors.length]; for (int i = 0; i != constructors.length; ++i) constructors[i] = new CachedConstructor(CachedClass.this, declaredConstructors[i]); return constructors; } };
public Object doConstructorInvoke(Object[] argumentArray) { argumentArray = coerceArgumentsToClasses(argumentArray); return invoke(argumentArray); }
public int compare(Object arg0, Object arg1) { CachedConstructor c0 = (CachedConstructor) arg0; CachedConstructor c1 = (CachedConstructor) arg1; String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes()); String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes()); return descriptor0.compareTo(descriptor1); } };
private MetaConstructor(CachedConstructor cc, boolean bean) { super(cc.getNativeParameterTypes()); this.setParametersTypes(cc.getParameterTypes()); this.cc = cc; this.beanConstructor = bean; } @Override
private static CachedConstructor findDefaultConstructor(CachedClass mixinClass) { for (CachedConstructor constr : mixinClass.getConstructors()) { if (!Modifier.isPublic(constr.getModifiers())) continue; CachedClass[] classes = constr.getParameterTypes(); if (classes.length == 0) return constr; } throw new GroovyRuntimeException("No default constructor for class " + mixinClass.getName() + "! Can't be mixed in."); }
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); } }
@Override public Object invoke(Object object, Object[] arguments) { return cc.doConstructorInvoke(arguments); } public CachedConstructor getCachedConstrcutor() { return cc; }
public static ConstructorSite createConstructorSite(CallSite site, MetaClassImpl metaClass, CachedConstructor constructor, Class[] params, Object[] args) { if (constructor.correctArguments(args) == args) { if (noWrappers(args)) { if (noCoerce(constructor, args)) return new ConstructorSiteNoUnwrap(site, metaClass, constructor, params); else return new ConstructorSiteNoUnwrapNoCoerce(site, metaClass, constructor, params); } } return new ConstructorSite(site, metaClass, constructor, params); }
@Override public int getModifiers() { return cc.getModifiers(); } @Override
public Object invoke(Object[] argumentArray) { Constructor constr = cachedConstructor; try { return constr.newInstance(argumentArray); } catch (InvocationTargetException e) { throw new InvokerInvocationException(e); } catch (IllegalArgumentException e) { throw createExceptionText("failed to invoke constructor: ", constr, argumentArray, e, false); } catch (IllegalAccessException e) { throw createExceptionText("could not access constructor: ", constr, argumentArray, e, false); } catch (Exception e) { throw createExceptionText("failed to invoke constructor: ", constr, argumentArray, e, true); } }
public static Object doConstructorInvoke(CachedConstructor constructor, Object[] argumentArray) { final Constructor constr = constructor.cachedConstructor; argumentArray = constructor.coerceArgumentsToClasses(argumentArray); try { return constr.newInstance(argumentArray); } catch (InvocationTargetException e) { throw new InvokerInvocationException(e); } catch (IllegalArgumentException e) { throw createExceptionText("failed to invoke constructor: ", constr, argumentArray, e, false); } catch (IllegalAccessException e) { throw createExceptionText("could not access constructor: ", constr, argumentArray, e, false); } catch (Exception e) { throw createExceptionText("failed to invoke constructor: ", constr, argumentArray, e, true); } }
private CachedConstructor findDefaultConstructor(CachedClass mixinClass) { for (CachedConstructor constr : mixinClass.getConstructors()) { if (!Modifier.isPublic(constr.getModifiers())) continue; CachedClass[] classes = constr.getParameterTypes(); if (classes.length == 0) return constr; } throw new GroovyRuntimeException("No default constructor for class " + mixinClass.getName() + "! Can't be mixed in."); }
public synchronized Object getMixinInstance(Object object) { Object mixinInstance = get(object); if (mixinInstance == null) { mixinInstance = constructor.invoke(MetaClassHelper.EMPTY_ARRAY); new MixedInMetaClass(mixinInstance, object); put(object, mixinInstance); } return mixinInstance; }
public final Object callConstructor(Object receiver, Object[] args) throws Throwable { if (checkCall(receiver, args)) { try { return constructor.doConstructorInvoke(args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } else return CallSiteArray.defaultCallConstructor(this, receiver, args); } }
public static ConstructorSite createConstructorSite(CallSite site, MetaClassImpl metaClass, CachedConstructor constructor, Class[] params, Object[] args) { if (constructor.correctArguments(args) == args) { if (noWrappers(args)) { if (noCoerce(constructor,args)) return new ConstructorSiteNoUnwrap(site, metaClass, constructor, params); else return new ConstructorSiteNoUnwrapNoCoerce(site, metaClass, constructor, params); } } return new ConstructorSite(site, metaClass, constructor, params); }
public Object invoke(Object[] argumentArray) { Constructor constr = cachedConstructor; try { return constr.newInstance(argumentArray); } catch (InvocationTargetException e) { throw new InvokerInvocationException(e); } catch (IllegalArgumentException e) { throw createExceptionText("failed to invoke constructor: ", constr, argumentArray, e, false); } catch (IllegalAccessException e) { throw createExceptionText("could not access constructor: ", constr, argumentArray, e, false); } catch (Exception e) { throw createExceptionText("failed to invoke constructor: ", constr, argumentArray, e, true); } }
public Object doConstructorInvoke(Object[] argumentArray) { argumentArray = coerceArgumentsToClasses(argumentArray); return invoke(argumentArray); }
private void appendMethods(StringBuilder buffer) { for (int i = 0; i < methods.size; i++) { buffer.append("\n "); Object methodOrConstructor = methods.get(i); if (methodOrConstructor instanceof MetaMethod) { MetaMethod method = (MetaMethod) methodOrConstructor; buffer.append(Modifier.toString(method.getModifiers())); buffer.append(" ").append(method.getReturnType().getName()); buffer.append(" ").append(method.getDeclaringClass().getName()); buffer.append("#"); buffer.append(method.getName()); appendClassNames(buffer,method.getNativeParameterTypes()); } else { CachedConstructor method = (CachedConstructor) methodOrConstructor; buffer.append(Modifier.toString(method.cachedConstructor.getModifiers())); buffer.append(" ").append(method.cachedConstructor.getDeclaringClass().getName()); buffer.append("#<init>"); appendClassNames(buffer,method.getNativeParameterTypes()); } } } }
private CachedConstructor findDefaultConstructor(CachedClass mixinClass) { for(CachedConstructor constr : mixinClass.getConstructors()) { if (!Modifier.isPublic(constr.getModifiers())) continue; CachedClass[] classes = constr.getParameterTypes(); if (classes.length == 0) return constr; } throw new GroovyRuntimeException("No default constructor for class " + mixinClass.getName() + "! Can't be mixed in."); }
public final Object callConstructor(Object receiver, Object[] args) throws Throwable { if (checkCall(receiver, args)) { final Object[] newArgs = new Object[] {args[0]}; final Object bean = constructor.invoke(newArgs); try { ((MetaClassImpl) metaClass).setProperties(bean, (Map) args[1]); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } return bean; } else return CallSiteArray.defaultCallConstructor(this, receiver, args); } }