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