1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
// java.lang.Class
// An implementation of the Java Language Specification section 20.3
// Written by Charles Briscoe-Smith; refer to the file LEGAL for details.
package java.lang;
public final class Class {
public String toString()
{
return (isInterface() ? "interface " : "class ") + getName();
}
public String getName()
{
if (className==null) {
if (componentclass==null) {
// No name and not an array?
throw new InternalError();
}
if (componentclass.isArray) {
className="["+componentclass.getName();
} else {
className="[L"+componentclass.getName()+";";
}
}
return className;
}
public boolean isInterface()
{
return isIface;
}
private String className;
private boolean isIface;
private boolean isArray;
private Class superclass;
private Class componentclass;
private Class[] superInterfaces;
private static Class objectclass;
public Class getSuperclass()
{
return superclass;
}
public Class[] getInterfaces()
{
Class[] ret=new Class[superInterfaces.length];
for (int i=0; i<ret.length; i++) {
ret[i]=superInterfaces[i];
}
return ret;
}
public Object newInstance()
throws InstantiationException, IllegalAccessException
{
throw new InstantiationException();
}
public ClassLoader getClassLoader()
{
// No class has a classloader
return null;
}
public static Class forName(String className)
throws ClassNotFoundException
{
throw new ClassNotFoundException();
}
// Used internally to track the initialisation state of the class
// 1 = not yet initialised
// 0 = partially or fully initialised
// -1 = error
// There's no need to distinguish fully-initialised from
// initialisation-in-progress, because we're single-threaded.
private int initState;
// This constructor is used internally by the generated code's
// start-up sequence. KIND is 0=class, 1=interface, 2=array.
// If KIND=0, OTHER=superclass. If KIND=2, OTHER=component
// class, or null if an array with primitive component type.
// If KIND=0 or 1, NAME gives this class's name and IFACES tells
// how many interfaces we implement. If KIND=2, we are given
// a NAME only for arrays with primitive component type.
private Class(int kind, Class other, String name, int ifaces) {
initState=1;
// Object is always the first class to be constructed
if (objectclass==null) objectclass=this;
if (kind==0) {
className=name;
superclass=other;
superInterfaces=new Class[ifaces];
} else if (kind==1) {
className=name;
isIface=true;
superInterfaces=new Class[ifaces];
} else /* kind==2 */ {
isArray=true;
className=name;
componentclass=other;
superclass=objectclass;
}
}
private void initInterface(int no, Class cl) {
superInterfaces[no]=cl;
}
}
|