class.java

来自「kaffe Java 解释器语言,源码,Java的子集系统,开放源代码」· Java 代码 · 共 530 行 · 第 1/2 页

JAVA
530
字号
	if( name.equals("<init>") || name.equals("<clinit>") )		throw new NoSuchMethodException();	return (lookupMethod(name, parameterTypes, false));}native private Method getMethod0(String name, Class[] args, boolean declared);public Method[] getMethods() throws SecurityException{	SecurityManager sm = System.getSecurityManager();	if (sm != null)		sm.checkMemberAccess(this, Member.PUBLIC);	return (getMethods0(false));}native private Method[] getMethods0(boolean declared);native public int getModifiers();native public String getName();public Package getPackage() {	ClassLoader loader = getClassLoader();		if (loader == null) {		return PrimordialClassLoader.getSingleton().				getPackage(PackageHelper.getPackageName(this));	}	return loader.getPackage(PackageHelper.getPackageName(this));}public ProtectionDomain getProtectionDomain() {	ClassLoader loader = getClassLoader ();	if (loader == null) {		return PrimordialClassLoader.getSingleton().getProtectionDomain(this);		}	return loader.getProtectionDomain(this);}native static Class getPrimitiveClass(String name);/** * Finds a resource with the specified name. * The rules for searching for resources associated with a given class * are implemented by the class loader of the class. * <p> * The Class methods delegate to ClassLoader methods, after applying a * naming convention: if the resource name starts with "/", it is used as * is. Otherwise, the name of the package is prepended, after converting * "." to "/". * * @param 	name the string representing the resource to be found. * @return 	the URL object having the specified name, or null if no * resource with the specified name is found.  */public URL getResource(String name) {	ClassLoader loader = getClassLoader();	name = fullResourceName(name);	if (loader == null) {		return ClassLoader.getSystemResource(name);	}	return (loader.getResource(name));}/** * Finds a resource with a given name. * Will return null if no resource with this name is found. The rules * for searching a resources associated with a given class are implemented * by the ClassLoader of the class. * * The Class methods delegate to ClassLoader methods, after applying a * naming convention: if the resource name starts with "/", it is used * as is. Otherwise, the name of the package is prepended, after * converting "." to "/". * * @param 	name the string representing the resource to be found * @return 	the InputStream object having the specified name, or null *		if no resource with the specified name is found. */public InputStream getResourceAsStream(String name) {  	ClassLoader loader = getClassLoader();	name = fullResourceName (name);	if (loader == null) {		return ClassLoader.getSystemResourceAsStream(name);	}		return loader.getResourceAsStream(name);}native public Object[] getSigners();native void setSigners(Object[] signers);native public Class getSuperclass();native public boolean isArray();native public boolean isAssignableFrom(Class cls);native public boolean isInstance(Object obj);native public boolean isInterface();native public boolean isPrimitive();/** * Lookup a method. * * Internal helper method used to combine common method lookup operations into a single method. * * @param name method name * @param parameterTypes method's list of parameters * @param declared true if the method is supposed to be declared in this class * @return the method, if it can be found. * @exception NoSuchMethodException if no method can be found * @exception SecurityException if access to the method is denied */private Method lookupMethod (String name, Class [] parameterTypes, boolean declared) throws NoSuchMethodException, SecurityException {  Method meth = getMethod0(name, parameterTypes, declared);  if (meth == null) {    StringBuffer buf = new StringBuffer("In class ");    buf.append(getName())      .append(" there is no method ")      .append(name)      .append(" (");	      /* write parameter types */    if (parameterTypes != null) {      for (int i = 0; i < parameterTypes.length; ++i) {        buf.append(parameterTypes[i].getName());        if (i < parameterTypes.length - 1) {	  buf.append(", ");        }      }    }    buf.append(')');    throw new NoSuchMethodException(buf.toString());  }  return meth;}public Object newInstance() throws InstantiationException, IllegalAccessException {    if (Modifier.isAbstract(getModifiers()) || isInterface() || isPrimitive()) {	throw new InstantiationException(getName());    }    else {	try {	    return getDeclaredConstructor(null).newInstance(null);	}	catch (InvocationTargetException e) {	    // we rethrow runtime exceptions thrown by constructors, in order to	    // pass on exceptions like NullPointerException to the caller.	    if (e.getTargetException() instanceof RuntimeException) {		throw (RuntimeException) e.getTargetException();	    }	    else {		throw new InstantiationException(e.getTargetException().getMessage());	    }	}	catch (NoSuchMethodException e) {	    throw new InstantiationException(e.getMessage());	}    }}  /**   * Strip the last portion of the name (after the last dot).   *   * @param name the name to get package of   * @return the package name, or "" if no package   */  private static String getPackagePortion(String name)  {    int lastInd = name.lastIndexOf('.');    if (lastInd == -1)      return "";    return name.substring(0, lastInd);  }  /**   * Return the human-readable form of this Object.  For an object, this   * is either "interface " or "class " followed by <code>getName()</code>,   * for primitive types and void it is just <code>getName()</code>.   *   * @return the human-readable form of this Object   */  public String toString()  {    if (isPrimitive())      return getName();    return (isInterface() ? "interface " : "class ") + getName();  }/** * Returns the desired assertion status of this class, if it were to be * initialized at this moment. The class assertion status, if set, is * returned; the backup is the default package status; then if there is * a class loader, that default is returned; and finally the system default * is returned. This method seldom needs calling in user code, but exists * for compilers to implement the assert statement. Note that there is no * guarantee that the result of this method matches the class's actual * assertion status. * * @return the desired assertion status * @see ClassLoader#setClassAssertionStatus(String, boolean) * @see ClassLoader#setPackageAssertionStatus(String, boolean) * @see ClassLoader#setDefaultAssertionStatus(boolean) * @since 1.4 */public boolean desiredAssertionStatus() {	ClassLoader c = getClassLoader();	Object status;	if (c == null)		return ClassLoader.systemDefaultAssertionStatus;	if (c.classAssertionStatus != null) {		synchronized (c) {			status = c.classAssertionStatus.get(getName());			if (status != null)				return status.equals(Boolean.TRUE);		}	} else {		status = ClassLoader.systemClassAssertionStatus.get(getName());		if (status != null)			return status.equals(Boolean.TRUE);	}	if (c.packageAssertionStatus != null) {		synchronized (c) {			String name = getPackagePortion(getName());			if ("".equals(name))				status = c.packageAssertionStatus.get(null);			else {				do {					status = c.packageAssertionStatus.get(name);					name = getPackagePortion(name);				} while (! "".equals(name) && status == null);			}			if (status != null)				return status.equals(Boolean.TRUE);		}	} else {		String name = getPackagePortion(getName());		if ("".equals(name))			status = ClassLoader.systemPackageAssertionStatus.get(null);		else {			do {				status = ClassLoader.systemPackageAssertionStatus.get(name);				name = getPackagePortion(name);			} while (! "".equals(name) && status == null);		}		if (status != null)			return status.equals(Boolean.TRUE);	}	return c.defaultAssertionStatus;}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?