class.java
来自「java jdk 1.4的源码」· Java 代码 · 共 2,182 行 · 第 1/5 页
JAVA
2,182 行
ret = new Class(className); ret.realclass = java.lang.Double.TYPE; } else if ("void".equals(className)) { // ***** Void is an "absence of type". We might want to create // a special object to represent it. This is a placeholder. ret = new Class(className); ret.realclass = java.lang.Class.forName("java.lang.Object"); } // Other classes are just wrappered. Unknown classes throw a // ClassNotFoundException; the user can switch to declareClass() // if they're sure that an unreified class is OK. else ret = new Class(java.lang.Class.forName(className)); } return ret; } /** * Start to create a synthetic Class with the given fully-qualified * name. If a Class by that name already exists, and it is not * reified, it will be returned instead. If a reified Class _does_ * exist, we throw a synthesis exception. * * @param className the fully qualified name of the desired class. * @return the synthetic Class descriptor for the class with the specified name. * @throws SynthesisException if the class has been reified. */ public static Class declareClass(String className) throws SynthesisException { Class ret = (Class) (global_classtable.get(className)); if (null == ret) ret = new Class(className); if (ret.realclass != null) throw new SynthesisException(SynthesisException.REIFIED); return ret; } /** * Start to create a synthetic Class with the given fully-qualified * name. If a Class by that name already exists,whether reified or * not, it will be removed from the table and replaced by the new synthesis. * * NOTE THAT the replacement will not affect classes which * have already refernced the old version. We could change that by * having everyone reference everyone else via an indirection table. * * @param className the fully qualified name of the desired class. * @return the synthetic Class descriptor for the class with the specified name. */ public static Class reallyDeclareClass(String className) { Class ret = (Class) (global_classtable.get(className)); if (null != ret) global_classtable.remove(ret); ret = new Class(className); return ret; } /** * Returns an array containing Class objects * representing all the public classes and interfaces * that are members of the class represented by this * Class object. This includes public class and * interface members inherited from superclasses and * public class and interface members declared by the * class. Returns an array of length 0 if the class has * no public member classes or interfaces, or if this * Class object represents a primitive type. * <p> * NOTE: In a significant number of existing Java environments, * this method is not implemented by the official Class object * and always returns an empty array. So if you don't get any * useful information from a proxied java.lang.Class, don't * be surprised. I'm not sure if someone decided it was a * potential security issue, or if Sun was lazy and everyone * else followed suit. * <p> * ALSO NOTE: The above spec, as taken from java.lang.Class, * doesn't provide any good way to distinguish the immediate * superclass from all other superclasses. That makes it only * marginally useful, which is no doubt one of the reasons folks * have declined to implement it. * * @return an array of classes. */ public Class[] getClasses() { if (realclass != null && allclasses == null) { java.lang.Class[] realDE = realclass.getClasses(); allclasses = new Class[realDE.length]; for (int i = 0; i < realDE.length; ++i) { allclasses[i] = forClass(realDE[i]); } } return allclasses; } /** * Determines the class loader for the class. * * the class loader that created the class or * interface represented by this object, or null * if the org.apache.xml.utils.synthetic.Class was not created by a class loader. */ public ClassLoader getClassLoader() { return (realclass == null) ? null : realclass.getClassLoader(); } /** * If this class represents an array type, returns the * Class object representing the component type of * the array; otherwise returns null. * <p> * NOTE: Since org.apache.xml.utils.synthetic.Class doesn't yet attempt to model array * types, this will currently return false unless we are * proxying such a type. * * @return the Class object representing the component type of * the array, otherwise returns null. */ public Class getComponentType() { return realclass == null ? null : new Class(realclass.getComponentType()); } /** * Returns a Constructor object that reflects the * specified public constructor of the class * represented by this Class object. The * parameterTypes parameter is an array of Class * objects that identify the constructor's formal * parameter types, in declared order. * <p> * The constructor to reflect is located by searching * all the constructors of the class represented by this * Class object for a public constructor with the * exactly the same formal parameter types. * * * @param parameterTypes array of Class * objects that identify the constructor's formal * parameter types, in declared order. * * @return a Constructor object that reflects the * specified public constructor of the class * represented by this Class object. * * @throws NoSuchMethodException * if a matching method is not found. * @throws SecurityException * if access to the information is denied. * @throws SynthesisException */ public Constructor getConstructor(Class parameterTypes[]) throws NoSuchMethodException, SecurityException, SynthesisException { if (realclass == null) throw new SynthesisException(SynthesisException.UNREIFIED); java.lang.Class[] real = new java.lang.Class[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; ++i) { if ((real[i] = parameterTypes[i].getRealClass()) == null) throw new SynthesisException(SynthesisException.UNREIFIED); } return new Constructor(realclass.getConstructor(real), this); } /** * Returns an array containing Constructor objects * reflecting all the public constructors of the class * represented by this Class object. An array of length * 0 is returned if the class has no public * constructors. * * * @return an array containing Constructor objects * reflecting all the public constructors of the class * represented by this Class object. * * @throws SecurityException * if access to the information is denied. */ public Constructor[] getConstructors() throws SecurityException { if (realclass != null && allconstructors == null) { java.lang.reflect.Constructor[] realDC = realclass.getConstructors(); allconstructors = new Constructor[realDC.length]; for (int i = 0; i < realDC.length; ++i) { allconstructors[i] = new Constructor(realDC[i], this); } } return allconstructors; } /** * This method is not implemented in VAJAVA 3.0 * <p> * Returns an array of Class objects reflecting all the * classes and interfaces declared as members of the * class represented by this Class object. This * includes public, protected, default (package) * access, and private classes and interfaces declared * by the class, but excludes inherited classes and * interfaces. Returns an array of length 0 if the class * declares no classes or interfaces as members, or if * this Class object represents a primitive type. * * * @return an array of Class objects reflecting all the * classes and interfaces declared as members of the * class represented by this Class object. * * @throws SecurityException * if access to the information is denied. */ public Class[] getDeclaredClasses() throws SecurityException { // ***** This should really be a single class plus declared interfaces. if (realclass != null && declaredclasses == null) { java.lang.Class[] realDE = realclass.getDeclaredClasses(); declaredclasses = new Class[realDE.length]; for (int i = 0; i < realDE.length; ++i) { declaredclasses[i] = forClass(realDE[i]); if (!realDE[i].isInterface()) superclass = declaredclasses[i]; } } return declaredclasses; } /** * Adds an "extends" description for the class or * interface represented by this Class object * * @param newclass The class that this class extends. * @throws SynthesisException * if the class has been reified. */ public void addExtends(Class newclass) throws SynthesisException { if (realclass != null) throw new SynthesisException(SynthesisException.REIFIED); Class[] scratch = new Class[declaredclasses.length + 1]; System.arraycopy(declaredclasses, 0, scratch, 0, declaredclasses.length); scratch[declaredclasses.length] = newclass; declaredclasses = scratch; } /** * Returns a Constructor object that reflects the * specified declared constructor of the class or * interface represented by this Class object. The * parameterTypes parameter is an array of Class * objects that identify the constructor's formal * parameter types, in declared order. * * * @param parameterTypes array of Class * objects that identify the constructor's formal * parameter types, in declared order. * * @return a Constructor object that reflects the * specified declared constructor of the class or * interface represented by this Class object. * * @throws NoSuchMethodException * if a matching method is not found. * @throws SecurityException * if access to the information is denied. */ public Constructor getDeclaredConstructor(Class parameterTypes[]) throws NoSuchMethodException, SecurityException { throw new java.lang.IllegalStateException(); } /** * Adds a Constructor description for the class or * interface represented by this Class object * * @return The constructor object. * * @throws SynthesisException * if the class has been reified. */ public Constructor declareConstructor() throws SynthesisException { if (realclass != null) throw new SynthesisException(SynthesisException.REIFIED); Constructor newctor = new Constructor(this); Constructor[] scratch = new Constructor[declaredconstructors.length + 1]; System.arraycopy(declaredconstructors, 0, scratch, 0, declaredconstructors.length); scratch[declaredconstructors.length] = newctor; declaredconstructors = scratch; scratch = new Constructor[allconstructors.length + 1]; System.arraycopy(allconstructors, 0, scratch, 0, allconstructors.length); scratch[allconstructors.length] = newctor; allconstructors = scratch; return newctor; } /** * State that this class implements a specified interface. * This does not yet update allMethods or otherwise * attempt to inherit data. * * @param newifce org.apache.xml.utils.synthetic.Class representing the interface we want to add. * * @return The new interface class. * * @throws org.apache.xml.utils.synthetic.SynthesisException if the Class isn't an interface */ public Class declareInterface(Class newifce) throws SynthesisException { if (realclass != null) throw new SynthesisException(SynthesisException.REIFIED); if (!newifce.isInterface()) throw new SynthesisException(SynthesisException.SYNTAX, newifce.getName() + " isn't an interface"); Class[] scratch = new Class[interfaces.length + 1]; System.arraycopy(interfaces, 0, scratch, 0, interfaces.length); scratch[interfaces.length] = newifce; interfaces = scratch; scratch = new Class[allclasses.length + 1]; System.arraycopy(allclasses, 0, scratch, 0, allclasses.length); scratch[allclasses.length] = newifce; allclasses = scratch; return newifce; } /** * Returns an array of Constructor objects reflecting * all the constructors declared by the class * represented by this Class object. These are public, * protected, default (package) access, and private * constructors. Returns an array of length 0 if this * Class object represents an interface or a primitive * type. * <p> * See The Java Language Specification, section 8.2. * * * @return an array of Constructor objects reflecting * all the constructors declared by the class * represented by this Class object. * * @throws SecurityException * if access to the information is denied. */ public Constructor[] getDeclaredConstructors() throws SecurityException { if (realclass != null && declaredconstructors == null) { java.lang.reflect.Constructor[] realDC = realclass.getDeclaredConstructors(); declaredconstructors = new Constructor[realDC.length]; for (int i = 0; i < realDC.length; ++i) { declaredconstructors[i] = new Constructor(realDC[i], this); } } return declaredconstructors; } /** * Returns a Field object that reflects the specified * declared field of the class or interface represented * by this Class object. The name parameter is a * String that specifies the simple name of the desired * field. * * * @param name String that specifies the simple name of the desired * field. * * @return a Field object that reflects the specified
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?