@@ -43,20 +43,67 @@ public Constructor(Class<T> declaringClass, Class<?>[] parameterTypes, Class<?>[
4343 this .parameterTypes = parameterTypes ;
4444 this .exceptionTypes = checkedExceptions ;
4545 this .modifiers = modifiers ;
46- this .signature = "c$" ;
4746 // all of the SwingJS primitive classes run without parameterization
4847 if (";Integer;Long;Short;Byte;Float;Double;" .indexOf (";" + declaringClass .getName () + ";" ) >= 0 )
4948 parameterTypes = null ;
5049 this .parameterTypes = parameterTypes ;
51- if (parameterTypes != null ) {
52- for (int i = 0 ; i < parameterTypes .length ; i ++) {
53- String code = /** j2sNative Clazz._getParamCode(parameterTypes[i]) || */
54- null ;
55- this .signature += "$" + code ;
56- }
50+ this .signature = "c$" + Class .argumentTypesToString (parameterTypes );
51+ constr = /** @j2sNative this.Class_.$clazz$[this.signature] || */ null ;
52+ }
53+
54+ /**
55+ * Return a new instance of the declaring class, initialized by dynamically
56+ * invoking the modelled constructor. This reproduces the effect of
57+ * <code>new declaringClass(arg1, arg2, ... , argN)</code> This method performs
58+ * the following:
59+ * <ul>
60+ * <li>A new instance of the declaring class is created. If the declaring class
61+ * cannot be instantiated (i.e. abstract class, an interface, an array type, or
62+ * a base type) then an InstantiationException is thrown.</li>
63+ * <li>If this Constructor object is enforcing access control (see
64+ * AccessibleObject) and the modelled constructor is not accessible from the
65+ * current context, an IllegalAccessException is thrown.</li>
66+ * <li>If the number of arguments passed and the number of parameters do not
67+ * match, an IllegalArgumentException is thrown.</li>
68+ * <li>For each argument passed:
69+ * <ul>
70+ * <li>If the corresponding parameter type is a base type, the argument is
71+ * unwrapped. If the unwrapping fails, an IllegalArgumentException is
72+ * thrown.</li>
73+ * <li>If the resulting argument cannot be converted to the parameter type via a
74+ * widening conversion, an IllegalArgumentException is thrown.</li>
75+ * </ul>
76+ * <li>The modelled constructor is then invoked. If an exception is thrown
77+ * during the invocation, it is caught and wrapped in an
78+ * InvocationTargetException. This exception is then thrown. If the invocation
79+ * completes normally, the newly initialized object is returned.
80+ * </ul>
81+ *
82+ * @param args the arguments to the constructor
83+ * @return the new, initialized, object
84+ * @exception java.lang.InstantiationException if the class cannot be
85+ * instantiated
86+ * @exception java.lang.IllegalAccessException if the modelled constructor is
87+ * not accessible
88+ * @exception java.lang.IllegalArgumentException if an incorrect number of
89+ * arguments are passed, or an argument could not be converted by a
90+ * widening conversion
91+ * @exception java.lang.reflect.InvocationTargetException if an exception was
92+ * thrown by the invoked constructor
93+ * @see java.lang.reflect.AccessibleObject
94+ *
95+ */
96+ @ SuppressWarnings ("unused" )
97+ public T newInstance (Object ... args )
98+ throws InstantiationException , IllegalAccessException , IllegalArgumentException , InvocationTargetException {
99+ if (this .constr != null ) {
100+ Object [] a = Class .getArgumentArray (parameterTypes , args , false );
101+ T instance = /** @j2sNative Clazz.new_(this.constr, a) || */ null ;
102+ if (instance != null )
103+ return instance ;
57104 }
58- constr = /** @j2sNative this.Class_.$clazz$[this. signature] || */
59- null ;
105+ String message = "Constructor " + getDeclaringClass (). getName () + "." + signature + " was not found" ;
106+ throw new IllegalArgumentException ( message ) ;
60107 }
61108
62109 public TypeVariable <Constructor <T >>[] getTypeParameters () {
@@ -243,72 +290,6 @@ public int hashCode() {
243290 return getDeclaringClass ().getName ().hashCode ();
244291 }
245292
246- /**
247- * Return a new instance of the declaring class, initialized by dynamically
248- * invoking the modelled constructor. This reproduces the effect of
249- * <code>new declaringClass(arg1, arg2, ... , argN)</code> This method performs
250- * the following:
251- * <ul>
252- * <li>A new instance of the declaring class is created. If the declaring class
253- * cannot be instantiated (i.e. abstract class, an interface, an array type, or
254- * a base type) then an InstantiationException is thrown.</li>
255- * <li>If this Constructor object is enforcing access control (see
256- * AccessibleObject) and the modelled constructor is not accessible from the
257- * current context, an IllegalAccessException is thrown.</li>
258- * <li>If the number of arguments passed and the number of parameters do not
259- * match, an IllegalArgumentException is thrown.</li>
260- * <li>For each argument passed:
261- * <ul>
262- * <li>If the corresponding parameter type is a base type, the argument is
263- * unwrapped. If the unwrapping fails, an IllegalArgumentException is
264- * thrown.</li>
265- * <li>If the resulting argument cannot be converted to the parameter type via a
266- * widening conversion, an IllegalArgumentException is thrown.</li>
267- * </ul>
268- * <li>The modelled constructor is then invoked. If an exception is thrown
269- * during the invocation, it is caught and wrapped in an
270- * InvocationTargetException. This exception is then thrown. If the invocation
271- * completes normally, the newly initialized object is returned.
272- * </ul>
273- *
274- * @param args the arguments to the constructor
275- * @return the new, initialized, object
276- * @exception java.lang.InstantiationException if the class cannot be
277- * instantiated
278- * @exception java.lang.IllegalAccessException if the modelled constructor is
279- * not accessible
280- * @exception java.lang.IllegalArgumentException if an incorrect number of
281- * arguments are passed, or an argument could not be converted by a
282- * widening conversion
283- * @exception java.lang.reflect.InvocationTargetException if an exception was
284- * thrown by the invoked constructor
285- * @see java.lang.reflect.AccessibleObject
286- *
287- */
288- public T newInstance (Object ... args )
289- throws InstantiationException , IllegalAccessException , IllegalArgumentException , InvocationTargetException {
290- /**
291- * @j2sNative
292- *
293- * var instance = null;
294- * if (this.constr) {
295- * var a = (args ? new Array(args.length) : []);
296- * if (args) {
297- * for (var i = args.length; --i >= 0;) {
298- * a[i] = (this.parameterTypes[i].__PRIMITIVE ? args[i].valueOf() : args[i]);
299- * }
300- * }
301- * var instance = Clazz.new_(this.constr, a);
302- * }
303- * if (instance == null)
304- * newMethodNotFoundException(this.Class_.$clazz$, this.signature);
305- * return instance;
306- */
307- {
308- return null ;
309- }
310- }
311-
312293 /**
313294 * Answers a string containing a concise, human-readable description of the
314295 * receiver. The format of the string is modifiers (if any) declaring class name
0 commit comments