class.java
来自「kaffe Java 解释器语言,源码,Java的子集系统,开放源代码」· Java 代码 · 共 530 行 · 第 1/2 页
JAVA
530 行
/* * Java core library component. * * Copyright (c) 1997, 1998 * Transvirtual Technologies, Inc. All rights reserved. * Portions Copyright (C) 1998, 2002, 2003 Free Software Foundation * * See the file "license.terms" for information on usage and redistribution * of this file. */package java.lang;import java.io.InputStream;import java.io.IOException;import java.io.Serializable;import java.lang.reflect.Constructor;import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Member;import java.lang.reflect.Method;import java.lang.reflect.Modifier;import java.net.URL;import java.security.ProtectionDomain;import java.util.Vector;import kaffe.lang.ThreadStack;import kaffe.lang.PackageHelper;import kaffe.lang.PrimordialClassLoader;public final class Class implements Serializable {/* For GCJ compatibility, we cannot define any fields in * java.lang.Class at this point. Valid as of 10/28/99 * We special case it instead in clib/native/ObjectStreamClassImpl.c * --gback */// private static final long serialVersionUID = 3206093459760846163L;// Only instantiable by the VMprivate Class() {}public static Class forName(String className) throws ClassNotFoundException { return forName(className, true, ThreadStack.getCallersClassLoader(false));}/* * NOTE: We go native here because it already implements all the necessary * synchronization stuff. */public static native Class forName(String className, boolean initialize, ClassLoader loader) throws ClassNotFoundException;private String fullResourceName(String name) { if (name.charAt(0) == '/') { return name; } String cname = getName(); StringBuffer buf = new StringBuffer(); int tail = cname.lastIndexOf('.'); if (tail != -1) { buf.append(cname.substring(0, tail+1).replace('.', '/')); } buf.append(name); return (buf.toString());}/** * Determines the class loader for the class. * * @returns the class loader that created the class or interface * represented by this object, or null if the class was not * created by a class loader. * @see java.lang.ClassLoader */public ClassLoader getClassLoader() { return (getClassLoader0());}native private ClassLoader getClassLoader0();/** * If this is an inner class, return the class that * declared it. If not, return null. * * @return the declaring class of this class. * @since JDK1.1 */public Class getDeclaringClass() { Class[] classes = getClasses0(false); switch (classes.length) { case 0: return null; case 1: return classes[0]; default: throw new ClassFormatError ("Too many outer classes :" + classes.length); }}/** * Get all the public inner classes, declared in this * class or inherited from superclasses, that are * members of this class. * * @return all public inner classes in this class. * @since JDK1.1 */public Class[] getClasses() { SecurityManager sm = System.getSecurityManager(); Vector v = new Vector(); Class clazz = this; while (clazz != null) { if (sm != null) sm.checkMemberAccess(clazz, Member.PUBLIC); Class[] classes = clazz.getClasses0(true); for (int i = 0; i < classes.length; i++) { if (Modifier.isPublic(classes[i].getModifiers())) { v.add (classes[i]); } } clazz = clazz.getSuperclass(); } return (Class[])v.toArray (new Class[v.size()]);}native private Class[] getClasses0(boolean inner);native public Class getComponentType();public Constructor getConstructor(Class parameterTypes[]) throws NoSuchMethodException, SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.PUBLIC); return (getConstructor0(parameterTypes, false));}native private Constructor getConstructor0(Class[] args, boolean declared);public Constructor[] getConstructors() throws SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.PUBLIC); return (getConstructors0(false));}native private Constructor[] getConstructors0(boolean declared);/** * Get all the inner classes declared in this class. * * @return all inner classes declared in this class. * @exception SecurityException if you do not have access * to non-public inner classes of this class. * @since JDK1.1 */public Class[] getDeclaredClasses() throws SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.DECLARED); return (getClasses0(true));}public Constructor getDeclaredConstructor(Class parameterTypes[]) throws NoSuchMethodException, SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.DECLARED); return (getConstructor0(parameterTypes, true));}public Constructor[] getDeclaredConstructors() throws SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.DECLARED); return (getConstructors0(true));}public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.DECLARED); return getFieldInternal(name, true);}public Field[] getDeclaredFields() throws SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.DECLARED); return (getFields0(true));}public Method getDeclaredMethod(String name, Class parameterTypes[]) throws NoSuchMethodException, SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.DECLARED); return lookupMethod(name, parameterTypes, true);}public Method[] getDeclaredMethods() throws SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.DECLARED); return (getMethods0(true));}public Field getField(String name) throws NoSuchFieldException, SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.PUBLIC); return getFieldInternal(name, false);}/* Lookup a field in a class. @param name a field name @param declared true if the field is supposed to be declared in this class @return a pointer to the field, if it can be found. @throws NoSuchFieldException if no such field can be found*/private Field getFieldInternal(String name, boolean declared) throws NoSuchFieldException { Field field = getField0(name, declared); if (field == null) { throw new NoSuchFieldException("Class " + getName() + " has no field named " + name); } return field;}native private Field getField0(String name, boolean declared);public Field[] getFields() throws SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.PUBLIC); return (getFields0(false));}native private Field[] getFields0(boolean declared);native public Class[] getInterfaces();public Method getMethod(String name, Class parameterTypes[]) throws NoSuchMethodException, SecurityException{ SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkMemberAccess(this, Member.PUBLIC );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?