1.1 --- a/rt/emul/mini/src/main/java/java/lang/Class.java Sat Sep 28 01:32:59 2013 +0200
1.2 +++ b/rt/emul/mini/src/main/java/java/lang/Class.java Sat Sep 28 12:03:59 2013 +0200
1.3 @@ -29,6 +29,7 @@
1.4 import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
1.5 import java.io.InputStream;
1.6 import java.lang.annotation.Annotation;
1.7 +import java.lang.reflect.Constructor;
1.8 import java.lang.reflect.Field;
1.9 import java.lang.reflect.Method;
1.10 import java.lang.reflect.TypeVariable;
1.11 @@ -1106,6 +1107,188 @@
1.12 }
1.13
1.14 /**
1.15 + * Returns an array containing {@code Constructor} objects reflecting
1.16 + * all the public constructors of the class represented by this
1.17 + * {@code Class} object. An array of length 0 is returned if the
1.18 + * class has no public constructors, or if the class is an array class, or
1.19 + * if the class reflects a primitive type or void.
1.20 + *
1.21 + * Note that while this method returns an array of {@code
1.22 + * Constructor<T>} objects (that is an array of constructors from
1.23 + * this class), the return type of this method is {@code
1.24 + * Constructor<?>[]} and <em>not</em> {@code Constructor<T>[]} as
1.25 + * might be expected. This less informative return type is
1.26 + * necessary since after being returned from this method, the
1.27 + * array could be modified to hold {@code Constructor} objects for
1.28 + * different classes, which would violate the type guarantees of
1.29 + * {@code Constructor<T>[]}.
1.30 + *
1.31 + * @return the array of {@code Constructor} objects representing the
1.32 + * public constructors of this class
1.33 + * @exception SecurityException
1.34 + * If a security manager, <i>s</i>, is present and any of the
1.35 + * following conditions is met:
1.36 + *
1.37 + * <ul>
1.38 + *
1.39 + * <li> invocation of
1.40 + * {@link SecurityManager#checkMemberAccess
1.41 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
1.42 + * access to the constructors within this class
1.43 + *
1.44 + * <li> the caller's class loader is not the same as or an
1.45 + * ancestor of the class loader for the current class and
1.46 + * invocation of {@link SecurityManager#checkPackageAccess
1.47 + * s.checkPackageAccess()} denies access to the package
1.48 + * of this class
1.49 + *
1.50 + * </ul>
1.51 + *
1.52 + * @since JDK1.1
1.53 + */
1.54 + public Constructor<?>[] getConstructors() throws SecurityException {
1.55 + return MethodImpl.findConstructors(this, 0x01);
1.56 + }
1.57 +
1.58 + /**
1.59 + * Returns a {@code Constructor} object that reflects the specified
1.60 + * public constructor of the class represented by this {@code Class}
1.61 + * object. The {@code parameterTypes} parameter is an array of
1.62 + * {@code Class} objects that identify the constructor's formal
1.63 + * parameter types, in declared order.
1.64 + *
1.65 + * If this {@code Class} object represents an inner class
1.66 + * declared in a non-static context, the formal parameter types
1.67 + * include the explicit enclosing instance as the first parameter.
1.68 + *
1.69 + * <p> The constructor to reflect is the public constructor of the class
1.70 + * represented by this {@code Class} object whose formal parameter
1.71 + * types match those specified by {@code parameterTypes}.
1.72 + *
1.73 + * @param parameterTypes the parameter array
1.74 + * @return the {@code Constructor} object of the public constructor that
1.75 + * matches the specified {@code parameterTypes}
1.76 + * @exception NoSuchMethodException if a matching method is not found.
1.77 + * @exception SecurityException
1.78 + * If a security manager, <i>s</i>, is present and any of the
1.79 + * following conditions is met:
1.80 + *
1.81 + * <ul>
1.82 + *
1.83 + * <li> invocation of
1.84 + * {@link SecurityManager#checkMemberAccess
1.85 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
1.86 + * access to the constructor
1.87 + *
1.88 + * <li> the caller's class loader is not the same as or an
1.89 + * ancestor of the class loader for the current class and
1.90 + * invocation of {@link SecurityManager#checkPackageAccess
1.91 + * s.checkPackageAccess()} denies access to the package
1.92 + * of this class
1.93 + *
1.94 + * </ul>
1.95 + *
1.96 + * @since JDK1.1
1.97 + */
1.98 + public Constructor<T> getConstructor(Class<?>... parameterTypes)
1.99 + throws NoSuchMethodException, SecurityException {
1.100 + Constructor c = MethodImpl.findConstructor(this, parameterTypes);
1.101 + if (c == null) {
1.102 + StringBuilder sb = new StringBuilder();
1.103 + sb.append(getName()).append('(');
1.104 + String sep = "";
1.105 + for (int i = 0; i < parameterTypes.length; i++) {
1.106 + sb.append(sep).append(parameterTypes[i].getName());
1.107 + sep = ", ";
1.108 + }
1.109 + sb.append(')');
1.110 + throw new NoSuchMethodException(sb.toString());
1.111 + }
1.112 + return c;
1.113 + }
1.114 +
1.115 + /**
1.116 + * Returns an array of {@code Constructor} objects reflecting all the
1.117 + * constructors declared by the class represented by this
1.118 + * {@code Class} object. These are public, protected, default
1.119 + * (package) access, and private constructors. The elements in the array
1.120 + * returned are not sorted and are not in any particular order. If the
1.121 + * class has a default constructor, it is included in the returned array.
1.122 + * This method returns an array of length 0 if this {@code Class}
1.123 + * object represents an interface, a primitive type, an array class, or
1.124 + * void.
1.125 + *
1.126 + * <p> See <em>The Java Language Specification</em>, section 8.2.
1.127 + *
1.128 + * @return the array of {@code Constructor} objects representing all the
1.129 + * declared constructors of this class
1.130 + * @exception SecurityException
1.131 + * If a security manager, <i>s</i>, is present and any of the
1.132 + * following conditions is met:
1.133 + *
1.134 + * <ul>
1.135 + *
1.136 + * <li> invocation of
1.137 + * {@link SecurityManager#checkMemberAccess
1.138 + * s.checkMemberAccess(this, Member.DECLARED)} denies
1.139 + * access to the declared constructors within this class
1.140 + *
1.141 + * <li> the caller's class loader is not the same as or an
1.142 + * ancestor of the class loader for the current class and
1.143 + * invocation of {@link SecurityManager#checkPackageAccess
1.144 + * s.checkPackageAccess()} denies access to the package
1.145 + * of this class
1.146 + *
1.147 + * </ul>
1.148 + *
1.149 + * @since JDK1.1
1.150 + */
1.151 + public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
1.152 + throw new SecurityException();
1.153 + }
1.154 + /**
1.155 + * Returns a {@code Constructor} object that reflects the specified
1.156 + * constructor of the class or interface represented by this
1.157 + * {@code Class} object. The {@code parameterTypes} parameter is
1.158 + * an array of {@code Class} objects that identify the constructor's
1.159 + * formal parameter types, in declared order.
1.160 + *
1.161 + * If this {@code Class} object represents an inner class
1.162 + * declared in a non-static context, the formal parameter types
1.163 + * include the explicit enclosing instance as the first parameter.
1.164 + *
1.165 + * @param parameterTypes the parameter array
1.166 + * @return The {@code Constructor} object for the constructor with the
1.167 + * specified parameter list
1.168 + * @exception NoSuchMethodException if a matching method is not found.
1.169 + * @exception SecurityException
1.170 + * If a security manager, <i>s</i>, is present and any of the
1.171 + * following conditions is met:
1.172 + *
1.173 + * <ul>
1.174 + *
1.175 + * <li> invocation of
1.176 + * {@link SecurityManager#checkMemberAccess
1.177 + * s.checkMemberAccess(this, Member.DECLARED)} denies
1.178 + * access to the declared constructor
1.179 + *
1.180 + * <li> the caller's class loader is not the same as or an
1.181 + * ancestor of the class loader for the current class and
1.182 + * invocation of {@link SecurityManager#checkPackageAccess
1.183 + * s.checkPackageAccess()} denies access to the package
1.184 + * of this class
1.185 + *
1.186 + * </ul>
1.187 + *
1.188 + * @since JDK1.1
1.189 + */
1.190 + public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
1.191 + throws NoSuchMethodException, SecurityException {
1.192 + return getConstructor(parameterTypes);
1.193 + }
1.194 +
1.195 +
1.196 + /**
1.197 * Character.isDigit answers {@code true} to some non-ascii
1.198 * digits. This one does not.
1.199 */