Adding more reflection methods, but mostly throwing exceptions javac
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 28 Sep 2013 01:32:59 +0200
branchjavac
changeset 1312bf0b56f2dca2
parent 1311 a7d89cd0e34c
child 1313 f08854c7f8b1
child 1327 217ca48c5b80
Adding more reflection methods, but mostly throwing exceptions
rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java
rt/emul/mini/src/main/java/java/lang/Class.java
     1.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java	Sat Sep 28 01:23:06 2013 +0200
     1.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java	Sat Sep 28 01:32:59 2013 +0200
     1.3 @@ -72,6 +72,10 @@
     1.4      @Compare public String isRunnableHasRunMethod() throws NoSuchMethodException {
     1.5          return Runnable.class.getMethod("run").getName();
     1.6      }
     1.7 +
     1.8 +    @Compare public String isRunnableDeclaresRunMethod() throws NoSuchMethodException {
     1.9 +        return Runnable.class.getDeclaredMethod("run").getName();
    1.10 +    }
    1.11      
    1.12      @Compare public String namesOfMethods() {
    1.13          StringBuilder sb = new StringBuilder();
     2.1 --- a/rt/emul/mini/src/main/java/java/lang/Class.java	Sat Sep 28 01:23:06 2013 +0200
     2.2 +++ b/rt/emul/mini/src/main/java/java/lang/Class.java	Sat Sep 28 01:32:59 2013 +0200
     2.3 @@ -975,6 +975,137 @@
     2.4      }
     2.5      
     2.6      /**
     2.7 +     * Returns an array of {@code Field} objects reflecting all the fields
     2.8 +     * declared by the class or interface represented by this
     2.9 +     * {@code Class} object. This includes public, protected, default
    2.10 +     * (package) access, and private fields, but excludes inherited fields.
    2.11 +     * The elements in the array returned are not sorted and are not in any
    2.12 +     * particular order.  This method returns an array of length 0 if the class
    2.13 +     * or interface declares no fields, or if this {@code Class} object
    2.14 +     * represents a primitive type, an array class, or void.
    2.15 +     *
    2.16 +     * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
    2.17 +     *
    2.18 +     * @return    the array of {@code Field} objects representing all the
    2.19 +     * declared fields of this class
    2.20 +     * @exception  SecurityException
    2.21 +     *             If a security manager, <i>s</i>, is present and any of the
    2.22 +     *             following conditions is met:
    2.23 +     *
    2.24 +     *             <ul>
    2.25 +     *
    2.26 +     *             <li> invocation of
    2.27 +     *             {@link SecurityManager#checkMemberAccess
    2.28 +     *             s.checkMemberAccess(this, Member.DECLARED)} denies
    2.29 +     *             access to the declared fields within this class
    2.30 +     *
    2.31 +     *             <li> the caller's class loader is not the same as or an
    2.32 +     *             ancestor of the class loader for the current class and
    2.33 +     *             invocation of {@link SecurityManager#checkPackageAccess
    2.34 +     *             s.checkPackageAccess()} denies access to the package
    2.35 +     *             of this class
    2.36 +     *
    2.37 +     *             </ul>
    2.38 +     *
    2.39 +     * @since JDK1.1
    2.40 +     */
    2.41 +    public Field[] getDeclaredFields() throws SecurityException {
    2.42 +        throw new SecurityException();
    2.43 +    }
    2.44 +
    2.45 +    /**
    2.46 +     * <b>Bck2Brwsr</b> emulation can only seek public methods, otherwise it
    2.47 +     * throws a {@code SecurityException}.
    2.48 +     * <p>
    2.49 +     * Returns a {@code Method} object that reflects the specified
    2.50 +     * declared method of the class or interface represented by this
    2.51 +     * {@code Class} object. The {@code name} parameter is a
    2.52 +     * {@code String} that specifies the simple name of the desired
    2.53 +     * method, and the {@code parameterTypes} parameter is an array of
    2.54 +     * {@code Class} objects that identify the method's formal parameter
    2.55 +     * types, in declared order.  If more than one method with the same
    2.56 +     * parameter types is declared in a class, and one of these methods has a
    2.57 +     * return type that is more specific than any of the others, that method is
    2.58 +     * returned; otherwise one of the methods is chosen arbitrarily.  If the
    2.59 +     * name is "&lt;init&gt;"or "&lt;clinit&gt;" a {@code NoSuchMethodException}
    2.60 +     * is raised.
    2.61 +     *
    2.62 +     * @param name the name of the method
    2.63 +     * @param parameterTypes the parameter array
    2.64 +     * @return    the {@code Method} object for the method of this class
    2.65 +     * matching the specified name and parameters
    2.66 +     * @exception NoSuchMethodException if a matching method is not found.
    2.67 +     * @exception NullPointerException if {@code name} is {@code null}
    2.68 +     * @exception  SecurityException
    2.69 +     *             If a security manager, <i>s</i>, is present and any of the
    2.70 +     *             following conditions is met:
    2.71 +     *
    2.72 +     *             <ul>
    2.73 +     *
    2.74 +     *             <li> invocation of
    2.75 +     *             {@link SecurityManager#checkMemberAccess
    2.76 +     *             s.checkMemberAccess(this, Member.DECLARED)} denies
    2.77 +     *             access to the declared method
    2.78 +     *
    2.79 +     *             <li> the caller's class loader is not the same as or an
    2.80 +     *             ancestor of the class loader for the current class and
    2.81 +     *             invocation of {@link SecurityManager#checkPackageAccess
    2.82 +     *             s.checkPackageAccess()} denies access to the package
    2.83 +     *             of this class
    2.84 +     *
    2.85 +     *             </ul>
    2.86 +     *
    2.87 +     * @since JDK1.1
    2.88 +     */
    2.89 +    public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
    2.90 +    throws NoSuchMethodException, SecurityException {
    2.91 +        try {
    2.92 +            return getMethod(name, parameterTypes);
    2.93 +        } catch (NoSuchMethodException ex) {
    2.94 +            throw new SecurityException();
    2.95 +        }
    2.96 +    }
    2.97 +
    2.98 +    /**
    2.99 +     * Returns a {@code Field} object that reflects the specified declared
   2.100 +     * field of the class or interface represented by this {@code Class}
   2.101 +     * object. The {@code name} parameter is a {@code String} that
   2.102 +     * specifies the simple name of the desired field.  Note that this method
   2.103 +     * will not reflect the {@code length} field of an array class.
   2.104 +     *
   2.105 +     * @param name the name of the field
   2.106 +     * @return the {@code Field} object for the specified field in this
   2.107 +     * class
   2.108 +     * @exception NoSuchFieldException if a field with the specified name is
   2.109 +     *              not found.
   2.110 +     * @exception NullPointerException if {@code name} is {@code null}
   2.111 +     * @exception  SecurityException
   2.112 +     *             If a security manager, <i>s</i>, is present and any of the
   2.113 +     *             following conditions is met:
   2.114 +     *
   2.115 +     *             <ul>
   2.116 +     *
   2.117 +     *             <li> invocation of
   2.118 +     *             {@link SecurityManager#checkMemberAccess
   2.119 +     *             s.checkMemberAccess(this, Member.DECLARED)} denies
   2.120 +     *             access to the declared field
   2.121 +     *
   2.122 +     *             <li> the caller's class loader is not the same as or an
   2.123 +     *             ancestor of the class loader for the current class and
   2.124 +     *             invocation of {@link SecurityManager#checkPackageAccess
   2.125 +     *             s.checkPackageAccess()} denies access to the package
   2.126 +     *             of this class
   2.127 +     *
   2.128 +     *             </ul>
   2.129 +     *
   2.130 +     * @since JDK1.1
   2.131 +     */
   2.132 +    public Field getDeclaredField(String name)
   2.133 +    throws SecurityException {
   2.134 +        throw new SecurityException();
   2.135 +    }
   2.136 +    
   2.137 +    /**
   2.138       * Character.isDigit answers {@code true} to some non-ascii
   2.139       * digits.  This one does not.
   2.140       */