src/share/classes/java/beans/Statement.java

Print this page
rev 10203 : 8048874: Replace uses of 'new Byte', 'new Short' and 'new Character' with appropriate alternative across core classes
Reviewed-by: chegar, prappo
Contributed-by: Otavio Santana <otaviojava@java.net>


 231             */
 232             if (methodName.equals("new")) {
 233                 methodName = "newInstance";
 234             }
 235             // Provide a short form for array instantiation by faking an nary-constructor.
 236             if (methodName.equals("newInstance") && ((Class)target).isArray()) {
 237                 Object result = Array.newInstance(((Class)target).getComponentType(), arguments.length);
 238                 for(int i = 0; i < arguments.length; i++) {
 239                     Array.set(result, i, arguments[i]);
 240                 }
 241                 return result;
 242             }
 243             if (methodName.equals("newInstance") && arguments.length != 0) {
 244                 // The Character class, as of 1.4, does not have a constructor
 245                 // which takes a String. All of the other "wrapper" classes
 246                 // for Java's primitive types have a String constructor so we
 247                 // fake such a constructor here so that this special case can be
 248                 // ignored elsewhere.
 249                 if (target == Character.class && arguments.length == 1 &&
 250                     argClasses[0] == String.class) {
 251                     return new Character(((String)arguments[0]).charAt(0));
 252                 }
 253                 try {
 254                     m = ConstructorFinder.findConstructor((Class)target, argClasses);
 255                 }
 256                 catch (NoSuchMethodException exception) {
 257                     m = null;
 258                 }
 259             }
 260             if (m == null && target != Class.class) {
 261                 m = getMethod((Class)target, methodName, argClasses);
 262             }
 263             if (m == null) {
 264                 m = getMethod(Class.class, methodName, argClasses);
 265             }
 266         }
 267         else {
 268             /*
 269             This special casing of arrays is not necessary, but makes files
 270             involving arrays much shorter and simplifies the archiving infrastrcure.
 271             The Array.set() method introduces an unusual idea - that of a static method




 231             */
 232             if (methodName.equals("new")) {
 233                 methodName = "newInstance";
 234             }
 235             // Provide a short form for array instantiation by faking an nary-constructor.
 236             if (methodName.equals("newInstance") && ((Class)target).isArray()) {
 237                 Object result = Array.newInstance(((Class)target).getComponentType(), arguments.length);
 238                 for(int i = 0; i < arguments.length; i++) {
 239                     Array.set(result, i, arguments[i]);
 240                 }
 241                 return result;
 242             }
 243             if (methodName.equals("newInstance") && arguments.length != 0) {
 244                 // The Character class, as of 1.4, does not have a constructor
 245                 // which takes a String. All of the other "wrapper" classes
 246                 // for Java's primitive types have a String constructor so we
 247                 // fake such a constructor here so that this special case can be
 248                 // ignored elsewhere.
 249                 if (target == Character.class && arguments.length == 1 &&
 250                     argClasses[0] == String.class) {
 251                     return ((String)arguments[0]).charAt(0);
 252                 }
 253                 try {
 254                     m = ConstructorFinder.findConstructor((Class)target, argClasses);
 255                 }
 256                 catch (NoSuchMethodException exception) {
 257                     m = null;
 258                 }
 259             }
 260             if (m == null && target != Class.class) {
 261                 m = getMethod((Class)target, methodName, argClasses);
 262             }
 263             if (m == null) {
 264                 m = getMethod(Class.class, methodName, argClasses);
 265             }
 266         }
 267         else {
 268             /*
 269             This special casing of arrays is not necessary, but makes files
 270             involving arrays much shorter and simplifies the archiving infrastrcure.
 271             The Array.set() method introduces an unusual idea - that of a static method