rt/emul/mini/src/main/java/java/lang/Class.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 13 Sep 2014 18:33:05 +0200
changeset 1688 e709c530c227
parent 1676 87f66a77adf9
parent 1653 bd151459ee4f
child 1702 228f26fc1159
permissions -rw-r--r--
Lambda's work OK in AOT mode. Defender methods work OK. Merging.
     1 /*
     2  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 
    26 package java.lang;
    27 
    28 import java.io.ByteArrayInputStream;
    29 import java.io.InputStream;
    30 import java.lang.annotation.Annotation;
    31 import java.lang.reflect.Array;
    32 import java.lang.reflect.Constructor;
    33 import java.lang.reflect.Field;
    34 import java.lang.reflect.Method;
    35 import java.lang.reflect.TypeVariable;
    36 import java.net.URL;
    37 import org.apidesign.bck2brwsr.core.Exported;
    38 import org.apidesign.bck2brwsr.core.JavaScriptBody;
    39 import org.apidesign.bck2brwsr.core.JavaScriptOnly;
    40 import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
    41 import org.apidesign.bck2brwsr.emul.reflect.MethodImpl;
    42 
    43 /**
    44  * Instances of the class {@code Class} represent classes and
    45  * interfaces in a running Java application.  An enum is a kind of
    46  * class and an annotation is a kind of interface.  Every array also
    47  * belongs to a class that is reflected as a {@code Class} object
    48  * that is shared by all arrays with the same element type and number
    49  * of dimensions.  The primitive Java types ({@code boolean},
    50  * {@code byte}, {@code char}, {@code short},
    51  * {@code int}, {@code long}, {@code float}, and
    52  * {@code double}), and the keyword {@code void} are also
    53  * represented as {@code Class} objects.
    54  *
    55  * <p> {@code Class} has no public constructor. Instead {@code Class}
    56  * objects are constructed automatically by the Java Virtual Machine as classes
    57  * are loaded and by calls to the {@code defineClass} method in the class
    58  * loader.
    59  *
    60  * <p> The following example uses a {@code Class} object to print the
    61  * class name of an object:
    62  *
    63  * <p> <blockquote><pre>
    64  *     void printClassName(Object obj) {
    65  *         System.out.println("The class of " + obj +
    66  *                            " is " + obj.getClass().getName());
    67  *     }
    68  * </pre></blockquote>
    69  *
    70  * <p> It is also possible to get the {@code Class} object for a named
    71  * type (or for void) using a class literal.  See Section 15.8.2 of
    72  * <cite>The Java&trade; Language Specification</cite>.
    73  * For example:
    74  *
    75  * <p> <blockquote>
    76  *     {@code System.out.println("The name of class Foo is: "+Foo.class.getName());}
    77  * </blockquote>
    78  *
    79  * @param <T> the type of the class modeled by this {@code Class}
    80  * object.  For example, the type of {@code String.class} is {@code
    81  * Class<String>}.  Use {@code Class<?>} if the class being modeled is
    82  * unknown.
    83  *
    84  * @author  unascribed
    85  * @see     java.lang.ClassLoader#defineClass(byte[], int, int)
    86  * @since   JDK1.0
    87  */
    88 public final
    89     class Class<T> implements java.io.Serializable,
    90                               java.lang.reflect.GenericDeclaration,
    91                               java.lang.reflect.Type,
    92                               java.lang.reflect.AnnotatedElement {
    93     private static final int ANNOTATION= 0x00002000;
    94     private static final int ENUM      = 0x00004000;
    95     private static final int SYNTHETIC = 0x00001000;
    96 
    97     /* Backing store of user-defined values pertaining to this class.
    98      * Maintained by the ClassValue class.
    99      */
   100     transient Object classValueMap;
   101     
   102     /*
   103      * Constructor. Only the Java Virtual Machine creates Class
   104      * objects.
   105      */
   106     private Class() {}
   107 
   108 
   109     /**
   110      * Converts the object to a string. The string representation is the
   111      * string "class" or "interface", followed by a space, and then by the
   112      * fully qualified name of the class in the format returned by
   113      * {@code getName}.  If this {@code Class} object represents a
   114      * primitive type, this method returns the name of the primitive type.  If
   115      * this {@code Class} object represents void this method returns
   116      * "void".
   117      *
   118      * @return a string representation of this class object.
   119      */
   120     public String toString() {
   121         return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
   122             + getName();
   123     }
   124 
   125 
   126     /**
   127      * Returns the {@code Class} object associated with the class or
   128      * interface with the given string name.  Invoking this method is
   129      * equivalent to:
   130      *
   131      * <blockquote>
   132      *  {@code Class.forName(className, true, currentLoader)}
   133      * </blockquote>
   134      *
   135      * where {@code currentLoader} denotes the defining class loader of
   136      * the current class.
   137      *
   138      * <p> For example, the following code fragment returns the
   139      * runtime {@code Class} descriptor for the class named
   140      * {@code java.lang.Thread}:
   141      *
   142      * <blockquote>
   143      *   {@code Class t = Class.forName("java.lang.Thread")}
   144      * </blockquote>
   145      * <p>
   146      * A call to {@code forName("X")} causes the class named
   147      * {@code X} to be initialized.
   148      *
   149      * @param      className   the fully qualified name of the desired class.
   150      * @return     the {@code Class} object for the class with the
   151      *             specified name.
   152      * @exception LinkageError if the linkage fails
   153      * @exception ExceptionInInitializerError if the initialization provoked
   154      *            by this method fails
   155      * @exception ClassNotFoundException if the class cannot be located
   156      */
   157     public static Class<?> forName(String className)
   158     throws ClassNotFoundException {
   159         if (className.startsWith("[")) {
   160             Class<?> arrType = defineArray(className, null);
   161             Class<?> c = arrType;
   162             while (c != null && c.isArray()) {
   163                 c = c.getComponentType0(); // verify component type is sane
   164             }
   165             return arrType;
   166         }
   167         try {
   168             Class<?> c = loadCls(className, className.replace('.', '_'));
   169             if (c == null) {
   170                 throw new ClassNotFoundException(className);
   171             }
   172             return c;
   173         } catch (Throwable ex) {
   174             throw new ClassNotFoundException(className, ex);
   175         }
   176     }
   177 
   178 
   179     /**
   180      * Returns the {@code Class} object associated with the class or
   181      * interface with the given string name, using the given class loader.
   182      * Given the fully qualified name for a class or interface (in the same
   183      * format returned by {@code getName}) this method attempts to
   184      * locate, load, and link the class or interface.  The specified class
   185      * loader is used to load the class or interface.  If the parameter
   186      * {@code loader} is null, the class is loaded through the bootstrap
   187      * class loader.  The class is initialized only if the
   188      * {@code initialize} parameter is {@code true} and if it has
   189      * not been initialized earlier.
   190      *
   191      * <p> If {@code name} denotes a primitive type or void, an attempt
   192      * will be made to locate a user-defined class in the unnamed package whose
   193      * name is {@code name}. Therefore, this method cannot be used to
   194      * obtain any of the {@code Class} objects representing primitive
   195      * types or void.
   196      *
   197      * <p> If {@code name} denotes an array class, the component type of
   198      * the array class is loaded but not initialized.
   199      *
   200      * <p> For example, in an instance method the expression:
   201      *
   202      * <blockquote>
   203      *  {@code Class.forName("Foo")}
   204      * </blockquote>
   205      *
   206      * is equivalent to:
   207      *
   208      * <blockquote>
   209      *  {@code Class.forName("Foo", true, this.getClass().getClassLoader())}
   210      * </blockquote>
   211      *
   212      * Note that this method throws errors related to loading, linking or
   213      * initializing as specified in Sections 12.2, 12.3 and 12.4 of <em>The
   214      * Java Language Specification</em>.
   215      * Note that this method does not check whether the requested class
   216      * is accessible to its caller.
   217      *
   218      * <p> If the {@code loader} is {@code null}, and a security
   219      * manager is present, and the caller's class loader is not null, then this
   220      * method calls the security manager's {@code checkPermission} method
   221      * with a {@code RuntimePermission("getClassLoader")} permission to
   222      * ensure it's ok to access the bootstrap class loader.
   223      *
   224      * @param name       fully qualified name of the desired class
   225      * @param initialize whether the class must be initialized
   226      * @param loader     class loader from which the class must be loaded
   227      * @return           class object representing the desired class
   228      *
   229      * @exception LinkageError if the linkage fails
   230      * @exception ExceptionInInitializerError if the initialization provoked
   231      *            by this method fails
   232      * @exception ClassNotFoundException if the class cannot be located by
   233      *            the specified class loader
   234      *
   235      * @see       java.lang.Class#forName(String)
   236      * @see       java.lang.ClassLoader
   237      * @since     1.2
   238      */
   239     public static Class<?> forName(String name, boolean initialize,
   240                                    ClassLoader loader)
   241         throws ClassNotFoundException
   242     {
   243         return forName(name);
   244     }
   245     
   246     @JavaScriptBody(args = {"n", "c" }, body =
   247         "var m = vm[c];\n"
   248       + "if (!m) {\n"
   249       + "  var l = vm.loadClass ? vm.loadClass : exports ? exports.loadClass : null;\n"
   250       + "  if (l) {\n"
   251       + "    l(n);\n"
   252       + "  }\n"
   253       + "  if (vm[c]) m = vm[c];\n"
   254       + "  else if (exports[c]) m = exports[c];\n"
   255       + "}\n"
   256       + "if (!m) return null;"
   257       + "m(false);"
   258       + "return m.$class;"
   259     )
   260     private static native Class<?> loadCls(String n, String c);
   261 
   262 
   263     /**
   264      * Creates a new instance of the class represented by this {@code Class}
   265      * object.  The class is instantiated as if by a {@code new}
   266      * expression with an empty argument list.  The class is initialized if it
   267      * has not already been initialized.
   268      *
   269      * <p>Note that this method propagates any exception thrown by the
   270      * nullary constructor, including a checked exception.  Use of
   271      * this method effectively bypasses the compile-time exception
   272      * checking that would otherwise be performed by the compiler.
   273      * The {@link
   274      * java.lang.reflect.Constructor#newInstance(java.lang.Object...)
   275      * Constructor.newInstance} method avoids this problem by wrapping
   276      * any exception thrown by the constructor in a (checked) {@link
   277      * java.lang.reflect.InvocationTargetException}.
   278      *
   279      * @return     a newly allocated instance of the class represented by this
   280      *             object.
   281      * @exception  IllegalAccessException  if the class or its nullary
   282      *               constructor is not accessible.
   283      * @exception  InstantiationException
   284      *               if this {@code Class} represents an abstract class,
   285      *               an interface, an array class, a primitive type, or void;
   286      *               or if the class has no nullary constructor;
   287      *               or if the instantiation fails for some other reason.
   288      * @exception  ExceptionInInitializerError if the initialization
   289      *               provoked by this method fails.
   290      * @exception  SecurityException
   291      *             If a security manager, <i>s</i>, is present and any of the
   292      *             following conditions is met:
   293      *
   294      *             <ul>
   295      *
   296      *             <li> invocation of
   297      *             {@link SecurityManager#checkMemberAccess
   298      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   299      *             creation of new instances of this class
   300      *
   301      *             <li> the caller's class loader is not the same as or an
   302      *             ancestor of the class loader for the current class and
   303      *             invocation of {@link SecurityManager#checkPackageAccess
   304      *             s.checkPackageAccess()} denies access to the package
   305      *             of this class
   306      *
   307      *             </ul>
   308      *
   309      */
   310     @JavaScriptBody(args = { "self", "illegal" }, body =
   311           "\nvar c = self.cnstr;"
   312         + "\nif (c['cons__V']) {"
   313         + "\n  if ((c['cons__V'].access & 0x1) != 0) {"
   314         + "\n    var inst = c();"
   315         + "\n    c['cons__V'].call(inst);"
   316         + "\n    return inst;"
   317         + "\n  }"
   318         + "\n  return illegal;"
   319         + "\n}"
   320         + "\nreturn null;"
   321     )
   322     private static native Object newInstance0(Class<?> self, Object illegal);
   323     
   324     public T newInstance()
   325         throws InstantiationException, IllegalAccessException
   326     {
   327         Object illegal = new Object();
   328         Object inst = newInstance0(this, illegal);
   329         if (inst == null) {
   330             throw new InstantiationException(getName());
   331         }
   332         if (inst == illegal) {
   333             throw new IllegalAccessException();
   334         }
   335         return (T)inst;
   336     }
   337 
   338     /**
   339      * Determines if the specified {@code Object} is assignment-compatible
   340      * with the object represented by this {@code Class}.  This method is
   341      * the dynamic equivalent of the Java language {@code instanceof}
   342      * operator. The method returns {@code true} if the specified
   343      * {@code Object} argument is non-null and can be cast to the
   344      * reference type represented by this {@code Class} object without
   345      * raising a {@code ClassCastException.} It returns {@code false}
   346      * otherwise.
   347      *
   348      * <p> Specifically, if this {@code Class} object represents a
   349      * declared class, this method returns {@code true} if the specified
   350      * {@code Object} argument is an instance of the represented class (or
   351      * of any of its subclasses); it returns {@code false} otherwise. If
   352      * this {@code Class} object represents an array class, this method
   353      * returns {@code true} if the specified {@code Object} argument
   354      * can be converted to an object of the array class by an identity
   355      * conversion or by a widening reference conversion; it returns
   356      * {@code false} otherwise. If this {@code Class} object
   357      * represents an interface, this method returns {@code true} if the
   358      * class or any superclass of the specified {@code Object} argument
   359      * implements this interface; it returns {@code false} otherwise. If
   360      * this {@code Class} object represents a primitive type, this method
   361      * returns {@code false}.
   362      *
   363      * @param   obj the object to check
   364      * @return  true if {@code obj} is an instance of this class
   365      *
   366      * @since JDK1.1
   367      */
   368     public boolean isInstance(Object obj) {
   369         if (obj == null) {
   370             return false;
   371         }
   372         if (isArray()) {
   373             return isAssignableFrom(obj.getClass());
   374         }
   375         
   376         String prop = "$instOf_" + getName().replace('.', '_');
   377         return hasProperty(obj, prop);
   378     }
   379     
   380     @JavaScriptBody(args = { "who", "prop" }, body = 
   381         "if (who[prop]) return true; else return false;"
   382     )
   383     private static native boolean hasProperty(Object who, String prop);
   384 
   385 
   386     /**
   387      * Determines if the class or interface represented by this
   388      * {@code Class} object is either the same as, or is a superclass or
   389      * superinterface of, the class or interface represented by the specified
   390      * {@code Class} parameter. It returns {@code true} if so;
   391      * otherwise it returns {@code false}. If this {@code Class}
   392      * object represents a primitive type, this method returns
   393      * {@code true} if the specified {@code Class} parameter is
   394      * exactly this {@code Class} object; otherwise it returns
   395      * {@code false}.
   396      *
   397      * <p> Specifically, this method tests whether the type represented by the
   398      * specified {@code Class} parameter can be converted to the type
   399      * represented by this {@code Class} object via an identity conversion
   400      * or via a widening reference conversion. See <em>The Java Language
   401      * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
   402      *
   403      * @param cls the {@code Class} object to be checked
   404      * @return the {@code boolean} value indicating whether objects of the
   405      * type {@code cls} can be assigned to objects of this class
   406      * @exception NullPointerException if the specified Class parameter is
   407      *            null.
   408      * @since JDK1.1
   409      */
   410     public boolean isAssignableFrom(Class<?> cls) {
   411         if (this == cls) {
   412             return true;
   413         }
   414         if (this == Object.class) {
   415             return true;
   416         }
   417         
   418         if (isArray()) {
   419             final Class<?> cmpType = cls.getComponentType();
   420             if (isPrimitive()) {
   421                 return this == cmpType;
   422             }
   423             return cmpType != null && getComponentType().isAssignableFrom(cmpType);
   424         }
   425         if (isPrimitive()) {
   426             return false;
   427         } else {
   428             if (cls.isPrimitive()) {
   429                 return false;
   430             }
   431             if (cls.isArray()) {
   432                 return false;
   433             }
   434             String prop = "$instOf_" + getName().replace('.', '_');
   435             return hasCnstrProperty(cls, prop);
   436         }
   437     }
   438 
   439     @JavaScriptBody(args = { "who", "prop" }, body = 
   440         "if (who.cnstr.prototype[prop]) return true; else return false;"
   441     )
   442     private static native boolean hasCnstrProperty(Object who, String prop);
   443     
   444     
   445     /**
   446      * Determines if the specified {@code Class} object represents an
   447      * interface type.
   448      *
   449      * @return  {@code true} if this object represents an interface;
   450      *          {@code false} otherwise.
   451      */
   452     public boolean isInterface() {
   453         return (getAccess() & 0x200) != 0;
   454     }
   455     
   456     @JavaScriptBody(args = {}, body = "return this.access;")
   457     private native int getAccess();
   458 
   459 
   460     /**
   461      * Determines if this {@code Class} object represents an array class.
   462      *
   463      * @return  {@code true} if this object represents an array class;
   464      *          {@code false} otherwise.
   465      * @since   JDK1.1
   466      */
   467     public boolean isArray() {
   468         return hasProperty(this, "array"); // NOI18N
   469     }
   470 
   471 
   472     /**
   473      * Determines if the specified {@code Class} object represents a
   474      * primitive type.
   475      *
   476      * <p> There are nine predefined {@code Class} objects to represent
   477      * the eight primitive types and void.  These are created by the Java
   478      * Virtual Machine, and have the same names as the primitive types that
   479      * they represent, namely {@code boolean}, {@code byte},
   480      * {@code char}, {@code short}, {@code int},
   481      * {@code long}, {@code float}, and {@code double}.
   482      *
   483      * <p> These objects may only be accessed via the following public static
   484      * final variables, and are the only {@code Class} objects for which
   485      * this method returns {@code true}.
   486      *
   487      * @return true if and only if this class represents a primitive type
   488      *
   489      * @see     java.lang.Boolean#TYPE
   490      * @see     java.lang.Character#TYPE
   491      * @see     java.lang.Byte#TYPE
   492      * @see     java.lang.Short#TYPE
   493      * @see     java.lang.Integer#TYPE
   494      * @see     java.lang.Long#TYPE
   495      * @see     java.lang.Float#TYPE
   496      * @see     java.lang.Double#TYPE
   497      * @see     java.lang.Void#TYPE
   498      * @since JDK1.1
   499      */
   500     @JavaScriptBody(args = {}, body = 
   501            "if (this.primitive) return true;"
   502         + "else return false;"
   503     )
   504     public native boolean isPrimitive();
   505 
   506     /**
   507      * Returns true if this {@code Class} object represents an annotation
   508      * type.  Note that if this method returns true, {@link #isInterface()}
   509      * would also return true, as all annotation types are also interfaces.
   510      *
   511      * @return {@code true} if this class object represents an annotation
   512      *      type; {@code false} otherwise
   513      * @since 1.5
   514      */
   515     public boolean isAnnotation() {
   516         return (getModifiers() & ANNOTATION) != 0;
   517     }
   518 
   519     /**
   520      * Returns {@code true} if this class is a synthetic class;
   521      * returns {@code false} otherwise.
   522      * @return {@code true} if and only if this class is a synthetic class as
   523      *         defined by the Java Language Specification.
   524      * @since 1.5
   525      */
   526     public boolean isSynthetic() {
   527         return (getModifiers() & SYNTHETIC) != 0;
   528     }
   529 
   530     /**
   531      * Returns the  name of the entity (class, interface, array class,
   532      * primitive type, or void) represented by this {@code Class} object,
   533      * as a {@code String}.
   534      *
   535      * <p> If this class object represents a reference type that is not an
   536      * array type then the binary name of the class is returned, as specified
   537      * by
   538      * <cite>The Java&trade; Language Specification</cite>.
   539      *
   540      * <p> If this class object represents a primitive type or void, then the
   541      * name returned is a {@code String} equal to the Java language
   542      * keyword corresponding to the primitive type or void.
   543      *
   544      * <p> If this class object represents a class of arrays, then the internal
   545      * form of the name consists of the name of the element type preceded by
   546      * one or more '{@code [}' characters representing the depth of the array
   547      * nesting.  The encoding of element type names is as follows:
   548      *
   549      * <blockquote><table summary="Element types and encodings">
   550      * <tr><th> Element Type <th> &nbsp;&nbsp;&nbsp; <th> Encoding
   551      * <tr><td> boolean      <td> &nbsp;&nbsp;&nbsp; <td align=center> Z
   552      * <tr><td> byte         <td> &nbsp;&nbsp;&nbsp; <td align=center> B
   553      * <tr><td> char         <td> &nbsp;&nbsp;&nbsp; <td align=center> C
   554      * <tr><td> class or interface
   555      *                       <td> &nbsp;&nbsp;&nbsp; <td align=center> L<i>classname</i>;
   556      * <tr><td> double       <td> &nbsp;&nbsp;&nbsp; <td align=center> D
   557      * <tr><td> float        <td> &nbsp;&nbsp;&nbsp; <td align=center> F
   558      * <tr><td> int          <td> &nbsp;&nbsp;&nbsp; <td align=center> I
   559      * <tr><td> long         <td> &nbsp;&nbsp;&nbsp; <td align=center> J
   560      * <tr><td> short        <td> &nbsp;&nbsp;&nbsp; <td align=center> S
   561      * </table></blockquote>
   562      *
   563      * <p> The class or interface name <i>classname</i> is the binary name of
   564      * the class specified above.
   565      *
   566      * <p> Examples:
   567      * <blockquote><pre>
   568      * String.class.getName()
   569      *     returns "java.lang.String"
   570      * byte.class.getName()
   571      *     returns "byte"
   572      * (new Object[3]).getClass().getName()
   573      *     returns "[Ljava.lang.Object;"
   574      * (new int[3][4][5][6][7][8][9]).getClass().getName()
   575      *     returns "[[[[[[[I"
   576      * </pre></blockquote>
   577      *
   578      * @return  the name of the class or interface
   579      *          represented by this object.
   580      */
   581     public String getName() {
   582         return jvmName().replace('/', '.');
   583     }
   584 
   585     @JavaScriptBody(args = {}, body = "return this.jvmName;")
   586     private native String jvmName();
   587 
   588     
   589     /**
   590      * Returns an array of {@code TypeVariable} objects that represent the
   591      * type variables declared by the generic declaration represented by this
   592      * {@code GenericDeclaration} object, in declaration order.  Returns an
   593      * array of length 0 if the underlying generic declaration declares no type
   594      * variables.
   595      *
   596      * @return an array of {@code TypeVariable} objects that represent
   597      *     the type variables declared by this generic declaration
   598      * @throws java.lang.reflect.GenericSignatureFormatError if the generic
   599      *     signature of this generic declaration does not conform to
   600      *     the format specified in
   601      *     <cite>The Java&trade; Virtual Machine Specification</cite>
   602      * @since 1.5
   603      */
   604     public TypeVariable<Class<T>>[] getTypeParameters() {
   605         throw new UnsupportedOperationException();
   606     }
   607  
   608     /**
   609      * Returns the {@code Class} representing the superclass of the entity
   610      * (class, interface, primitive type or void) represented by this
   611      * {@code Class}.  If this {@code Class} represents either the
   612      * {@code Object} class, an interface, a primitive type, or void, then
   613      * null is returned.  If this object represents an array class then the
   614      * {@code Class} object representing the {@code Object} class is
   615      * returned.
   616      *
   617      * @return the superclass of the class represented by this object.
   618      */
   619     @JavaScriptBody(args = {}, body = "return this.superclass;")
   620     public native Class<? super T> getSuperclass();
   621 
   622     /**
   623      * Returns the Java language modifiers for this class or interface, encoded
   624      * in an integer. The modifiers consist of the Java Virtual Machine's
   625      * constants for {@code public}, {@code protected},
   626      * {@code private}, {@code final}, {@code static},
   627      * {@code abstract} and {@code interface}; they should be decoded
   628      * using the methods of class {@code Modifier}.
   629      *
   630      * <p> If the underlying class is an array class, then its
   631      * {@code public}, {@code private} and {@code protected}
   632      * modifiers are the same as those of its component type.  If this
   633      * {@code Class} represents a primitive type or void, its
   634      * {@code public} modifier is always {@code true}, and its
   635      * {@code protected} and {@code private} modifiers are always
   636      * {@code false}. If this object represents an array class, a
   637      * primitive type or void, then its {@code final} modifier is always
   638      * {@code true} and its interface modifier is always
   639      * {@code false}. The values of its other modifiers are not determined
   640      * by this specification.
   641      *
   642      * <p> The modifier encodings are defined in <em>The Java Virtual Machine
   643      * Specification</em>, table 4.1.
   644      *
   645      * @return the {@code int} representing the modifiers for this class
   646      * @see     java.lang.reflect.Modifier
   647      * @since JDK1.1
   648      */
   649     public int getModifiers() {
   650         return getAccess();
   651     }
   652 
   653     /**
   654      * If the class or interface represented by this {@code Class} object
   655      * is a member of another class, returns the {@code Class} object
   656      * representing the class in which it was declared.  This method returns
   657      * null if this class or interface is not a member of any other class.  If
   658      * this {@code Class} object represents an array class, a primitive
   659      * type, or void,then this method returns null.
   660      *
   661      * @return the declaring class for this class
   662      * @since JDK1.1
   663      */
   664     public Class<?> getDeclaringClass() {
   665         throw new SecurityException();
   666     }
   667 
   668     /**
   669      * Returns the simple name of the underlying class as given in the
   670      * source code. Returns an empty string if the underlying class is
   671      * anonymous.
   672      *
   673      * <p>The simple name of an array is the simple name of the
   674      * component type with "[]" appended.  In particular the simple
   675      * name of an array whose component type is anonymous is "[]".
   676      *
   677      * @return the simple name of the underlying class
   678      * @since 1.5
   679      */
   680     public String getSimpleName() {
   681         if (isArray())
   682             return getComponentType().getSimpleName()+"[]";
   683 
   684         String simpleName = getSimpleBinaryName();
   685         if (simpleName == null) { // top level class
   686             simpleName = getName();
   687             return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
   688         }
   689         // According to JLS3 "Binary Compatibility" (13.1) the binary
   690         // name of non-package classes (not top level) is the binary
   691         // name of the immediately enclosing class followed by a '$' followed by:
   692         // (for nested and inner classes): the simple name.
   693         // (for local classes): 1 or more digits followed by the simple name.
   694         // (for anonymous classes): 1 or more digits.
   695 
   696         // Since getSimpleBinaryName() will strip the binary name of
   697         // the immediatly enclosing class, we are now looking at a
   698         // string that matches the regular expression "\$[0-9]*"
   699         // followed by a simple name (considering the simple of an
   700         // anonymous class to be the empty string).
   701 
   702         // Remove leading "\$[0-9]*" from the name
   703         int length = simpleName.length();
   704         if (length < 1 || simpleName.charAt(0) != '$')
   705             throw new IllegalStateException("Malformed class name");
   706         int index = 1;
   707         while (index < length && isAsciiDigit(simpleName.charAt(index)))
   708             index++;
   709         // Eventually, this is the empty string iff this is an anonymous class
   710         return simpleName.substring(index);
   711     }
   712 
   713     /**
   714      * Returns the "simple binary name" of the underlying class, i.e.,
   715      * the binary name without the leading enclosing class name.
   716      * Returns {@code null} if the underlying class is a top level
   717      * class.
   718      */
   719     private String getSimpleBinaryName() {
   720         Class<?> enclosingClass = null; // XXX getEnclosingClass();
   721         if (enclosingClass == null) // top level class
   722             return null;
   723         // Otherwise, strip the enclosing class' name
   724         try {
   725             return getName().substring(enclosingClass.getName().length());
   726         } catch (IndexOutOfBoundsException ex) {
   727             throw new IllegalStateException("Malformed class name");
   728         }
   729     }
   730 
   731     /**
   732      * Returns an array containing {@code Field} objects reflecting all
   733      * the accessible public fields of the class or interface represented by
   734      * this {@code Class} object.  The elements in the array returned are
   735      * not sorted and are not in any particular order.  This method returns an
   736      * array of length 0 if the class or interface has no accessible public
   737      * fields, or if it represents an array class, a primitive type, or void.
   738      *
   739      * <p> Specifically, if this {@code Class} object represents a class,
   740      * this method returns the public fields of this class and of all its
   741      * superclasses.  If this {@code Class} object represents an
   742      * interface, this method returns the fields of this interface and of all
   743      * its superinterfaces.
   744      *
   745      * <p> The implicit length field for array class is not reflected by this
   746      * method. User code should use the methods of class {@code Array} to
   747      * manipulate arrays.
   748      *
   749      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
   750      *
   751      * @return the array of {@code Field} objects representing the
   752      * public fields
   753      * @exception  SecurityException
   754      *             If a security manager, <i>s</i>, is present and any of the
   755      *             following conditions is met:
   756      *
   757      *             <ul>
   758      *
   759      *             <li> invocation of
   760      *             {@link SecurityManager#checkMemberAccess
   761      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   762      *             access to the fields within this class
   763      *
   764      *             <li> the caller's class loader is not the same as or an
   765      *             ancestor of the class loader for the current class and
   766      *             invocation of {@link SecurityManager#checkPackageAccess
   767      *             s.checkPackageAccess()} denies access to the package
   768      *             of this class
   769      *
   770      *             </ul>
   771      *
   772      * @since JDK1.1
   773      */
   774     public Field[] getFields() throws SecurityException {
   775         throw new SecurityException();
   776     }
   777 
   778     /**
   779      * Returns an array containing {@code Method} objects reflecting all
   780      * the public <em>member</em> methods of the class or interface represented
   781      * by this {@code Class} object, including those declared by the class
   782      * or interface and those inherited from superclasses and
   783      * superinterfaces.  Array classes return all the (public) member methods
   784      * inherited from the {@code Object} class.  The elements in the array
   785      * returned are not sorted and are not in any particular order.  This
   786      * method returns an array of length 0 if this {@code Class} object
   787      * represents a class or interface that has no public member methods, or if
   788      * this {@code Class} object represents a primitive type or void.
   789      *
   790      * <p> The class initialization method {@code <clinit>} is not
   791      * included in the returned array. If the class declares multiple public
   792      * member methods with the same parameter types, they are all included in
   793      * the returned array.
   794      *
   795      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
   796      *
   797      * @return the array of {@code Method} objects representing the
   798      * public methods of this class
   799      * @exception  SecurityException
   800      *             If a security manager, <i>s</i>, is present and any of the
   801      *             following conditions is met:
   802      *
   803      *             <ul>
   804      *
   805      *             <li> invocation of
   806      *             {@link SecurityManager#checkMemberAccess
   807      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   808      *             access to the methods within this class
   809      *
   810      *             <li> the caller's class loader is not the same as or an
   811      *             ancestor of the class loader for the current class and
   812      *             invocation of {@link SecurityManager#checkPackageAccess
   813      *             s.checkPackageAccess()} denies access to the package
   814      *             of this class
   815      *
   816      *             </ul>
   817      *
   818      * @since JDK1.1
   819      */
   820     public Method[] getMethods() throws SecurityException {
   821         return MethodImpl.findMethods(this, 0x01);
   822     }
   823 
   824     /**
   825      * Returns a {@code Field} object that reflects the specified public
   826      * member field of the class or interface represented by this
   827      * {@code Class} object. The {@code name} parameter is a
   828      * {@code String} specifying the simple name of the desired field.
   829      *
   830      * <p> The field to be reflected is determined by the algorithm that
   831      * follows.  Let C be the class represented by this object:
   832      * <OL>
   833      * <LI> If C declares a public field with the name specified, that is the
   834      *      field to be reflected.</LI>
   835      * <LI> If no field was found in step 1 above, this algorithm is applied
   836      *      recursively to each direct superinterface of C. The direct
   837      *      superinterfaces are searched in the order they were declared.</LI>
   838      * <LI> If no field was found in steps 1 and 2 above, and C has a
   839      *      superclass S, then this algorithm is invoked recursively upon S.
   840      *      If C has no superclass, then a {@code NoSuchFieldException}
   841      *      is thrown.</LI>
   842      * </OL>
   843      *
   844      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
   845      *
   846      * @param name the field name
   847      * @return  the {@code Field} object of this class specified by
   848      * {@code name}
   849      * @exception NoSuchFieldException if a field with the specified name is
   850      *              not found.
   851      * @exception NullPointerException if {@code name} is {@code null}
   852      * @exception  SecurityException
   853      *             If a security manager, <i>s</i>, is present and any of the
   854      *             following conditions is met:
   855      *
   856      *             <ul>
   857      *
   858      *             <li> invocation of
   859      *             {@link SecurityManager#checkMemberAccess
   860      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   861      *             access to the field
   862      *
   863      *             <li> the caller's class loader is not the same as or an
   864      *             ancestor of the class loader for the current class and
   865      *             invocation of {@link SecurityManager#checkPackageAccess
   866      *             s.checkPackageAccess()} denies access to the package
   867      *             of this class
   868      *
   869      *             </ul>
   870      *
   871      * @since JDK1.1
   872      */
   873     public Field getField(String name)
   874         throws SecurityException {
   875         throw new SecurityException();
   876     }
   877     
   878     
   879     /**
   880      * Returns a {@code Method} object that reflects the specified public
   881      * member method of the class or interface represented by this
   882      * {@code Class} object. The {@code name} parameter is a
   883      * {@code String} specifying the simple name of the desired method. The
   884      * {@code parameterTypes} parameter is an array of {@code Class}
   885      * objects that identify the method's formal parameter types, in declared
   886      * order. If {@code parameterTypes} is {@code null}, it is
   887      * treated as if it were an empty array.
   888      *
   889      * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
   890      * {@code NoSuchMethodException} is raised. Otherwise, the method to
   891      * be reflected is determined by the algorithm that follows.  Let C be the
   892      * class represented by this object:
   893      * <OL>
   894      * <LI> C is searched for any <I>matching methods</I>. If no matching
   895      *      method is found, the algorithm of step 1 is invoked recursively on
   896      *      the superclass of C.</LI>
   897      * <LI> If no method was found in step 1 above, the superinterfaces of C
   898      *      are searched for a matching method. If any such method is found, it
   899      *      is reflected.</LI>
   900      * </OL>
   901      *
   902      * To find a matching method in a class C:&nbsp; If C declares exactly one
   903      * public method with the specified name and exactly the same formal
   904      * parameter types, that is the method reflected. If more than one such
   905      * method is found in C, and one of these methods has a return type that is
   906      * more specific than any of the others, that method is reflected;
   907      * otherwise one of the methods is chosen arbitrarily.
   908      *
   909      * <p>Note that there may be more than one matching method in a
   910      * class because while the Java language forbids a class to
   911      * declare multiple methods with the same signature but different
   912      * return types, the Java virtual machine does not.  This
   913      * increased flexibility in the virtual machine can be used to
   914      * implement various language features.  For example, covariant
   915      * returns can be implemented with {@linkplain
   916      * java.lang.reflect.Method#isBridge bridge methods}; the bridge
   917      * method and the method being overridden would have the same
   918      * signature but different return types.
   919      *
   920      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
   921      *
   922      * @param name the name of the method
   923      * @param parameterTypes the list of parameters
   924      * @return the {@code Method} object that matches the specified
   925      * {@code name} and {@code parameterTypes}
   926      * @exception NoSuchMethodException if a matching method is not found
   927      *            or if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
   928      * @exception NullPointerException if {@code name} is {@code null}
   929      * @exception  SecurityException
   930      *             If a security manager, <i>s</i>, is present and any of the
   931      *             following conditions is met:
   932      *
   933      *             <ul>
   934      *
   935      *             <li> invocation of
   936      *             {@link SecurityManager#checkMemberAccess
   937      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   938      *             access to the method
   939      *
   940      *             <li> the caller's class loader is not the same as or an
   941      *             ancestor of the class loader for the current class and
   942      *             invocation of {@link SecurityManager#checkPackageAccess
   943      *             s.checkPackageAccess()} denies access to the package
   944      *             of this class
   945      *
   946      *             </ul>
   947      *
   948      * @since JDK1.1
   949      */
   950     public Method getMethod(String name, Class<?>... parameterTypes)
   951         throws SecurityException, NoSuchMethodException {
   952         Method m = MethodImpl.findMethod(this, name, parameterTypes);
   953         if (m == null) {
   954             StringBuilder sb = new StringBuilder();
   955             sb.append(getName()).append('.').append(name).append('(');
   956             String sep = "";
   957             for (int i = 0; i < parameterTypes.length; i++) {
   958                 sb.append(sep).append(parameterTypes[i].getName());
   959                 sep = ", ";
   960             }
   961             sb.append(')');
   962             throw new NoSuchMethodException(sb.toString());
   963         }
   964         return m;
   965     }
   966     
   967     /**
   968      * Returns an array of {@code Method} objects reflecting all the
   969      * methods declared by the class or interface represented by this
   970      * {@code Class} object. This includes public, protected, default
   971      * (package) access, and private methods, but excludes inherited methods.
   972      * The elements in the array returned are not sorted and are not in any
   973      * particular order.  This method returns an array of length 0 if the class
   974      * or interface declares no methods, or if this {@code Class} object
   975      * represents a primitive type, an array class, or void.  The class
   976      * initialization method {@code <clinit>} is not included in the
   977      * returned array. If the class declares multiple public member methods
   978      * with the same parameter types, they are all included in the returned
   979      * array.
   980      *
   981      * <p> See <em>The Java Language Specification</em>, section 8.2.
   982      *
   983      * @return    the array of {@code Method} objects representing all the
   984      * declared methods of this class
   985      * @exception  SecurityException
   986      *             If a security manager, <i>s</i>, is present and any of the
   987      *             following conditions is met:
   988      *
   989      *             <ul>
   990      *
   991      *             <li> invocation of
   992      *             {@link SecurityManager#checkMemberAccess
   993      *             s.checkMemberAccess(this, Member.DECLARED)} denies
   994      *             access to the declared methods within this class
   995      *
   996      *             <li> the caller's class loader is not the same as or an
   997      *             ancestor of the class loader for the current class and
   998      *             invocation of {@link SecurityManager#checkPackageAccess
   999      *             s.checkPackageAccess()} denies access to the package
  1000      *             of this class
  1001      *
  1002      *             </ul>
  1003      *
  1004      * @since JDK1.1
  1005      */
  1006     public Method[] getDeclaredMethods() throws SecurityException {
  1007         throw new SecurityException();
  1008     }
  1009     
  1010     /**
  1011      * Returns an array of {@code Field} objects reflecting all the fields
  1012      * declared by the class or interface represented by this
  1013      * {@code Class} object. This includes public, protected, default
  1014      * (package) access, and private fields, but excludes inherited fields.
  1015      * The elements in the array returned are not sorted and are not in any
  1016      * particular order.  This method returns an array of length 0 if the class
  1017      * or interface declares no fields, or if this {@code Class} object
  1018      * represents a primitive type, an array class, or void.
  1019      *
  1020      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
  1021      *
  1022      * @return    the array of {@code Field} objects representing all the
  1023      * declared fields of this class
  1024      * @exception  SecurityException
  1025      *             If a security manager, <i>s</i>, is present and any of the
  1026      *             following conditions is met:
  1027      *
  1028      *             <ul>
  1029      *
  1030      *             <li> invocation of
  1031      *             {@link SecurityManager#checkMemberAccess
  1032      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1033      *             access to the declared fields within this class
  1034      *
  1035      *             <li> the caller's class loader is not the same as or an
  1036      *             ancestor of the class loader for the current class and
  1037      *             invocation of {@link SecurityManager#checkPackageAccess
  1038      *             s.checkPackageAccess()} denies access to the package
  1039      *             of this class
  1040      *
  1041      *             </ul>
  1042      *
  1043      * @since JDK1.1
  1044      */
  1045     public Field[] getDeclaredFields() throws SecurityException {
  1046         throw new SecurityException();
  1047     }
  1048 
  1049     /**
  1050      * <b>Bck2Brwsr</b> emulation can only seek public methods, otherwise it
  1051      * throws a {@code SecurityException}.
  1052      * <p>
  1053      * Returns a {@code Method} object that reflects the specified
  1054      * declared method of the class or interface represented by this
  1055      * {@code Class} object. The {@code name} parameter is a
  1056      * {@code String} that specifies the simple name of the desired
  1057      * method, and the {@code parameterTypes} parameter is an array of
  1058      * {@code Class} objects that identify the method's formal parameter
  1059      * types, in declared order.  If more than one method with the same
  1060      * parameter types is declared in a class, and one of these methods has a
  1061      * return type that is more specific than any of the others, that method is
  1062      * returned; otherwise one of the methods is chosen arbitrarily.  If the
  1063      * name is "&lt;init&gt;"or "&lt;clinit&gt;" a {@code NoSuchMethodException}
  1064      * is raised.
  1065      *
  1066      * @param name the name of the method
  1067      * @param parameterTypes the parameter array
  1068      * @return    the {@code Method} object for the method of this class
  1069      * matching the specified name and parameters
  1070      * @exception NoSuchMethodException if a matching method is not found.
  1071      * @exception NullPointerException if {@code name} is {@code null}
  1072      * @exception  SecurityException
  1073      *             If a security manager, <i>s</i>, is present and any of the
  1074      *             following conditions is met:
  1075      *
  1076      *             <ul>
  1077      *
  1078      *             <li> invocation of
  1079      *             {@link SecurityManager#checkMemberAccess
  1080      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1081      *             access to the declared method
  1082      *
  1083      *             <li> the caller's class loader is not the same as or an
  1084      *             ancestor of the class loader for the current class and
  1085      *             invocation of {@link SecurityManager#checkPackageAccess
  1086      *             s.checkPackageAccess()} denies access to the package
  1087      *             of this class
  1088      *
  1089      *             </ul>
  1090      *
  1091      * @since JDK1.1
  1092      */
  1093     public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
  1094     throws NoSuchMethodException, SecurityException {
  1095         try {
  1096             return getMethod(name, parameterTypes);
  1097         } catch (NoSuchMethodException ex) {
  1098             throw new SecurityException();
  1099         }
  1100     }
  1101 
  1102     /**
  1103      * Returns a {@code Field} object that reflects the specified declared
  1104      * field of the class or interface represented by this {@code Class}
  1105      * object. The {@code name} parameter is a {@code String} that
  1106      * specifies the simple name of the desired field.  Note that this method
  1107      * will not reflect the {@code length} field of an array class.
  1108      *
  1109      * @param name the name of the field
  1110      * @return the {@code Field} object for the specified field in this
  1111      * class
  1112      * @exception NoSuchFieldException if a field with the specified name is
  1113      *              not found.
  1114      * @exception NullPointerException if {@code name} is {@code null}
  1115      * @exception  SecurityException
  1116      *             If a security manager, <i>s</i>, is present and any of the
  1117      *             following conditions is met:
  1118      *
  1119      *             <ul>
  1120      *
  1121      *             <li> invocation of
  1122      *             {@link SecurityManager#checkMemberAccess
  1123      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1124      *             access to the declared field
  1125      *
  1126      *             <li> the caller's class loader is not the same as or an
  1127      *             ancestor of the class loader for the current class and
  1128      *             invocation of {@link SecurityManager#checkPackageAccess
  1129      *             s.checkPackageAccess()} denies access to the package
  1130      *             of this class
  1131      *
  1132      *             </ul>
  1133      *
  1134      * @since JDK1.1
  1135      */
  1136     public Field getDeclaredField(String name)
  1137     throws SecurityException {
  1138         throw new SecurityException();
  1139     }
  1140     
  1141     /**
  1142      * Returns an array containing {@code Constructor} objects reflecting
  1143      * all the public constructors of the class represented by this
  1144      * {@code Class} object.  An array of length 0 is returned if the
  1145      * class has no public constructors, or if the class is an array class, or
  1146      * if the class reflects a primitive type or void.
  1147      *
  1148      * Note that while this method returns an array of {@code
  1149      * Constructor<T>} objects (that is an array of constructors from
  1150      * this class), the return type of this method is {@code
  1151      * Constructor<?>[]} and <em>not</em> {@code Constructor<T>[]} as
  1152      * might be expected.  This less informative return type is
  1153      * necessary since after being returned from this method, the
  1154      * array could be modified to hold {@code Constructor} objects for
  1155      * different classes, which would violate the type guarantees of
  1156      * {@code Constructor<T>[]}.
  1157      *
  1158      * @return the array of {@code Constructor} objects representing the
  1159      *  public constructors of this class
  1160      * @exception  SecurityException
  1161      *             If a security manager, <i>s</i>, is present and any of the
  1162      *             following conditions is met:
  1163      *
  1164      *             <ul>
  1165      *
  1166      *             <li> invocation of
  1167      *             {@link SecurityManager#checkMemberAccess
  1168      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
  1169      *             access to the constructors within this class
  1170      *
  1171      *             <li> the caller's class loader is not the same as or an
  1172      *             ancestor of the class loader for the current class and
  1173      *             invocation of {@link SecurityManager#checkPackageAccess
  1174      *             s.checkPackageAccess()} denies access to the package
  1175      *             of this class
  1176      *
  1177      *             </ul>
  1178      *
  1179      * @since JDK1.1
  1180      */
  1181     public Constructor<?>[] getConstructors() throws SecurityException {
  1182         return MethodImpl.findConstructors(this, 0x01);
  1183     }
  1184 
  1185     /**
  1186      * Returns a {@code Constructor} object that reflects the specified
  1187      * public constructor of the class represented by this {@code Class}
  1188      * object. The {@code parameterTypes} parameter is an array of
  1189      * {@code Class} objects that identify the constructor's formal
  1190      * parameter types, in declared order.
  1191      *
  1192      * If this {@code Class} object represents an inner class
  1193      * declared in a non-static context, the formal parameter types
  1194      * include the explicit enclosing instance as the first parameter.
  1195      *
  1196      * <p> The constructor to reflect is the public constructor of the class
  1197      * represented by this {@code Class} object whose formal parameter
  1198      * types match those specified by {@code parameterTypes}.
  1199      *
  1200      * @param parameterTypes the parameter array
  1201      * @return the {@code Constructor} object of the public constructor that
  1202      * matches the specified {@code parameterTypes}
  1203      * @exception NoSuchMethodException if a matching method is not found.
  1204      * @exception  SecurityException
  1205      *             If a security manager, <i>s</i>, is present and any of the
  1206      *             following conditions is met:
  1207      *
  1208      *             <ul>
  1209      *
  1210      *             <li> invocation of
  1211      *             {@link SecurityManager#checkMemberAccess
  1212      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
  1213      *             access to the constructor
  1214      *
  1215      *             <li> the caller's class loader is not the same as or an
  1216      *             ancestor of the class loader for the current class and
  1217      *             invocation of {@link SecurityManager#checkPackageAccess
  1218      *             s.checkPackageAccess()} denies access to the package
  1219      *             of this class
  1220      *
  1221      *             </ul>
  1222      *
  1223      * @since JDK1.1
  1224      */
  1225     public Constructor<T> getConstructor(Class<?>... parameterTypes)
  1226     throws NoSuchMethodException, SecurityException {
  1227         Constructor c = MethodImpl.findConstructor(this, parameterTypes);
  1228         if (c == null) {
  1229             StringBuilder sb = new StringBuilder();
  1230             sb.append(getName()).append('(');
  1231             String sep = "";
  1232             for (int i = 0; i < parameterTypes.length; i++) {
  1233                 sb.append(sep).append(parameterTypes[i].getName());
  1234                 sep = ", ";
  1235             }
  1236             sb.append(')');
  1237             throw new NoSuchMethodException(sb.toString());
  1238         }
  1239         return c;
  1240     }
  1241 
  1242     /**
  1243      * Returns an array of {@code Constructor} objects reflecting all the
  1244      * constructors declared by the class represented by this
  1245      * {@code Class} object. These are public, protected, default
  1246      * (package) access, and private constructors.  The elements in the array
  1247      * returned are not sorted and are not in any particular order.  If the
  1248      * class has a default constructor, it is included in the returned array.
  1249      * This method returns an array of length 0 if this {@code Class}
  1250      * object represents an interface, a primitive type, an array class, or
  1251      * void.
  1252      *
  1253      * <p> See <em>The Java Language Specification</em>, section 8.2.
  1254      *
  1255      * @return    the array of {@code Constructor} objects representing all the
  1256      * declared constructors of this class
  1257      * @exception  SecurityException
  1258      *             If a security manager, <i>s</i>, is present and any of the
  1259      *             following conditions is met:
  1260      *
  1261      *             <ul>
  1262      *
  1263      *             <li> invocation of
  1264      *             {@link SecurityManager#checkMemberAccess
  1265      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1266      *             access to the declared constructors within this class
  1267      *
  1268      *             <li> the caller's class loader is not the same as or an
  1269      *             ancestor of the class loader for the current class and
  1270      *             invocation of {@link SecurityManager#checkPackageAccess
  1271      *             s.checkPackageAccess()} denies access to the package
  1272      *             of this class
  1273      *
  1274      *             </ul>
  1275      *
  1276      * @since JDK1.1
  1277      */
  1278     public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
  1279         throw new SecurityException();
  1280     }
  1281     /**
  1282      * Returns a {@code Constructor} object that reflects the specified
  1283      * constructor of the class or interface represented by this
  1284      * {@code Class} object.  The {@code parameterTypes} parameter is
  1285      * an array of {@code Class} objects that identify the constructor's
  1286      * formal parameter types, in declared order.
  1287      *
  1288      * If this {@code Class} object represents an inner class
  1289      * declared in a non-static context, the formal parameter types
  1290      * include the explicit enclosing instance as the first parameter.
  1291      *
  1292      * @param parameterTypes the parameter array
  1293      * @return    The {@code Constructor} object for the constructor with the
  1294      * specified parameter list
  1295      * @exception NoSuchMethodException if a matching method is not found.
  1296      * @exception  SecurityException
  1297      *             If a security manager, <i>s</i>, is present and any of the
  1298      *             following conditions is met:
  1299      *
  1300      *             <ul>
  1301      *
  1302      *             <li> invocation of
  1303      *             {@link SecurityManager#checkMemberAccess
  1304      *             s.checkMemberAccess(this, Member.DECLARED)} denies
  1305      *             access to the declared constructor
  1306      *
  1307      *             <li> the caller's class loader is not the same as or an
  1308      *             ancestor of the class loader for the current class and
  1309      *             invocation of {@link SecurityManager#checkPackageAccess
  1310      *             s.checkPackageAccess()} denies access to the package
  1311      *             of this class
  1312      *
  1313      *             </ul>
  1314      *
  1315      * @since JDK1.1
  1316      */
  1317     public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
  1318     throws NoSuchMethodException, SecurityException {
  1319         return getConstructor(parameterTypes);
  1320     }
  1321     
  1322     
  1323     /**
  1324      * Character.isDigit answers {@code true} to some non-ascii
  1325      * digits.  This one does not.
  1326      */
  1327     private static boolean isAsciiDigit(char c) {
  1328         return '0' <= c && c <= '9';
  1329     }
  1330 
  1331     /**
  1332      * Returns the canonical name of the underlying class as
  1333      * defined by the Java Language Specification.  Returns null if
  1334      * the underlying class does not have a canonical name (i.e., if
  1335      * it is a local or anonymous class or an array whose component
  1336      * type does not have a canonical name).
  1337      * @return the canonical name of the underlying class if it exists, and
  1338      * {@code null} otherwise.
  1339      * @since 1.5
  1340      */
  1341     public String getCanonicalName() {
  1342         if (isArray()) {
  1343             String canonicalName = getComponentType().getCanonicalName();
  1344             if (canonicalName != null)
  1345                 return canonicalName + "[]";
  1346             else
  1347                 return null;
  1348         }
  1349 //        if (isLocalOrAnonymousClass())
  1350 //            return null;
  1351 //        Class<?> enclosingClass = getEnclosingClass();
  1352         Class<?> enclosingClass = null;
  1353         if (enclosingClass == null) { // top level class
  1354             return getName();
  1355         } else {
  1356             String enclosingName = enclosingClass.getCanonicalName();
  1357             if (enclosingName == null)
  1358                 return null;
  1359             return enclosingName + "." + getSimpleName();
  1360         }
  1361     }
  1362 
  1363     /**
  1364      * Finds a resource with a given name.  The rules for searching resources
  1365      * associated with a given class are implemented by the defining
  1366      * {@linkplain ClassLoader class loader} of the class.  This method
  1367      * delegates to this object's class loader.  If this object was loaded by
  1368      * the bootstrap class loader, the method delegates to {@link
  1369      * ClassLoader#getSystemResourceAsStream}.
  1370      *
  1371      * <p> Before delegation, an absolute resource name is constructed from the
  1372      * given resource name using this algorithm:
  1373      *
  1374      * <ul>
  1375      *
  1376      * <li> If the {@code name} begins with a {@code '/'}
  1377      * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
  1378      * portion of the {@code name} following the {@code '/'}.
  1379      *
  1380      * <li> Otherwise, the absolute name is of the following form:
  1381      *
  1382      * <blockquote>
  1383      *   {@code modified_package_name/name}
  1384      * </blockquote>
  1385      *
  1386      * <p> Where the {@code modified_package_name} is the package name of this
  1387      * object with {@code '/'} substituted for {@code '.'}
  1388      * (<tt>'&#92;u002e'</tt>).
  1389      *
  1390      * </ul>
  1391      *
  1392      * @param  name name of the desired resource
  1393      * @return      A {@link java.io.InputStream} object or {@code null} if
  1394      *              no resource with this name is found
  1395      * @throws  NullPointerException If {@code name} is {@code null}
  1396      * @since  JDK1.1
  1397      */
  1398      public InputStream getResourceAsStream(String name) {
  1399         name = resolveName(name);
  1400         byte[] arr = ClassLoader.getResourceAsStream0(name, 0);
  1401         return arr == null ? null : new ByteArrayInputStream(arr);
  1402      }
  1403     
  1404     /**
  1405      * Finds a resource with a given name.  The rules for searching resources
  1406      * associated with a given class are implemented by the defining
  1407      * {@linkplain ClassLoader class loader} of the class.  This method
  1408      * delegates to this object's class loader.  If this object was loaded by
  1409      * the bootstrap class loader, the method delegates to {@link
  1410      * ClassLoader#getSystemResource}.
  1411      *
  1412      * <p> Before delegation, an absolute resource name is constructed from the
  1413      * given resource name using this algorithm:
  1414      *
  1415      * <ul>
  1416      *
  1417      * <li> If the {@code name} begins with a {@code '/'}
  1418      * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
  1419      * portion of the {@code name} following the {@code '/'}.
  1420      *
  1421      * <li> Otherwise, the absolute name is of the following form:
  1422      *
  1423      * <blockquote>
  1424      *   {@code modified_package_name/name}
  1425      * </blockquote>
  1426      *
  1427      * <p> Where the {@code modified_package_name} is the package name of this
  1428      * object with {@code '/'} substituted for {@code '.'}
  1429      * (<tt>'&#92;u002e'</tt>).
  1430      *
  1431      * </ul>
  1432      *
  1433      * @param  name name of the desired resource
  1434      * @return      A  {@link java.net.URL} object or {@code null} if no
  1435      *              resource with this name is found
  1436      * @since  JDK1.1
  1437      */
  1438     public java.net.URL getResource(String name) {
  1439         return newResourceURL(name, getResourceAsStream(name));
  1440     }
  1441 
  1442     static URL newResourceURL(String name, InputStream is) {
  1443         return is == null ? null : newResourceURL0(URL.class, "res:/" + name, is);
  1444     }
  1445     
  1446     @JavaScriptBody(args = { "url", "spec", "is" }, body = 
  1447         "var u = url.cnstr(true);\n"
  1448       + "u.constructor.cons__VLjava_lang_String_2Ljava_io_InputStream_2.call(u, spec, is);\n"
  1449       + "return u;"
  1450     )
  1451     private static native URL newResourceURL0(Class<URL> url, String spec, InputStream is);
  1452 
  1453    /**
  1454      * Add a package name prefix if the name is not absolute Remove leading "/"
  1455      * if name is absolute
  1456      */
  1457     private String resolveName(String name) {
  1458         if (name == null) {
  1459             return name;
  1460         }
  1461         if (!name.startsWith("/")) {
  1462             Class<?> c = this;
  1463             while (c.isArray()) {
  1464                 c = c.getComponentType();
  1465             }
  1466             String baseName = c.getName();
  1467             int index = baseName.lastIndexOf('.');
  1468             if (index != -1) {
  1469                 name = baseName.substring(0, index).replace('.', '/')
  1470                     +"/"+name;
  1471             }
  1472         } else {
  1473             name = name.substring(1);
  1474         }
  1475         return name;
  1476     }
  1477     
  1478     /**
  1479      * Returns the class loader for the class.  Some implementations may use
  1480      * null to represent the bootstrap class loader. This method will return
  1481      * null in such implementations if this class was loaded by the bootstrap
  1482      * class loader.
  1483      *
  1484      * <p> If a security manager is present, and the caller's class loader is
  1485      * not null and the caller's class loader is not the same as or an ancestor of
  1486      * the class loader for the class whose class loader is requested, then
  1487      * this method calls the security manager's {@code checkPermission}
  1488      * method with a {@code RuntimePermission("getClassLoader")}
  1489      * permission to ensure it's ok to access the class loader for the class.
  1490      *
  1491      * <p>If this object
  1492      * represents a primitive type or void, null is returned.
  1493      *
  1494      * @return  the class loader that loaded the class or interface
  1495      *          represented by this object.
  1496      * @throws SecurityException
  1497      *    if a security manager exists and its
  1498      *    {@code checkPermission} method denies
  1499      *    access to the class loader for the class.
  1500      * @see java.lang.ClassLoader
  1501      * @see SecurityManager#checkPermission
  1502      * @see java.lang.RuntimePermission
  1503      */
  1504     public ClassLoader getClassLoader() {
  1505         return ClassLoader.getSystemClassLoader();
  1506     }
  1507 
  1508     /**
  1509      * Determines the interfaces implemented by the class or interface
  1510      * represented by this object.
  1511      *
  1512      * <p> If this object represents a class, the return value is an array
  1513      * containing objects representing all interfaces implemented by the
  1514      * class. The order of the interface objects in the array corresponds to
  1515      * the order of the interface names in the {@code implements} clause
  1516      * of the declaration of the class represented by this object. For
  1517      * example, given the declaration:
  1518      * <blockquote>
  1519      * {@code class Shimmer implements FloorWax, DessertTopping { ... }}
  1520      * </blockquote>
  1521      * suppose the value of {@code s} is an instance of
  1522      * {@code Shimmer}; the value of the expression:
  1523      * <blockquote>
  1524      * {@code s.getClass().getInterfaces()[0]}
  1525      * </blockquote>
  1526      * is the {@code Class} object that represents interface
  1527      * {@code FloorWax}; and the value of:
  1528      * <blockquote>
  1529      * {@code s.getClass().getInterfaces()[1]}
  1530      * </blockquote>
  1531      * is the {@code Class} object that represents interface
  1532      * {@code DessertTopping}.
  1533      *
  1534      * <p> If this object represents an interface, the array contains objects
  1535      * representing all interfaces extended by the interface. The order of the
  1536      * interface objects in the array corresponds to the order of the interface
  1537      * names in the {@code extends} clause of the declaration of the
  1538      * interface represented by this object.
  1539      *
  1540      * <p> If this object represents a class or interface that implements no
  1541      * interfaces, the method returns an array of length 0.
  1542      *
  1543      * <p> If this object represents a primitive type or void, the method
  1544      * returns an array of length 0.
  1545      *
  1546      * @return an array of interfaces implemented by this class.
  1547      */
  1548     public native Class<?>[] getInterfaces();
  1549     
  1550     /**
  1551      * Returns the {@code Class} representing the component type of an
  1552      * array.  If this class does not represent an array class this method
  1553      * returns null.
  1554      *
  1555      * @return the {@code Class} representing the component type of this
  1556      * class if this class is an array
  1557      * @see     java.lang.reflect.Array
  1558      * @since JDK1.1
  1559      */
  1560     public Class<?> getComponentType() {
  1561         if (isArray()) {
  1562             try {
  1563                 Class<?> c = getComponentTypeByFnc();
  1564                 return c != null ? c : getComponentType0();
  1565             } catch (ClassNotFoundException cnfe) {
  1566                 throw new IllegalStateException(cnfe);
  1567             }
  1568         }
  1569         return null;
  1570     }
  1571     
  1572     @JavaScriptBody(args = {  }, body = 
  1573         "if (this.fnc) {\n"
  1574       + "  var c = this.fnc(false).constructor.$class;\n"
  1575 //      + "  java.lang.System.out.println('will call: ' + (!!this.fnc) + ' res: ' + c.jvmName);\n"
  1576       + "  if (c) return c;\n"
  1577       + "}\n"
  1578       + "return null;"
  1579     )
  1580     private native Class<?> getComponentTypeByFnc();
  1581 
  1582     private Class<?> getComponentType0() throws ClassNotFoundException {
  1583         String n = getName().substring(1);
  1584         switch (n.charAt(0)) {
  1585             case 'L': 
  1586                 n = n.substring(1, n.length() - 1);
  1587                 return Class.forName(n);
  1588             case 'I':
  1589                 return Integer.TYPE;
  1590             case 'J':
  1591                 return Long.TYPE;
  1592             case 'D':
  1593                 return Double.TYPE;
  1594             case 'F':
  1595                 return Float.TYPE;
  1596             case 'B':
  1597                 return Byte.TYPE;
  1598             case 'Z':
  1599                 return Boolean.TYPE;
  1600             case 'S':
  1601                 return Short.TYPE;
  1602             case 'V':
  1603                 return Void.TYPE;
  1604             case 'C':
  1605                 return Character.TYPE;
  1606             case '[':
  1607                 return defineArray(n, null);
  1608             default:
  1609                 throw new ClassNotFoundException("Unknown component type of " + getName());
  1610         }
  1611     }
  1612     
  1613     @JavaScriptBody(args = { "sig", "fnc" }, body = 
  1614         "if (!sig) sig = '[Ljava/lang/Object;';\n" +
  1615         "var c = Array[sig];\n" +
  1616         "if (!c) {\n" +
  1617         "  c = vm.java_lang_Class(true);\n" +
  1618         "  c.jvmName = sig;\n" +
  1619         "  c.superclass = vm.java_lang_Object(false).$class;\n" +
  1620         "  c.array = true;\n" +
  1621         "  Array[sig] = c;\n" +
  1622         "}\n" +
  1623         "if (!c.fnc) c.fnc = fnc;\n" +
  1624         "return c;"
  1625     )
  1626     private static native Class<?> defineArray(String sig, Object fnc);
  1627     
  1628     /**
  1629      * Returns true if and only if this class was declared as an enum in the
  1630      * source code.
  1631      *
  1632      * @return true if and only if this class was declared as an enum in the
  1633      *     source code
  1634      * @since 1.5
  1635      */
  1636     public boolean isEnum() {
  1637         // An enum must both directly extend java.lang.Enum and have
  1638         // the ENUM bit set; classes for specialized enum constants
  1639         // don't do the former.
  1640         return (this.getModifiers() & ENUM) != 0 &&
  1641         this.getSuperclass() == java.lang.Enum.class;
  1642     }
  1643 
  1644     /**
  1645      * Casts an object to the class or interface represented
  1646      * by this {@code Class} object.
  1647      *
  1648      * @param obj the object to be cast
  1649      * @return the object after casting, or null if obj is null
  1650      *
  1651      * @throws ClassCastException if the object is not
  1652      * null and is not assignable to the type T.
  1653      *
  1654      * @since 1.5
  1655      */
  1656     public T cast(Object obj) {
  1657         if (obj != null && !isInstance(obj))
  1658             throw new ClassCastException(cannotCastMsg(obj));
  1659         return (T) obj;
  1660     }
  1661 
  1662     private String cannotCastMsg(Object obj) {
  1663         return "Cannot cast " + obj.getClass().getName() + " to " + getName();
  1664     }
  1665 
  1666     /**
  1667      * Casts this {@code Class} object to represent a subclass of the class
  1668      * represented by the specified class object.  Checks that that the cast
  1669      * is valid, and throws a {@code ClassCastException} if it is not.  If
  1670      * this method succeeds, it always returns a reference to this class object.
  1671      *
  1672      * <p>This method is useful when a client needs to "narrow" the type of
  1673      * a {@code Class} object to pass it to an API that restricts the
  1674      * {@code Class} objects that it is willing to accept.  A cast would
  1675      * generate a compile-time warning, as the correctness of the cast
  1676      * could not be checked at runtime (because generic types are implemented
  1677      * by erasure).
  1678      *
  1679      * @return this {@code Class} object, cast to represent a subclass of
  1680      *    the specified class object.
  1681      * @throws ClassCastException if this {@code Class} object does not
  1682      *    represent a subclass of the specified class (here "subclass" includes
  1683      *    the class itself).
  1684      * @since 1.5
  1685      */
  1686     public <U> Class<? extends U> asSubclass(Class<U> clazz) {
  1687         if (clazz.isAssignableFrom(this))
  1688             return (Class<? extends U>) this;
  1689         else
  1690             throw new ClassCastException(this.toString());
  1691     }
  1692 
  1693     @JavaScriptBody(args = { "ac" }, 
  1694         body = 
  1695           "if (this.anno) {\n"
  1696         + "  var r = this.anno['L' + ac.jvmName + ';'];\n"
  1697         + "  if (typeof r === 'undefined') r = null;\n"
  1698         + "  return r;\n"
  1699         + "} else return null;\n"
  1700     )
  1701     private Object getAnnotationData(Class<?> annotationClass) {
  1702         throw new UnsupportedOperationException();
  1703     }
  1704     /**
  1705      * @throws NullPointerException {@inheritDoc}
  1706      * @since 1.5
  1707      */
  1708     public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
  1709         Object data = getAnnotationData(annotationClass);
  1710         return data == null ? null : AnnotationImpl.create(annotationClass, data);
  1711     }
  1712 
  1713     /**
  1714      * @throws NullPointerException {@inheritDoc}
  1715      * @since 1.5
  1716      */
  1717     @JavaScriptBody(args = { "ac" }, 
  1718         body = "if (this.anno && this.anno['L' + ac.jvmName + ';']) { return true; }"
  1719         + "else return false;"
  1720     )
  1721     public boolean isAnnotationPresent(
  1722         Class<? extends Annotation> annotationClass) {
  1723         if (annotationClass == null)
  1724             throw new NullPointerException();
  1725 
  1726         return getAnnotation(annotationClass) != null;
  1727     }
  1728 
  1729     @JavaScriptBody(args = {}, body = "return this.anno;")
  1730     private Object getAnnotationData() {
  1731         throw new UnsupportedOperationException();
  1732     }
  1733 
  1734     /**
  1735      * @since 1.5
  1736      */
  1737     public Annotation[] getAnnotations() {
  1738         Object data = getAnnotationData();
  1739         return data == null ? new Annotation[0] : AnnotationImpl.create(data);
  1740     }
  1741 
  1742     /**
  1743      * @since 1.5
  1744      */
  1745     public Annotation[] getDeclaredAnnotations()  {
  1746         throw new UnsupportedOperationException();
  1747     }
  1748 
  1749     @JavaScriptBody(args = "type", body = ""
  1750         + "var c = vm.java_lang_Class(true);"
  1751         + "c.jvmName = type;"
  1752         + "c.primitive = true;"
  1753         + "return c;"
  1754     )
  1755     native static Class getPrimitiveClass(String type);
  1756 
  1757     @JavaScriptBody(args = {}, body = 
  1758         "return this['desiredAssertionStatus'] ? this['desiredAssertionStatus'] : false;"
  1759     )
  1760     public native boolean desiredAssertionStatus();
  1761 
  1762     public boolean equals(Object obj) {
  1763         if (isPrimitive() && obj instanceof Class) {
  1764             Class c = ((Class)obj);
  1765             return c.isPrimitive() && getName().equals(c.getName());
  1766         }
  1767         return super.equals(obj);
  1768     }
  1769     
  1770     static void registerNatives() {
  1771         boolean assertsOn = false;
  1772         //       assert assertsOn = true;
  1773         if (assertsOn) {
  1774             try {
  1775                 Array.get(null, 0);
  1776             } catch (Throwable ex) {
  1777                 // ignore
  1778             }
  1779         }
  1780     }
  1781 
  1782     @JavaScriptBody(args = {}, body = "var p = vm.java_lang_Object(false);"
  1783             + "p.toString = function() { return this.toString__Ljava_lang_String_2(); };"
  1784     )
  1785     static native void registerToString();
  1786     
  1787     @JavaScriptBody(args = {"self"}, body
  1788             = "var c = self.constructor.$class;\n"
  1789             + "return c ? c : null;\n"
  1790     )
  1791     static native Class<?> classFor(Object self);
  1792     
  1793     @Exported
  1794     @JavaScriptBody(args = { "self" }, body
  1795             = "if (self['$hashCode']) return self['$hashCode'];\n"
  1796             + "var h = self['computeHashCode__I'] ? self['computeHashCode__I']() : Math.random() * Math.pow(2, 31);\n"
  1797             + "return self['$hashCode'] = h & h;"
  1798     )
  1799     static native int defaultHashCode(Object self);
  1800 
  1801     @JavaScriptBody(args = "self", body
  1802             = "\nif (!self['$instOf_java_lang_Cloneable']) {"
  1803             + "\n  return null;"
  1804             + "\n} else {"
  1805             + "\n  var clone = self.constructor(true);"
  1806             + "\n  var props = Object.getOwnPropertyNames(self);"
  1807             + "\n  for (var i = 0; i < props.length; i++) {"
  1808             + "\n    var p = props[i];"
  1809             + "\n    clone[p] = self[p];"
  1810             + "\n  };"
  1811             + "\n  return clone;"
  1812             + "\n}"
  1813     )
  1814     static native Object clone(Object self) throws CloneNotSupportedException;
  1815 
  1816     @JavaScriptOnly(name = "toJS", value = "function(v) {\n"
  1817         + "  if (v === null) return null;\n"
  1818         + "  if (Object.prototype.toString.call(v) === '[object Array]') {\n"
  1819         + "    return vm.org_apidesign_bck2brwsr_emul_lang_System(false).convArray__Ljava_lang_Object_2Ljava_lang_Object_2(v);\n"
  1820         + "  }\n"
  1821         + "  return v.valueOf();\n"
  1822         + "}\n"
  1823     )
  1824     static native int toJS();
  1825 
  1826     @Exported
  1827     @JavaScriptOnly(name = "activate__Ljava_io_Closeable_2Lorg_apidesign_html_boot_spi_Fn$Presenter_2", value = "function() {\n"
  1828         + "  return vm.org_apidesign_bck2brwsr_emul_lang_System(false).activate__Ljava_io_Closeable_2();"
  1829         + "}\n"
  1830     )
  1831     static native int activate();
  1832 
  1833     @Exported
  1834     @JavaScriptOnly(name = "activate__Ljava_io_Closeable_2Lorg_netbeans_html_boot_spi_Fn$Presenter_2", value = "function() {\n"
  1835         + "  return vm.org_apidesign_bck2brwsr_emul_lang_System(false).activate__Ljava_io_Closeable_2();"
  1836         + "}\n"
  1837     )
  1838     static native int activateNew();
  1839     
  1840     private static Object bck2BrwsrCnvrt(Object o) {
  1841         if (o instanceof Throwable) {
  1842             return o;
  1843         }
  1844         final String msg = msg(o);
  1845         if (msg == null || msg.startsWith("TypeError")) {
  1846             return new NullPointerException(msg);
  1847         }
  1848         return new Throwable(msg);
  1849     }
  1850 
  1851     @JavaScriptBody(args = {"o"}, body = "return o ? o.toString() : null;")
  1852     private static native String msg(Object o);
  1853 
  1854     @Exported
  1855     @JavaScriptOnly(name = "bck2BrwsrThrwrbl", value = "c.bck2BrwsrCnvrt__Ljava_lang_Object_2Ljava_lang_Object_2")
  1856     private static void bck2BrwsrCnvrtVM() {
  1857     }
  1858     
  1859 }