# HG changeset patch # User Jaroslav Tulach # Date 1380324779 -7200 # Node ID bf0b56f2dca22e8bcfca9d3457f08b71e9e2b9ab # Parent a7d89cd0e34c0b5279c92dc20c59e1bf429c9b19 Adding more reflection methods, but mostly throwing exceptions diff -r a7d89cd0e34c -r bf0b56f2dca2 rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java Sat Sep 28 01:23:06 2013 +0200 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java Sat Sep 28 01:32:59 2013 +0200 @@ -72,6 +72,10 @@ @Compare public String isRunnableHasRunMethod() throws NoSuchMethodException { return Runnable.class.getMethod("run").getName(); } + + @Compare public String isRunnableDeclaresRunMethod() throws NoSuchMethodException { + return Runnable.class.getDeclaredMethod("run").getName(); + } @Compare public String namesOfMethods() { StringBuilder sb = new StringBuilder(); diff -r a7d89cd0e34c -r bf0b56f2dca2 rt/emul/mini/src/main/java/java/lang/Class.java --- a/rt/emul/mini/src/main/java/java/lang/Class.java Sat Sep 28 01:23:06 2013 +0200 +++ b/rt/emul/mini/src/main/java/java/lang/Class.java Sat Sep 28 01:32:59 2013 +0200 @@ -975,6 +975,137 @@ } /** + * Returns an array of {@code Field} objects reflecting all the fields + * declared by the class or interface represented by this + * {@code Class} object. This includes public, protected, default + * (package) access, and private fields, but excludes inherited fields. + * The elements in the array returned are not sorted and are not in any + * particular order. This method returns an array of length 0 if the class + * or interface declares no fields, or if this {@code Class} object + * represents a primitive type, an array class, or void. + * + *

See The Java Language Specification, sections 8.2 and 8.3. + * + * @return the array of {@code Field} objects representing all the + * declared fields of this class + * @exception SecurityException + * If a security manager, s, is present and any of the + * following conditions is met: + * + *

+ * + * @since JDK1.1 + */ + public Field[] getDeclaredFields() throws SecurityException { + throw new SecurityException(); + } + + /** + * Bck2Brwsr emulation can only seek public methods, otherwise it + * throws a {@code SecurityException}. + *

+ * Returns a {@code Method} object that reflects the specified + * declared method of the class or interface represented by this + * {@code Class} object. The {@code name} parameter is a + * {@code String} that specifies the simple name of the desired + * method, and the {@code parameterTypes} parameter is an array of + * {@code Class} objects that identify the method's formal parameter + * types, in declared order. If more than one method with the same + * parameter types is declared in a class, and one of these methods has a + * return type that is more specific than any of the others, that method is + * returned; otherwise one of the methods is chosen arbitrarily. If the + * name is "<init>"or "<clinit>" a {@code NoSuchMethodException} + * is raised. + * + * @param name the name of the method + * @param parameterTypes the parameter array + * @return the {@code Method} object for the method of this class + * matching the specified name and parameters + * @exception NoSuchMethodException if a matching method is not found. + * @exception NullPointerException if {@code name} is {@code null} + * @exception SecurityException + * If a security manager, s, is present and any of the + * following conditions is met: + * + *

+ * + * @since JDK1.1 + */ + public Method getDeclaredMethod(String name, Class... parameterTypes) + throws NoSuchMethodException, SecurityException { + try { + return getMethod(name, parameterTypes); + } catch (NoSuchMethodException ex) { + throw new SecurityException(); + } + } + + /** + * Returns a {@code Field} object that reflects the specified declared + * field of the class or interface represented by this {@code Class} + * object. The {@code name} parameter is a {@code String} that + * specifies the simple name of the desired field. Note that this method + * will not reflect the {@code length} field of an array class. + * + * @param name the name of the field + * @return the {@code Field} object for the specified field in this + * class + * @exception NoSuchFieldException if a field with the specified name is + * not found. + * @exception NullPointerException if {@code name} is {@code null} + * @exception SecurityException + * If a security manager, s, is present and any of the + * following conditions is met: + * + * + * + * @since JDK1.1 + */ + public Field getDeclaredField(String name) + throws SecurityException { + throw new SecurityException(); + } + + /** * Character.isDigit answers {@code true} to some non-ascii * digits. This one does not. */