emul/mini/src/main/java/java/lang/Class.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 25 Jan 2013 15:47:46 +0100
changeset 586 b670af2aa0f7
parent 573 d3a0383d01d3
child 588 6f864278604a
permissions -rw-r--r--
Class.isEnum supported
     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 org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
    30 import java.io.InputStream;
    31 import java.lang.annotation.Annotation;
    32 import java.lang.reflect.Field;
    33 import java.lang.reflect.Method;
    34 import java.lang.reflect.TypeVariable;
    35 import org.apidesign.bck2brwsr.core.JavaScriptBody;
    36 import org.apidesign.bck2brwsr.emul.reflect.MethodImpl;
    37 
    38 /**
    39  * Instances of the class {@code Class} represent classes and
    40  * interfaces in a running Java application.  An enum is a kind of
    41  * class and an annotation is a kind of interface.  Every array also
    42  * belongs to a class that is reflected as a {@code Class} object
    43  * that is shared by all arrays with the same element type and number
    44  * of dimensions.  The primitive Java types ({@code boolean},
    45  * {@code byte}, {@code char}, {@code short},
    46  * {@code int}, {@code long}, {@code float}, and
    47  * {@code double}), and the keyword {@code void} are also
    48  * represented as {@code Class} objects.
    49  *
    50  * <p> {@code Class} has no public constructor. Instead {@code Class}
    51  * objects are constructed automatically by the Java Virtual Machine as classes
    52  * are loaded and by calls to the {@code defineClass} method in the class
    53  * loader.
    54  *
    55  * <p> The following example uses a {@code Class} object to print the
    56  * class name of an object:
    57  *
    58  * <p> <blockquote><pre>
    59  *     void printClassName(Object obj) {
    60  *         System.out.println("The class of " + obj +
    61  *                            " is " + obj.getClass().getName());
    62  *     }
    63  * </pre></blockquote>
    64  *
    65  * <p> It is also possible to get the {@code Class} object for a named
    66  * type (or for void) using a class literal.  See Section 15.8.2 of
    67  * <cite>The Java&trade; Language Specification</cite>.
    68  * For example:
    69  *
    70  * <p> <blockquote>
    71  *     {@code System.out.println("The name of class Foo is: "+Foo.class.getName());}
    72  * </blockquote>
    73  *
    74  * @param <T> the type of the class modeled by this {@code Class}
    75  * object.  For example, the type of {@code String.class} is {@code
    76  * Class<String>}.  Use {@code Class<?>} if the class being modeled is
    77  * unknown.
    78  *
    79  * @author  unascribed
    80  * @see     java.lang.ClassLoader#defineClass(byte[], int, int)
    81  * @since   JDK1.0
    82  */
    83 public final
    84     class Class<T> implements java.io.Serializable,
    85                               java.lang.reflect.GenericDeclaration,
    86                               java.lang.reflect.Type,
    87                               java.lang.reflect.AnnotatedElement {
    88     private static final int ANNOTATION= 0x00002000;
    89     private static final int ENUM      = 0x00004000;
    90     private static final int SYNTHETIC = 0x00001000;
    91 
    92     /*
    93      * Constructor. Only the Java Virtual Machine creates Class
    94      * objects.
    95      */
    96     private Class() {}
    97 
    98 
    99     /**
   100      * Converts the object to a string. The string representation is the
   101      * string "class" or "interface", followed by a space, and then by the
   102      * fully qualified name of the class in the format returned by
   103      * {@code getName}.  If this {@code Class} object represents a
   104      * primitive type, this method returns the name of the primitive type.  If
   105      * this {@code Class} object represents void this method returns
   106      * "void".
   107      *
   108      * @return a string representation of this class object.
   109      */
   110     public String toString() {
   111         return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
   112             + getName();
   113     }
   114 
   115 
   116     /**
   117      * Returns the {@code Class} object associated with the class or
   118      * interface with the given string name.  Invoking this method is
   119      * equivalent to:
   120      *
   121      * <blockquote>
   122      *  {@code Class.forName(className, true, currentLoader)}
   123      * </blockquote>
   124      *
   125      * where {@code currentLoader} denotes the defining class loader of
   126      * the current class.
   127      *
   128      * <p> For example, the following code fragment returns the
   129      * runtime {@code Class} descriptor for the class named
   130      * {@code java.lang.Thread}:
   131      *
   132      * <blockquote>
   133      *   {@code Class t = Class.forName("java.lang.Thread")}
   134      * </blockquote>
   135      * <p>
   136      * A call to {@code forName("X")} causes the class named
   137      * {@code X} to be initialized.
   138      *
   139      * @param      className   the fully qualified name of the desired class.
   140      * @return     the {@code Class} object for the class with the
   141      *             specified name.
   142      * @exception LinkageError if the linkage fails
   143      * @exception ExceptionInInitializerError if the initialization provoked
   144      *            by this method fails
   145      * @exception ClassNotFoundException if the class cannot be located
   146      */
   147     public static Class<?> forName(String className)
   148     throws ClassNotFoundException {
   149         if (className.startsWith("[")) {
   150             Class<?> arrType = defineArray(className);
   151             Class<?> c = arrType;
   152             while (c != null && c.isArray()) {
   153                 c = c.getComponentType0(); // verify component type is sane
   154             }
   155             return arrType;
   156         }
   157         Class<?> c = loadCls(className, className.replace('.', '_'));
   158         if (c == null) {
   159             throw new ClassNotFoundException(className);
   160         }
   161         return c;
   162     }
   163 
   164 
   165     /**
   166      * Returns the {@code Class} object associated with the class or
   167      * interface with the given string name, using the given class loader.
   168      * Given the fully qualified name for a class or interface (in the same
   169      * format returned by {@code getName}) this method attempts to
   170      * locate, load, and link the class or interface.  The specified class
   171      * loader is used to load the class or interface.  If the parameter
   172      * {@code loader} is null, the class is loaded through the bootstrap
   173      * class loader.  The class is initialized only if the
   174      * {@code initialize} parameter is {@code true} and if it has
   175      * not been initialized earlier.
   176      *
   177      * <p> If {@code name} denotes a primitive type or void, an attempt
   178      * will be made to locate a user-defined class in the unnamed package whose
   179      * name is {@code name}. Therefore, this method cannot be used to
   180      * obtain any of the {@code Class} objects representing primitive
   181      * types or void.
   182      *
   183      * <p> If {@code name} denotes an array class, the component type of
   184      * the array class is loaded but not initialized.
   185      *
   186      * <p> For example, in an instance method the expression:
   187      *
   188      * <blockquote>
   189      *  {@code Class.forName("Foo")}
   190      * </blockquote>
   191      *
   192      * is equivalent to:
   193      *
   194      * <blockquote>
   195      *  {@code Class.forName("Foo", true, this.getClass().getClassLoader())}
   196      * </blockquote>
   197      *
   198      * Note that this method throws errors related to loading, linking or
   199      * initializing as specified in Sections 12.2, 12.3 and 12.4 of <em>The
   200      * Java Language Specification</em>.
   201      * Note that this method does not check whether the requested class
   202      * is accessible to its caller.
   203      *
   204      * <p> If the {@code loader} is {@code null}, and a security
   205      * manager is present, and the caller's class loader is not null, then this
   206      * method calls the security manager's {@code checkPermission} method
   207      * with a {@code RuntimePermission("getClassLoader")} permission to
   208      * ensure it's ok to access the bootstrap class loader.
   209      *
   210      * @param name       fully qualified name of the desired class
   211      * @param initialize whether the class must be initialized
   212      * @param loader     class loader from which the class must be loaded
   213      * @return           class object representing the desired class
   214      *
   215      * @exception LinkageError if the linkage fails
   216      * @exception ExceptionInInitializerError if the initialization provoked
   217      *            by this method fails
   218      * @exception ClassNotFoundException if the class cannot be located by
   219      *            the specified class loader
   220      *
   221      * @see       java.lang.Class#forName(String)
   222      * @see       java.lang.ClassLoader
   223      * @since     1.2
   224      */
   225     public static Class<?> forName(String name, boolean initialize,
   226                                    ClassLoader loader)
   227         throws ClassNotFoundException
   228     {
   229         return forName(name);
   230     }
   231     
   232     @JavaScriptBody(args = {"n", "c" }, body =
   233         "if (vm[c]) return vm[c].$class;\n"
   234       + "if (vm.loadClass) {\n"
   235       + "  vm.loadClass(n);\n"
   236       + "  if (vm[c]) return vm[c].$class;\n"
   237       + "}\n"
   238       + "return null;"
   239     )
   240     private static native Class<?> loadCls(String n, String c);
   241 
   242 
   243     /**
   244      * Creates a new instance of the class represented by this {@code Class}
   245      * object.  The class is instantiated as if by a {@code new}
   246      * expression with an empty argument list.  The class is initialized if it
   247      * has not already been initialized.
   248      *
   249      * <p>Note that this method propagates any exception thrown by the
   250      * nullary constructor, including a checked exception.  Use of
   251      * this method effectively bypasses the compile-time exception
   252      * checking that would otherwise be performed by the compiler.
   253      * The {@link
   254      * java.lang.reflect.Constructor#newInstance(java.lang.Object...)
   255      * Constructor.newInstance} method avoids this problem by wrapping
   256      * any exception thrown by the constructor in a (checked) {@link
   257      * java.lang.reflect.InvocationTargetException}.
   258      *
   259      * @return     a newly allocated instance of the class represented by this
   260      *             object.
   261      * @exception  IllegalAccessException  if the class or its nullary
   262      *               constructor is not accessible.
   263      * @exception  InstantiationException
   264      *               if this {@code Class} represents an abstract class,
   265      *               an interface, an array class, a primitive type, or void;
   266      *               or if the class has no nullary constructor;
   267      *               or if the instantiation fails for some other reason.
   268      * @exception  ExceptionInInitializerError if the initialization
   269      *               provoked by this method fails.
   270      * @exception  SecurityException
   271      *             If a security manager, <i>s</i>, is present and any of the
   272      *             following conditions is met:
   273      *
   274      *             <ul>
   275      *
   276      *             <li> invocation of
   277      *             {@link SecurityManager#checkMemberAccess
   278      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   279      *             creation of new instances of this class
   280      *
   281      *             <li> the caller's class loader is not the same as or an
   282      *             ancestor of the class loader for the current class and
   283      *             invocation of {@link SecurityManager#checkPackageAccess
   284      *             s.checkPackageAccess()} denies access to the package
   285      *             of this class
   286      *
   287      *             </ul>
   288      *
   289      */
   290     @JavaScriptBody(args = { "self", "illegal" }, body =
   291           "\nvar c = self.cnstr;"
   292         + "\nif (c['cons__V']) {"
   293         + "\n  if ((c.cons__V.access & 0x1) != 0) {"
   294         + "\n    var inst = c();"
   295         + "\n    c.cons__V.call(inst);"
   296         + "\n    return inst;"
   297         + "\n  }"
   298         + "\n  return illegal;"
   299         + "\n}"
   300         + "\nreturn null;"
   301     )
   302     private static native Object newInstance0(Class<?> self, Object illegal);
   303     
   304     public T newInstance()
   305         throws InstantiationException, IllegalAccessException
   306     {
   307         Object illegal = new Object();
   308         Object inst = newInstance0(this, illegal);
   309         if (inst == null) {
   310             throw new InstantiationException(getName());
   311         }
   312         if (inst == illegal) {
   313             throw new IllegalAccessException();
   314         }
   315         return (T)inst;
   316     }
   317 
   318     /**
   319      * Determines if the specified {@code Object} is assignment-compatible
   320      * with the object represented by this {@code Class}.  This method is
   321      * the dynamic equivalent of the Java language {@code instanceof}
   322      * operator. The method returns {@code true} if the specified
   323      * {@code Object} argument is non-null and can be cast to the
   324      * reference type represented by this {@code Class} object without
   325      * raising a {@code ClassCastException.} It returns {@code false}
   326      * otherwise.
   327      *
   328      * <p> Specifically, if this {@code Class} object represents a
   329      * declared class, this method returns {@code true} if the specified
   330      * {@code Object} argument is an instance of the represented class (or
   331      * of any of its subclasses); it returns {@code false} otherwise. If
   332      * this {@code Class} object represents an array class, this method
   333      * returns {@code true} if the specified {@code Object} argument
   334      * can be converted to an object of the array class by an identity
   335      * conversion or by a widening reference conversion; it returns
   336      * {@code false} otherwise. If this {@code Class} object
   337      * represents an interface, this method returns {@code true} if the
   338      * class or any superclass of the specified {@code Object} argument
   339      * implements this interface; it returns {@code false} otherwise. If
   340      * this {@code Class} object represents a primitive type, this method
   341      * returns {@code false}.
   342      *
   343      * @param   obj the object to check
   344      * @return  true if {@code obj} is an instance of this class
   345      *
   346      * @since JDK1.1
   347      */
   348     public boolean isInstance(Object obj) {
   349         if (isArray()) {
   350             return isAssignableFrom(obj.getClass());
   351         }
   352         
   353         String prop = "$instOf_" + getName().replace('.', '_');
   354         return hasProperty(obj, prop);
   355     }
   356     
   357     @JavaScriptBody(args = { "who", "prop" }, body = 
   358         "if (who[prop]) return true; else return false;"
   359     )
   360     private static native boolean hasProperty(Object who, String prop);
   361 
   362 
   363     /**
   364      * Determines if the class or interface represented by this
   365      * {@code Class} object is either the same as, or is a superclass or
   366      * superinterface of, the class or interface represented by the specified
   367      * {@code Class} parameter. It returns {@code true} if so;
   368      * otherwise it returns {@code false}. If this {@code Class}
   369      * object represents a primitive type, this method returns
   370      * {@code true} if the specified {@code Class} parameter is
   371      * exactly this {@code Class} object; otherwise it returns
   372      * {@code false}.
   373      *
   374      * <p> Specifically, this method tests whether the type represented by the
   375      * specified {@code Class} parameter can be converted to the type
   376      * represented by this {@code Class} object via an identity conversion
   377      * or via a widening reference conversion. See <em>The Java Language
   378      * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
   379      *
   380      * @param cls the {@code Class} object to be checked
   381      * @return the {@code boolean} value indicating whether objects of the
   382      * type {@code cls} can be assigned to objects of this class
   383      * @exception NullPointerException if the specified Class parameter is
   384      *            null.
   385      * @since JDK1.1
   386      */
   387     public boolean isAssignableFrom(Class<?> cls) {
   388         if (this == cls) {
   389             return true;
   390         }
   391         
   392         if (isArray()) {
   393             final Class<?> cmpType = cls.getComponentType();
   394             if (isPrimitive()) {
   395                 return this == cmpType;
   396             }
   397             return cmpType != null && getComponentType().isAssignableFrom(cmpType);
   398         }
   399         String prop = "$instOf_" + getName().replace('.', '_');
   400         return hasProperty(cls, prop);
   401     }
   402 
   403 
   404     /**
   405      * Determines if the specified {@code Class} object represents an
   406      * interface type.
   407      *
   408      * @return  {@code true} if this object represents an interface;
   409      *          {@code false} otherwise.
   410      */
   411     public boolean isInterface() {
   412         return (getAccess() & 0x200) != 0;
   413     }
   414     
   415     @JavaScriptBody(args = {}, body = "return this.access;")
   416     private native int getAccess();
   417 
   418 
   419     /**
   420      * Determines if this {@code Class} object represents an array class.
   421      *
   422      * @return  {@code true} if this object represents an array class;
   423      *          {@code false} otherwise.
   424      * @since   JDK1.1
   425      */
   426     public boolean isArray() {
   427         return hasProperty(this, "array"); // NOI18N
   428     }
   429 
   430 
   431     /**
   432      * Determines if the specified {@code Class} object represents a
   433      * primitive type.
   434      *
   435      * <p> There are nine predefined {@code Class} objects to represent
   436      * the eight primitive types and void.  These are created by the Java
   437      * Virtual Machine, and have the same names as the primitive types that
   438      * they represent, namely {@code boolean}, {@code byte},
   439      * {@code char}, {@code short}, {@code int},
   440      * {@code long}, {@code float}, and {@code double}.
   441      *
   442      * <p> These objects may only be accessed via the following public static
   443      * final variables, and are the only {@code Class} objects for which
   444      * this method returns {@code true}.
   445      *
   446      * @return true if and only if this class represents a primitive type
   447      *
   448      * @see     java.lang.Boolean#TYPE
   449      * @see     java.lang.Character#TYPE
   450      * @see     java.lang.Byte#TYPE
   451      * @see     java.lang.Short#TYPE
   452      * @see     java.lang.Integer#TYPE
   453      * @see     java.lang.Long#TYPE
   454      * @see     java.lang.Float#TYPE
   455      * @see     java.lang.Double#TYPE
   456      * @see     java.lang.Void#TYPE
   457      * @since JDK1.1
   458      */
   459     @JavaScriptBody(args = {}, body = 
   460            "if (this.primitive) return true;"
   461         + "else return false;"
   462     )
   463     public native boolean isPrimitive();
   464 
   465     /**
   466      * Returns true if this {@code Class} object represents an annotation
   467      * type.  Note that if this method returns true, {@link #isInterface()}
   468      * would also return true, as all annotation types are also interfaces.
   469      *
   470      * @return {@code true} if this class object represents an annotation
   471      *      type; {@code false} otherwise
   472      * @since 1.5
   473      */
   474     public boolean isAnnotation() {
   475         return (getModifiers() & ANNOTATION) != 0;
   476     }
   477 
   478     /**
   479      * Returns {@code true} if this class is a synthetic class;
   480      * returns {@code false} otherwise.
   481      * @return {@code true} if and only if this class is a synthetic class as
   482      *         defined by the Java Language Specification.
   483      * @since 1.5
   484      */
   485     public boolean isSynthetic() {
   486         return (getModifiers() & SYNTHETIC) != 0;
   487     }
   488 
   489     /**
   490      * Returns the  name of the entity (class, interface, array class,
   491      * primitive type, or void) represented by this {@code Class} object,
   492      * as a {@code String}.
   493      *
   494      * <p> If this class object represents a reference type that is not an
   495      * array type then the binary name of the class is returned, as specified
   496      * by
   497      * <cite>The Java&trade; Language Specification</cite>.
   498      *
   499      * <p> If this class object represents a primitive type or void, then the
   500      * name returned is a {@code String} equal to the Java language
   501      * keyword corresponding to the primitive type or void.
   502      *
   503      * <p> If this class object represents a class of arrays, then the internal
   504      * form of the name consists of the name of the element type preceded by
   505      * one or more '{@code [}' characters representing the depth of the array
   506      * nesting.  The encoding of element type names is as follows:
   507      *
   508      * <blockquote><table summary="Element types and encodings">
   509      * <tr><th> Element Type <th> &nbsp;&nbsp;&nbsp; <th> Encoding
   510      * <tr><td> boolean      <td> &nbsp;&nbsp;&nbsp; <td align=center> Z
   511      * <tr><td> byte         <td> &nbsp;&nbsp;&nbsp; <td align=center> B
   512      * <tr><td> char         <td> &nbsp;&nbsp;&nbsp; <td align=center> C
   513      * <tr><td> class or interface
   514      *                       <td> &nbsp;&nbsp;&nbsp; <td align=center> L<i>classname</i>;
   515      * <tr><td> double       <td> &nbsp;&nbsp;&nbsp; <td align=center> D
   516      * <tr><td> float        <td> &nbsp;&nbsp;&nbsp; <td align=center> F
   517      * <tr><td> int          <td> &nbsp;&nbsp;&nbsp; <td align=center> I
   518      * <tr><td> long         <td> &nbsp;&nbsp;&nbsp; <td align=center> J
   519      * <tr><td> short        <td> &nbsp;&nbsp;&nbsp; <td align=center> S
   520      * </table></blockquote>
   521      *
   522      * <p> The class or interface name <i>classname</i> is the binary name of
   523      * the class specified above.
   524      *
   525      * <p> Examples:
   526      * <blockquote><pre>
   527      * String.class.getName()
   528      *     returns "java.lang.String"
   529      * byte.class.getName()
   530      *     returns "byte"
   531      * (new Object[3]).getClass().getName()
   532      *     returns "[Ljava.lang.Object;"
   533      * (new int[3][4][5][6][7][8][9]).getClass().getName()
   534      *     returns "[[[[[[[I"
   535      * </pre></blockquote>
   536      *
   537      * @return  the name of the class or interface
   538      *          represented by this object.
   539      */
   540     public String getName() {
   541         return jvmName().replace('/', '.');
   542     }
   543 
   544     @JavaScriptBody(args = {}, body = "return this.jvmName;")
   545     private native String jvmName();
   546 
   547     
   548     /**
   549      * Returns an array of {@code TypeVariable} objects that represent the
   550      * type variables declared by the generic declaration represented by this
   551      * {@code GenericDeclaration} object, in declaration order.  Returns an
   552      * array of length 0 if the underlying generic declaration declares no type
   553      * variables.
   554      *
   555      * @return an array of {@code TypeVariable} objects that represent
   556      *     the type variables declared by this generic declaration
   557      * @throws java.lang.reflect.GenericSignatureFormatError if the generic
   558      *     signature of this generic declaration does not conform to
   559      *     the format specified in
   560      *     <cite>The Java&trade; Virtual Machine Specification</cite>
   561      * @since 1.5
   562      */
   563     public TypeVariable<Class<T>>[] getTypeParameters() {
   564         throw new UnsupportedOperationException();
   565     }
   566  
   567     /**
   568      * Returns the {@code Class} representing the superclass of the entity
   569      * (class, interface, primitive type or void) represented by this
   570      * {@code Class}.  If this {@code Class} represents either the
   571      * {@code Object} class, an interface, a primitive type, or void, then
   572      * null is returned.  If this object represents an array class then the
   573      * {@code Class} object representing the {@code Object} class is
   574      * returned.
   575      *
   576      * @return the superclass of the class represented by this object.
   577      */
   578     @JavaScriptBody(args = {}, body = "return this.superclass;")
   579     public native Class<? super T> getSuperclass();
   580 
   581     /**
   582      * Returns the Java language modifiers for this class or interface, encoded
   583      * in an integer. The modifiers consist of the Java Virtual Machine's
   584      * constants for {@code public}, {@code protected},
   585      * {@code private}, {@code final}, {@code static},
   586      * {@code abstract} and {@code interface}; they should be decoded
   587      * using the methods of class {@code Modifier}.
   588      *
   589      * <p> If the underlying class is an array class, then its
   590      * {@code public}, {@code private} and {@code protected}
   591      * modifiers are the same as those of its component type.  If this
   592      * {@code Class} represents a primitive type or void, its
   593      * {@code public} modifier is always {@code true}, and its
   594      * {@code protected} and {@code private} modifiers are always
   595      * {@code false}. If this object represents an array class, a
   596      * primitive type or void, then its {@code final} modifier is always
   597      * {@code true} and its interface modifier is always
   598      * {@code false}. The values of its other modifiers are not determined
   599      * by this specification.
   600      *
   601      * <p> The modifier encodings are defined in <em>The Java Virtual Machine
   602      * Specification</em>, table 4.1.
   603      *
   604      * @return the {@code int} representing the modifiers for this class
   605      * @see     java.lang.reflect.Modifier
   606      * @since JDK1.1
   607      */
   608     public int getModifiers() {
   609         return getAccess();
   610     }
   611 
   612 
   613     /**
   614      * Returns the simple name of the underlying class as given in the
   615      * source code. Returns an empty string if the underlying class is
   616      * anonymous.
   617      *
   618      * <p>The simple name of an array is the simple name of the
   619      * component type with "[]" appended.  In particular the simple
   620      * name of an array whose component type is anonymous is "[]".
   621      *
   622      * @return the simple name of the underlying class
   623      * @since 1.5
   624      */
   625     public String getSimpleName() {
   626         if (isArray())
   627             return getComponentType().getSimpleName()+"[]";
   628 
   629         String simpleName = getSimpleBinaryName();
   630         if (simpleName == null) { // top level class
   631             simpleName = getName();
   632             return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
   633         }
   634         // According to JLS3 "Binary Compatibility" (13.1) the binary
   635         // name of non-package classes (not top level) is the binary
   636         // name of the immediately enclosing class followed by a '$' followed by:
   637         // (for nested and inner classes): the simple name.
   638         // (for local classes): 1 or more digits followed by the simple name.
   639         // (for anonymous classes): 1 or more digits.
   640 
   641         // Since getSimpleBinaryName() will strip the binary name of
   642         // the immediatly enclosing class, we are now looking at a
   643         // string that matches the regular expression "\$[0-9]*"
   644         // followed by a simple name (considering the simple of an
   645         // anonymous class to be the empty string).
   646 
   647         // Remove leading "\$[0-9]*" from the name
   648         int length = simpleName.length();
   649         if (length < 1 || simpleName.charAt(0) != '$')
   650             throw new IllegalStateException("Malformed class name");
   651         int index = 1;
   652         while (index < length && isAsciiDigit(simpleName.charAt(index)))
   653             index++;
   654         // Eventually, this is the empty string iff this is an anonymous class
   655         return simpleName.substring(index);
   656     }
   657 
   658     /**
   659      * Returns the "simple binary name" of the underlying class, i.e.,
   660      * the binary name without the leading enclosing class name.
   661      * Returns {@code null} if the underlying class is a top level
   662      * class.
   663      */
   664     private String getSimpleBinaryName() {
   665         Class<?> enclosingClass = null; // XXX getEnclosingClass();
   666         if (enclosingClass == null) // top level class
   667             return null;
   668         // Otherwise, strip the enclosing class' name
   669         try {
   670             return getName().substring(enclosingClass.getName().length());
   671         } catch (IndexOutOfBoundsException ex) {
   672             throw new IllegalStateException("Malformed class name");
   673         }
   674     }
   675 
   676     /**
   677      * Returns an array containing {@code Field} objects reflecting all
   678      * the accessible public fields of the class or interface represented by
   679      * this {@code Class} object.  The elements in the array returned are
   680      * not sorted and are not in any particular order.  This method returns an
   681      * array of length 0 if the class or interface has no accessible public
   682      * fields, or if it represents an array class, a primitive type, or void.
   683      *
   684      * <p> Specifically, if this {@code Class} object represents a class,
   685      * this method returns the public fields of this class and of all its
   686      * superclasses.  If this {@code Class} object represents an
   687      * interface, this method returns the fields of this interface and of all
   688      * its superinterfaces.
   689      *
   690      * <p> The implicit length field for array class is not reflected by this
   691      * method. User code should use the methods of class {@code Array} to
   692      * manipulate arrays.
   693      *
   694      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
   695      *
   696      * @return the array of {@code Field} objects representing the
   697      * public fields
   698      * @exception  SecurityException
   699      *             If a security manager, <i>s</i>, is present and any of the
   700      *             following conditions is met:
   701      *
   702      *             <ul>
   703      *
   704      *             <li> invocation of
   705      *             {@link SecurityManager#checkMemberAccess
   706      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   707      *             access to the fields within this class
   708      *
   709      *             <li> the caller's class loader is not the same as or an
   710      *             ancestor of the class loader for the current class and
   711      *             invocation of {@link SecurityManager#checkPackageAccess
   712      *             s.checkPackageAccess()} denies access to the package
   713      *             of this class
   714      *
   715      *             </ul>
   716      *
   717      * @since JDK1.1
   718      */
   719     public Field[] getFields() throws SecurityException {
   720         throw new SecurityException();
   721     }
   722 
   723     /**
   724      * Returns an array containing {@code Method} objects reflecting all
   725      * the public <em>member</em> methods of the class or interface represented
   726      * by this {@code Class} object, including those declared by the class
   727      * or interface and those inherited from superclasses and
   728      * superinterfaces.  Array classes return all the (public) member methods
   729      * inherited from the {@code Object} class.  The elements in the array
   730      * returned are not sorted and are not in any particular order.  This
   731      * method returns an array of length 0 if this {@code Class} object
   732      * represents a class or interface that has no public member methods, or if
   733      * this {@code Class} object represents a primitive type or void.
   734      *
   735      * <p> The class initialization method {@code <clinit>} is not
   736      * included in the returned array. If the class declares multiple public
   737      * member methods with the same parameter types, they are all included in
   738      * the returned array.
   739      *
   740      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
   741      *
   742      * @return the array of {@code Method} objects representing the
   743      * public methods of this class
   744      * @exception  SecurityException
   745      *             If a security manager, <i>s</i>, is present and any of the
   746      *             following conditions is met:
   747      *
   748      *             <ul>
   749      *
   750      *             <li> invocation of
   751      *             {@link SecurityManager#checkMemberAccess
   752      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   753      *             access to the methods within this class
   754      *
   755      *             <li> the caller's class loader is not the same as or an
   756      *             ancestor of the class loader for the current class and
   757      *             invocation of {@link SecurityManager#checkPackageAccess
   758      *             s.checkPackageAccess()} denies access to the package
   759      *             of this class
   760      *
   761      *             </ul>
   762      *
   763      * @since JDK1.1
   764      */
   765     public Method[] getMethods() throws SecurityException {
   766         return MethodImpl.findMethods(this, 0x01);
   767     }
   768 
   769     /**
   770      * Returns a {@code Field} object that reflects the specified public
   771      * member field of the class or interface represented by this
   772      * {@code Class} object. The {@code name} parameter is a
   773      * {@code String} specifying the simple name of the desired field.
   774      *
   775      * <p> The field to be reflected is determined by the algorithm that
   776      * follows.  Let C be the class represented by this object:
   777      * <OL>
   778      * <LI> If C declares a public field with the name specified, that is the
   779      *      field to be reflected.</LI>
   780      * <LI> If no field was found in step 1 above, this algorithm is applied
   781      *      recursively to each direct superinterface of C. The direct
   782      *      superinterfaces are searched in the order they were declared.</LI>
   783      * <LI> If no field was found in steps 1 and 2 above, and C has a
   784      *      superclass S, then this algorithm is invoked recursively upon S.
   785      *      If C has no superclass, then a {@code NoSuchFieldException}
   786      *      is thrown.</LI>
   787      * </OL>
   788      *
   789      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
   790      *
   791      * @param name the field name
   792      * @return  the {@code Field} object of this class specified by
   793      * {@code name}
   794      * @exception NoSuchFieldException if a field with the specified name is
   795      *              not found.
   796      * @exception NullPointerException if {@code name} is {@code null}
   797      * @exception  SecurityException
   798      *             If a security manager, <i>s</i>, is present and any of the
   799      *             following conditions is met:
   800      *
   801      *             <ul>
   802      *
   803      *             <li> invocation of
   804      *             {@link SecurityManager#checkMemberAccess
   805      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   806      *             access to the field
   807      *
   808      *             <li> the caller's class loader is not the same as or an
   809      *             ancestor of the class loader for the current class and
   810      *             invocation of {@link SecurityManager#checkPackageAccess
   811      *             s.checkPackageAccess()} denies access to the package
   812      *             of this class
   813      *
   814      *             </ul>
   815      *
   816      * @since JDK1.1
   817      */
   818     public Field getField(String name)
   819         throws SecurityException {
   820         throw new SecurityException();
   821     }
   822     
   823     
   824     /**
   825      * Returns a {@code Method} object that reflects the specified public
   826      * member method 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 method. The
   829      * {@code parameterTypes} parameter is an array of {@code Class}
   830      * objects that identify the method's formal parameter types, in declared
   831      * order. If {@code parameterTypes} is {@code null}, it is
   832      * treated as if it were an empty array.
   833      *
   834      * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
   835      * {@code NoSuchMethodException} is raised. Otherwise, the method to
   836      * be reflected is determined by the algorithm that follows.  Let C be the
   837      * class represented by this object:
   838      * <OL>
   839      * <LI> C is searched for any <I>matching methods</I>. If no matching
   840      *      method is found, the algorithm of step 1 is invoked recursively on
   841      *      the superclass of C.</LI>
   842      * <LI> If no method was found in step 1 above, the superinterfaces of C
   843      *      are searched for a matching method. If any such method is found, it
   844      *      is reflected.</LI>
   845      * </OL>
   846      *
   847      * To find a matching method in a class C:&nbsp; If C declares exactly one
   848      * public method with the specified name and exactly the same formal
   849      * parameter types, that is the method reflected. If more than one such
   850      * method is found in C, and one of these methods has a return type that is
   851      * more specific than any of the others, that method is reflected;
   852      * otherwise one of the methods is chosen arbitrarily.
   853      *
   854      * <p>Note that there may be more than one matching method in a
   855      * class because while the Java language forbids a class to
   856      * declare multiple methods with the same signature but different
   857      * return types, the Java virtual machine does not.  This
   858      * increased flexibility in the virtual machine can be used to
   859      * implement various language features.  For example, covariant
   860      * returns can be implemented with {@linkplain
   861      * java.lang.reflect.Method#isBridge bridge methods}; the bridge
   862      * method and the method being overridden would have the same
   863      * signature but different return types.
   864      *
   865      * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
   866      *
   867      * @param name the name of the method
   868      * @param parameterTypes the list of parameters
   869      * @return the {@code Method} object that matches the specified
   870      * {@code name} and {@code parameterTypes}
   871      * @exception NoSuchMethodException if a matching method is not found
   872      *            or if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
   873      * @exception NullPointerException if {@code name} is {@code null}
   874      * @exception  SecurityException
   875      *             If a security manager, <i>s</i>, is present and any of the
   876      *             following conditions is met:
   877      *
   878      *             <ul>
   879      *
   880      *             <li> invocation of
   881      *             {@link SecurityManager#checkMemberAccess
   882      *             s.checkMemberAccess(this, Member.PUBLIC)} denies
   883      *             access to the method
   884      *
   885      *             <li> the caller's class loader is not the same as or an
   886      *             ancestor of the class loader for the current class and
   887      *             invocation of {@link SecurityManager#checkPackageAccess
   888      *             s.checkPackageAccess()} denies access to the package
   889      *             of this class
   890      *
   891      *             </ul>
   892      *
   893      * @since JDK1.1
   894      */
   895     public Method getMethod(String name, Class<?>... parameterTypes)
   896         throws SecurityException, NoSuchMethodException {
   897         Method m = MethodImpl.findMethod(this, name, parameterTypes);
   898         if (m == null) {
   899             StringBuilder sb = new StringBuilder();
   900             sb.append(getName()).append('.').append(name).append('(');
   901             String sep = "";
   902             for (int i = 0; i < parameterTypes.length; i++) {
   903                 sb.append(sep).append(parameterTypes[i].getName());
   904                 sep = ", ";
   905             }
   906             sb.append(')');
   907             throw new NoSuchMethodException(sb.toString());
   908         }
   909         return m;
   910     }
   911 
   912     /**
   913      * Character.isDigit answers {@code true} to some non-ascii
   914      * digits.  This one does not.
   915      */
   916     private static boolean isAsciiDigit(char c) {
   917         return '0' <= c && c <= '9';
   918     }
   919 
   920     /**
   921      * Returns the canonical name of the underlying class as
   922      * defined by the Java Language Specification.  Returns null if
   923      * the underlying class does not have a canonical name (i.e., if
   924      * it is a local or anonymous class or an array whose component
   925      * type does not have a canonical name).
   926      * @return the canonical name of the underlying class if it exists, and
   927      * {@code null} otherwise.
   928      * @since 1.5
   929      */
   930     public String getCanonicalName() {
   931         if (isArray()) {
   932             String canonicalName = getComponentType().getCanonicalName();
   933             if (canonicalName != null)
   934                 return canonicalName + "[]";
   935             else
   936                 return null;
   937         }
   938 //        if (isLocalOrAnonymousClass())
   939 //            return null;
   940 //        Class<?> enclosingClass = getEnclosingClass();
   941         Class<?> enclosingClass = null;
   942         if (enclosingClass == null) { // top level class
   943             return getName();
   944         } else {
   945             String enclosingName = enclosingClass.getCanonicalName();
   946             if (enclosingName == null)
   947                 return null;
   948             return enclosingName + "." + getSimpleName();
   949         }
   950     }
   951 
   952     /**
   953      * Finds a resource with a given name.  The rules for searching resources
   954      * associated with a given class are implemented by the defining
   955      * {@linkplain ClassLoader class loader} of the class.  This method
   956      * delegates to this object's class loader.  If this object was loaded by
   957      * the bootstrap class loader, the method delegates to {@link
   958      * ClassLoader#getSystemResourceAsStream}.
   959      *
   960      * <p> Before delegation, an absolute resource name is constructed from the
   961      * given resource name using this algorithm:
   962      *
   963      * <ul>
   964      *
   965      * <li> If the {@code name} begins with a {@code '/'}
   966      * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
   967      * portion of the {@code name} following the {@code '/'}.
   968      *
   969      * <li> Otherwise, the absolute name is of the following form:
   970      *
   971      * <blockquote>
   972      *   {@code modified_package_name/name}
   973      * </blockquote>
   974      *
   975      * <p> Where the {@code modified_package_name} is the package name of this
   976      * object with {@code '/'} substituted for {@code '.'}
   977      * (<tt>'&#92;u002e'</tt>).
   978      *
   979      * </ul>
   980      *
   981      * @param  name name of the desired resource
   982      * @return      A {@link java.io.InputStream} object or {@code null} if
   983      *              no resource with this name is found
   984      * @throws  NullPointerException If {@code name} is {@code null}
   985      * @since  JDK1.1
   986      */
   987      public InputStream getResourceAsStream(String name) {
   988         name = resolveName(name);
   989         byte[] arr = getResourceAsStream0(name);
   990         return arr == null ? null : new ByteArrayInputStream(arr);
   991      }
   992      
   993      @JavaScriptBody(args = "name", body = 
   994          "return (vm.loadBytes) ? vm.loadBytes(name) : null;"
   995      )
   996      private static native byte[] getResourceAsStream0(String name);
   997 
   998     /**
   999      * Finds a resource with a given name.  The rules for searching resources
  1000      * associated with a given class are implemented by the defining
  1001      * {@linkplain ClassLoader class loader} of the class.  This method
  1002      * delegates to this object's class loader.  If this object was loaded by
  1003      * the bootstrap class loader, the method delegates to {@link
  1004      * ClassLoader#getSystemResource}.
  1005      *
  1006      * <p> Before delegation, an absolute resource name is constructed from the
  1007      * given resource name using this algorithm:
  1008      *
  1009      * <ul>
  1010      *
  1011      * <li> If the {@code name} begins with a {@code '/'}
  1012      * (<tt>'&#92;u002f'</tt>), then the absolute name of the resource is the
  1013      * portion of the {@code name} following the {@code '/'}.
  1014      *
  1015      * <li> Otherwise, the absolute name is of the following form:
  1016      *
  1017      * <blockquote>
  1018      *   {@code modified_package_name/name}
  1019      * </blockquote>
  1020      *
  1021      * <p> Where the {@code modified_package_name} is the package name of this
  1022      * object with {@code '/'} substituted for {@code '.'}
  1023      * (<tt>'&#92;u002e'</tt>).
  1024      *
  1025      * </ul>
  1026      *
  1027      * @param  name name of the desired resource
  1028      * @return      A  {@link java.net.URL} object or {@code null} if no
  1029      *              resource with this name is found
  1030      * @since  JDK1.1
  1031      */
  1032     public java.net.URL getResource(String name) {
  1033         name = resolveName(name);
  1034         ClassLoader cl = null;
  1035         if (cl==null) {
  1036             // A system class.
  1037             return ClassLoader.getSystemResource(name);
  1038         }
  1039         return cl.getResource(name);
  1040     }
  1041 
  1042 
  1043    /**
  1044      * Add a package name prefix if the name is not absolute Remove leading "/"
  1045      * if name is absolute
  1046      */
  1047     private String resolveName(String name) {
  1048         if (name == null) {
  1049             return name;
  1050         }
  1051         if (!name.startsWith("/")) {
  1052             Class<?> c = this;
  1053             while (c.isArray()) {
  1054                 c = c.getComponentType();
  1055             }
  1056             String baseName = c.getName();
  1057             int index = baseName.lastIndexOf('.');
  1058             if (index != -1) {
  1059                 name = baseName.substring(0, index).replace('.', '/')
  1060                     +"/"+name;
  1061             }
  1062         } else {
  1063             name = name.substring(1);
  1064         }
  1065         return name;
  1066     }
  1067     
  1068     /**
  1069      * Returns the class loader for the class.  Some implementations may use
  1070      * null to represent the bootstrap class loader. This method will return
  1071      * null in such implementations if this class was loaded by the bootstrap
  1072      * class loader.
  1073      *
  1074      * <p> If a security manager is present, and the caller's class loader is
  1075      * not null and the caller's class loader is not the same as or an ancestor of
  1076      * the class loader for the class whose class loader is requested, then
  1077      * this method calls the security manager's {@code checkPermission}
  1078      * method with a {@code RuntimePermission("getClassLoader")}
  1079      * permission to ensure it's ok to access the class loader for the class.
  1080      *
  1081      * <p>If this object
  1082      * represents a primitive type or void, null is returned.
  1083      *
  1084      * @return  the class loader that loaded the class or interface
  1085      *          represented by this object.
  1086      * @throws SecurityException
  1087      *    if a security manager exists and its
  1088      *    {@code checkPermission} method denies
  1089      *    access to the class loader for the class.
  1090      * @see java.lang.ClassLoader
  1091      * @see SecurityManager#checkPermission
  1092      * @see java.lang.RuntimePermission
  1093      */
  1094     public ClassLoader getClassLoader() {
  1095         throw new SecurityException();
  1096     }
  1097     
  1098     /**
  1099      * Returns the {@code Class} representing the component type of an
  1100      * array.  If this class does not represent an array class this method
  1101      * returns null.
  1102      *
  1103      * @return the {@code Class} representing the component type of this
  1104      * class if this class is an array
  1105      * @see     java.lang.reflect.Array
  1106      * @since JDK1.1
  1107      */
  1108     public Class<?> getComponentType() {
  1109         if (isArray()) {
  1110             try {
  1111                 return getComponentType0();
  1112             } catch (ClassNotFoundException cnfe) {
  1113                 throw new IllegalStateException(cnfe);
  1114             }
  1115         }
  1116         return null;
  1117     }
  1118 
  1119     private Class<?> getComponentType0() throws ClassNotFoundException {
  1120         String n = getName().substring(1);
  1121         switch (n.charAt(0)) {
  1122             case 'L': 
  1123                 n = n.substring(1, n.length() - 1);
  1124                 return Class.forName(n);
  1125             case 'I':
  1126                 return Integer.TYPE;
  1127             case 'J':
  1128                 return Long.TYPE;
  1129             case 'D':
  1130                 return Double.TYPE;
  1131             case 'F':
  1132                 return Float.TYPE;
  1133             case 'B':
  1134                 return Byte.TYPE;
  1135             case 'Z':
  1136                 return Boolean.TYPE;
  1137             case 'S':
  1138                 return Short.TYPE;
  1139             case 'V':
  1140                 return Void.TYPE;
  1141             case 'C':
  1142                 return Character.TYPE;
  1143             case '[':
  1144                 return defineArray(n);
  1145             default:
  1146                 throw new ClassNotFoundException("Unknown component type of " + getName());
  1147         }
  1148     }
  1149     
  1150     @JavaScriptBody(args = { "sig" }, body = 
  1151         "var c = Array[sig];\n" +
  1152         "if (c) return c;\n" +
  1153         "c = vm.java_lang_Class(true);\n" +
  1154         "c.jvmName = sig;\n" +
  1155         "c.superclass = vm.java_lang_Object(false).$class;\n" +
  1156         "c.array = true;\n" +
  1157         "Array[sig] = c;\n" +
  1158         "return c;"
  1159     )
  1160     private static native Class<?> defineArray(String sig);
  1161     
  1162     /**
  1163      * Returns true if and only if this class was declared as an enum in the
  1164      * source code.
  1165      *
  1166      * @return true if and only if this class was declared as an enum in the
  1167      *     source code
  1168      * @since 1.5
  1169      */
  1170     public boolean isEnum() {
  1171         // An enum must both directly extend java.lang.Enum and have
  1172         // the ENUM bit set; classes for specialized enum constants
  1173         // don't do the former.
  1174         return (this.getModifiers() & ENUM) != 0 &&
  1175         this.getSuperclass() == java.lang.Enum.class;
  1176     }
  1177 
  1178     /**
  1179      * Casts an object to the class or interface represented
  1180      * by this {@code Class} object.
  1181      *
  1182      * @param obj the object to be cast
  1183      * @return the object after casting, or null if obj is null
  1184      *
  1185      * @throws ClassCastException if the object is not
  1186      * null and is not assignable to the type T.
  1187      *
  1188      * @since 1.5
  1189      */
  1190     public T cast(Object obj) {
  1191         if (obj != null && !isInstance(obj))
  1192             throw new ClassCastException(cannotCastMsg(obj));
  1193         return (T) obj;
  1194     }
  1195 
  1196     private String cannotCastMsg(Object obj) {
  1197         return "Cannot cast " + obj.getClass().getName() + " to " + getName();
  1198     }
  1199 
  1200     /**
  1201      * Casts this {@code Class} object to represent a subclass of the class
  1202      * represented by the specified class object.  Checks that that the cast
  1203      * is valid, and throws a {@code ClassCastException} if it is not.  If
  1204      * this method succeeds, it always returns a reference to this class object.
  1205      *
  1206      * <p>This method is useful when a client needs to "narrow" the type of
  1207      * a {@code Class} object to pass it to an API that restricts the
  1208      * {@code Class} objects that it is willing to accept.  A cast would
  1209      * generate a compile-time warning, as the correctness of the cast
  1210      * could not be checked at runtime (because generic types are implemented
  1211      * by erasure).
  1212      *
  1213      * @return this {@code Class} object, cast to represent a subclass of
  1214      *    the specified class object.
  1215      * @throws ClassCastException if this {@code Class} object does not
  1216      *    represent a subclass of the specified class (here "subclass" includes
  1217      *    the class itself).
  1218      * @since 1.5
  1219      */
  1220     public <U> Class<? extends U> asSubclass(Class<U> clazz) {
  1221         if (clazz.isAssignableFrom(this))
  1222             return (Class<? extends U>) this;
  1223         else
  1224             throw new ClassCastException(this.toString());
  1225     }
  1226 
  1227     @JavaScriptBody(args = { "ac" }, 
  1228         body = 
  1229           "if (this.anno) {"
  1230         + "  return this.anno['L' + ac.jvmName + ';'];"
  1231         + "} else return null;"
  1232     )
  1233     private Object getAnnotationData(Class<?> annotationClass) {
  1234         throw new UnsupportedOperationException();
  1235     }
  1236     /**
  1237      * @throws NullPointerException {@inheritDoc}
  1238      * @since 1.5
  1239      */
  1240     public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
  1241         Object data = getAnnotationData(annotationClass);
  1242         return data == null ? null : AnnotationImpl.create(annotationClass, data);
  1243     }
  1244 
  1245     /**
  1246      * @throws NullPointerException {@inheritDoc}
  1247      * @since 1.5
  1248      */
  1249     @JavaScriptBody(args = { "ac" }, 
  1250         body = "if (this.anno && this.anno['L' + ac.jvmName + ';']) { return true; }"
  1251         + "else return false;"
  1252     )
  1253     public boolean isAnnotationPresent(
  1254         Class<? extends Annotation> annotationClass) {
  1255         if (annotationClass == null)
  1256             throw new NullPointerException();
  1257 
  1258         return getAnnotation(annotationClass) != null;
  1259     }
  1260 
  1261     @JavaScriptBody(args = {}, body = "return this.anno;")
  1262     private Object getAnnotationData() {
  1263         throw new UnsupportedOperationException();
  1264     }
  1265 
  1266     /**
  1267      * @since 1.5
  1268      */
  1269     public Annotation[] getAnnotations() {
  1270         Object data = getAnnotationData();
  1271         return data == null ? new Annotation[0] : AnnotationImpl.create(data);
  1272     }
  1273 
  1274     /**
  1275      * @since 1.5
  1276      */
  1277     public Annotation[] getDeclaredAnnotations()  {
  1278         throw new UnsupportedOperationException();
  1279     }
  1280 
  1281     @JavaScriptBody(args = "type", body = ""
  1282         + "var c = vm.java_lang_Class(true);"
  1283         + "c.jvmName = type;"
  1284         + "c.primitive = true;"
  1285         + "return c;"
  1286     )
  1287     native static Class getPrimitiveClass(String type);
  1288 
  1289     @JavaScriptBody(args = {}, body = 
  1290         "return vm.desiredAssertionStatus ? vm.desiredAssertionStatus : false;"
  1291     )
  1292     public native boolean desiredAssertionStatus();
  1293 }