1.1 --- a/rt/emul/mini/src/main/java/java/lang/Class.java Thu Oct 03 14:45:25 2013 +0200
1.2 +++ b/rt/emul/mini/src/main/java/java/lang/Class.java Thu Oct 03 15:51:55 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 @@ -975,6 +976,319 @@
1.12 }
1.13
1.14 /**
1.15 + * Returns an array of {@code Field} objects reflecting all the fields
1.16 + * declared by the class or interface represented by this
1.17 + * {@code Class} object. This includes public, protected, default
1.18 + * (package) access, and private fields, but excludes inherited fields.
1.19 + * The elements in the array returned are not sorted and are not in any
1.20 + * particular order. This method returns an array of length 0 if the class
1.21 + * or interface declares no fields, or if this {@code Class} object
1.22 + * represents a primitive type, an array class, or void.
1.23 + *
1.24 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
1.25 + *
1.26 + * @return the array of {@code Field} objects representing all the
1.27 + * declared fields of this class
1.28 + * @exception SecurityException
1.29 + * If a security manager, <i>s</i>, is present and any of the
1.30 + * following conditions is met:
1.31 + *
1.32 + * <ul>
1.33 + *
1.34 + * <li> invocation of
1.35 + * {@link SecurityManager#checkMemberAccess
1.36 + * s.checkMemberAccess(this, Member.DECLARED)} denies
1.37 + * access to the declared fields within this class
1.38 + *
1.39 + * <li> the caller's class loader is not the same as or an
1.40 + * ancestor of the class loader for the current class and
1.41 + * invocation of {@link SecurityManager#checkPackageAccess
1.42 + * s.checkPackageAccess()} denies access to the package
1.43 + * of this class
1.44 + *
1.45 + * </ul>
1.46 + *
1.47 + * @since JDK1.1
1.48 + */
1.49 + public Field[] getDeclaredFields() throws SecurityException {
1.50 + throw new SecurityException();
1.51 + }
1.52 +
1.53 + /**
1.54 + * <b>Bck2Brwsr</b> emulation can only seek public methods, otherwise it
1.55 + * throws a {@code SecurityException}.
1.56 + * <p>
1.57 + * Returns a {@code Method} object that reflects the specified
1.58 + * declared method of the class or interface represented by this
1.59 + * {@code Class} object. The {@code name} parameter is a
1.60 + * {@code String} that specifies the simple name of the desired
1.61 + * method, and the {@code parameterTypes} parameter is an array of
1.62 + * {@code Class} objects that identify the method's formal parameter
1.63 + * types, in declared order. If more than one method with the same
1.64 + * parameter types is declared in a class, and one of these methods has a
1.65 + * return type that is more specific than any of the others, that method is
1.66 + * returned; otherwise one of the methods is chosen arbitrarily. If the
1.67 + * name is "<init>"or "<clinit>" a {@code NoSuchMethodException}
1.68 + * is raised.
1.69 + *
1.70 + * @param name the name of the method
1.71 + * @param parameterTypes the parameter array
1.72 + * @return the {@code Method} object for the method of this class
1.73 + * matching the specified name and parameters
1.74 + * @exception NoSuchMethodException if a matching method is not found.
1.75 + * @exception NullPointerException if {@code name} is {@code null}
1.76 + * @exception SecurityException
1.77 + * If a security manager, <i>s</i>, is present and any of the
1.78 + * following conditions is met:
1.79 + *
1.80 + * <ul>
1.81 + *
1.82 + * <li> invocation of
1.83 + * {@link SecurityManager#checkMemberAccess
1.84 + * s.checkMemberAccess(this, Member.DECLARED)} denies
1.85 + * access to the declared method
1.86 + *
1.87 + * <li> the caller's class loader is not the same as or an
1.88 + * ancestor of the class loader for the current class and
1.89 + * invocation of {@link SecurityManager#checkPackageAccess
1.90 + * s.checkPackageAccess()} denies access to the package
1.91 + * of this class
1.92 + *
1.93 + * </ul>
1.94 + *
1.95 + * @since JDK1.1
1.96 + */
1.97 + public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
1.98 + throws NoSuchMethodException, SecurityException {
1.99 + try {
1.100 + return getMethod(name, parameterTypes);
1.101 + } catch (NoSuchMethodException ex) {
1.102 + throw new SecurityException();
1.103 + }
1.104 + }
1.105 +
1.106 + /**
1.107 + * Returns a {@code Field} object that reflects the specified declared
1.108 + * field of the class or interface represented by this {@code Class}
1.109 + * object. The {@code name} parameter is a {@code String} that
1.110 + * specifies the simple name of the desired field. Note that this method
1.111 + * will not reflect the {@code length} field of an array class.
1.112 + *
1.113 + * @param name the name of the field
1.114 + * @return the {@code Field} object for the specified field in this
1.115 + * class
1.116 + * @exception NoSuchFieldException if a field with the specified name is
1.117 + * not found.
1.118 + * @exception NullPointerException if {@code name} is {@code null}
1.119 + * @exception SecurityException
1.120 + * If a security manager, <i>s</i>, is present and any of the
1.121 + * following conditions is met:
1.122 + *
1.123 + * <ul>
1.124 + *
1.125 + * <li> invocation of
1.126 + * {@link SecurityManager#checkMemberAccess
1.127 + * s.checkMemberAccess(this, Member.DECLARED)} denies
1.128 + * access to the declared field
1.129 + *
1.130 + * <li> the caller's class loader is not the same as or an
1.131 + * ancestor of the class loader for the current class and
1.132 + * invocation of {@link SecurityManager#checkPackageAccess
1.133 + * s.checkPackageAccess()} denies access to the package
1.134 + * of this class
1.135 + *
1.136 + * </ul>
1.137 + *
1.138 + * @since JDK1.1
1.139 + */
1.140 + public Field getDeclaredField(String name)
1.141 + throws SecurityException {
1.142 + throw new SecurityException();
1.143 + }
1.144 +
1.145 + /**
1.146 + * Returns an array containing {@code Constructor} objects reflecting
1.147 + * all the public constructors of the class represented by this
1.148 + * {@code Class} object. An array of length 0 is returned if the
1.149 + * class has no public constructors, or if the class is an array class, or
1.150 + * if the class reflects a primitive type or void.
1.151 + *
1.152 + * Note that while this method returns an array of {@code
1.153 + * Constructor<T>} objects (that is an array of constructors from
1.154 + * this class), the return type of this method is {@code
1.155 + * Constructor<?>[]} and <em>not</em> {@code Constructor<T>[]} as
1.156 + * might be expected. This less informative return type is
1.157 + * necessary since after being returned from this method, the
1.158 + * array could be modified to hold {@code Constructor} objects for
1.159 + * different classes, which would violate the type guarantees of
1.160 + * {@code Constructor<T>[]}.
1.161 + *
1.162 + * @return the array of {@code Constructor} objects representing the
1.163 + * public constructors of this class
1.164 + * @exception SecurityException
1.165 + * If a security manager, <i>s</i>, is present and any of the
1.166 + * following conditions is met:
1.167 + *
1.168 + * <ul>
1.169 + *
1.170 + * <li> invocation of
1.171 + * {@link SecurityManager#checkMemberAccess
1.172 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
1.173 + * access to the constructors within this class
1.174 + *
1.175 + * <li> the caller's class loader is not the same as or an
1.176 + * ancestor of the class loader for the current class and
1.177 + * invocation of {@link SecurityManager#checkPackageAccess
1.178 + * s.checkPackageAccess()} denies access to the package
1.179 + * of this class
1.180 + *
1.181 + * </ul>
1.182 + *
1.183 + * @since JDK1.1
1.184 + */
1.185 + public Constructor<?>[] getConstructors() throws SecurityException {
1.186 + return MethodImpl.findConstructors(this, 0x01);
1.187 + }
1.188 +
1.189 + /**
1.190 + * Returns a {@code Constructor} object that reflects the specified
1.191 + * public constructor of the class represented by this {@code Class}
1.192 + * object. The {@code parameterTypes} parameter is an array of
1.193 + * {@code Class} objects that identify the constructor's formal
1.194 + * parameter types, in declared order.
1.195 + *
1.196 + * If this {@code Class} object represents an inner class
1.197 + * declared in a non-static context, the formal parameter types
1.198 + * include the explicit enclosing instance as the first parameter.
1.199 + *
1.200 + * <p> The constructor to reflect is the public constructor of the class
1.201 + * represented by this {@code Class} object whose formal parameter
1.202 + * types match those specified by {@code parameterTypes}.
1.203 + *
1.204 + * @param parameterTypes the parameter array
1.205 + * @return the {@code Constructor} object of the public constructor that
1.206 + * matches the specified {@code parameterTypes}
1.207 + * @exception NoSuchMethodException if a matching method is not found.
1.208 + * @exception SecurityException
1.209 + * If a security manager, <i>s</i>, is present and any of the
1.210 + * following conditions is met:
1.211 + *
1.212 + * <ul>
1.213 + *
1.214 + * <li> invocation of
1.215 + * {@link SecurityManager#checkMemberAccess
1.216 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
1.217 + * access to the constructor
1.218 + *
1.219 + * <li> the caller's class loader is not the same as or an
1.220 + * ancestor of the class loader for the current class and
1.221 + * invocation of {@link SecurityManager#checkPackageAccess
1.222 + * s.checkPackageAccess()} denies access to the package
1.223 + * of this class
1.224 + *
1.225 + * </ul>
1.226 + *
1.227 + * @since JDK1.1
1.228 + */
1.229 + public Constructor<T> getConstructor(Class<?>... parameterTypes)
1.230 + throws NoSuchMethodException, SecurityException {
1.231 + Constructor c = MethodImpl.findConstructor(this, parameterTypes);
1.232 + if (c == null) {
1.233 + StringBuilder sb = new StringBuilder();
1.234 + sb.append(getName()).append('(');
1.235 + String sep = "";
1.236 + for (int i = 0; i < parameterTypes.length; i++) {
1.237 + sb.append(sep).append(parameterTypes[i].getName());
1.238 + sep = ", ";
1.239 + }
1.240 + sb.append(')');
1.241 + throw new NoSuchMethodException(sb.toString());
1.242 + }
1.243 + return c;
1.244 + }
1.245 +
1.246 + /**
1.247 + * Returns an array of {@code Constructor} objects reflecting all the
1.248 + * constructors declared by the class represented by this
1.249 + * {@code Class} object. These are public, protected, default
1.250 + * (package) access, and private constructors. The elements in the array
1.251 + * returned are not sorted and are not in any particular order. If the
1.252 + * class has a default constructor, it is included in the returned array.
1.253 + * This method returns an array of length 0 if this {@code Class}
1.254 + * object represents an interface, a primitive type, an array class, or
1.255 + * void.
1.256 + *
1.257 + * <p> See <em>The Java Language Specification</em>, section 8.2.
1.258 + *
1.259 + * @return the array of {@code Constructor} objects representing all the
1.260 + * declared constructors of this class
1.261 + * @exception SecurityException
1.262 + * If a security manager, <i>s</i>, is present and any of the
1.263 + * following conditions is met:
1.264 + *
1.265 + * <ul>
1.266 + *
1.267 + * <li> invocation of
1.268 + * {@link SecurityManager#checkMemberAccess
1.269 + * s.checkMemberAccess(this, Member.DECLARED)} denies
1.270 + * access to the declared constructors within this class
1.271 + *
1.272 + * <li> the caller's class loader is not the same as or an
1.273 + * ancestor of the class loader for the current class and
1.274 + * invocation of {@link SecurityManager#checkPackageAccess
1.275 + * s.checkPackageAccess()} denies access to the package
1.276 + * of this class
1.277 + *
1.278 + * </ul>
1.279 + *
1.280 + * @since JDK1.1
1.281 + */
1.282 + public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
1.283 + throw new SecurityException();
1.284 + }
1.285 + /**
1.286 + * Returns a {@code Constructor} object that reflects the specified
1.287 + * constructor of the class or interface represented by this
1.288 + * {@code Class} object. The {@code parameterTypes} parameter is
1.289 + * an array of {@code Class} objects that identify the constructor's
1.290 + * formal parameter types, in declared order.
1.291 + *
1.292 + * If this {@code Class} object represents an inner class
1.293 + * declared in a non-static context, the formal parameter types
1.294 + * include the explicit enclosing instance as the first parameter.
1.295 + *
1.296 + * @param parameterTypes the parameter array
1.297 + * @return The {@code Constructor} object for the constructor with the
1.298 + * specified parameter list
1.299 + * @exception NoSuchMethodException if a matching method is not found.
1.300 + * @exception SecurityException
1.301 + * If a security manager, <i>s</i>, is present and any of the
1.302 + * following conditions is met:
1.303 + *
1.304 + * <ul>
1.305 + *
1.306 + * <li> invocation of
1.307 + * {@link SecurityManager#checkMemberAccess
1.308 + * s.checkMemberAccess(this, Member.DECLARED)} denies
1.309 + * access to the declared constructor
1.310 + *
1.311 + * <li> the caller's class loader is not the same as or an
1.312 + * ancestor of the class loader for the current class and
1.313 + * invocation of {@link SecurityManager#checkPackageAccess
1.314 + * s.checkPackageAccess()} denies access to the package
1.315 + * of this class
1.316 + *
1.317 + * </ul>
1.318 + *
1.319 + * @since JDK1.1
1.320 + */
1.321 + public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
1.322 + throws NoSuchMethodException, SecurityException {
1.323 + return getConstructor(parameterTypes);
1.324 + }
1.325 +
1.326 +
1.327 + /**
1.328 * Character.isDigit answers {@code true} to some non-ascii
1.329 * digits. This one does not.
1.330 */