JavaProxyClass realProxyClass = (JavaProxyClass)proxyClass;
RubyArray constructors = realProxyClass.constructors();
ArrayList<JavaProxyConstructor> forArity = new ArrayList<JavaProxyConstructor>();
for (int i = 0; i < constructors.size(); i++) {
JavaProxyConstructor constructor = (JavaProxyConstructor)constructors.eltInternal(i);
if (constructor.getParameterTypes().length == args.length) {
forArity.add(constructor);
}
}
if (forArity.size() == 0) {
throw context.getRuntime().newArgumentError("wrong number of arguments for constructor");
}
JavaProxyConstructor matching = (JavaProxyConstructor)CallableSelector.matchingCallableArityN(
methodCache,
forArity.toArray(new JavaProxyConstructor[forArity.size()]), args, args.length);
if (matching == null) {
throw context.getRuntime().newArgumentError("wrong number of arguments for constructor");
}
Object[] newArgs = new Object[args.length];
Class[] parameterTypes = matching.getParameterTypes();
for (int i = 0; i < args.length; i++) {
newArgs[i] = args[i].toJava(parameterTypes[i]);
}
JavaObject newObject = matching.newInstance(self, newArgs);
return JavaUtilities.set_java_object(self, self, newObject);
}
});
return runtime.getNil();