class.java

来自「java jdk 1.4的源码」· Java 代码 · 共 2,182 行 · 第 1/5 页

JAVA
2,182
字号
    System.arraycopy(interfaces, 0, scratch, 0, interfaces.length);    scratch[interfaces.length] = newclass;    interfaces = scratch;  }  /**   * Returns a Method object that reflects the specified   * public member method of the class or interface   * represented by this Class object. The name   * parameter is a String specifying the simple name   * the desired method, and the parameterTypes   * parameter is an array of Class objects that identify   * the method's formal parameter types, in declared   * order.   * <p>   * The method to reflect is located by searching all   * the member methods of the class or interface   * represented by this Class object for a public   * method with the specified name and exactly the   * same formal parameter types.   * <p>   * See The Java Language Specification, sections 8.2   * and 8.4.   *   *   * @param name   * @param parameterTypes   *   * @throws NoSuchMethodException   * if a matching method is not found.   * @throws SecurityException   * if access to the information is denied.   */  public Method getMethod(String name, Class parameterTypes[])          throws NoSuchMethodException, SecurityException  {    throw new java.lang.IllegalStateException();  }  /**   * Returns an array containing Method objects   * reflecting all the public member methods of the   * class or interface represented by this Class object,   * including those declared by the class or interface   * and and those inherited from superclasses and   * superinterfaces. Returns an array of length 0 if the   * class or interface has no public member methods.   * <p>   * See The Java Language Specification, sections 8.2   * and 8.4.   *   *   * @throws SecurityException   * if access to the information is denied.   */  public Method[] getMethods() throws SecurityException  {    if (realclass != null && allmethods == null)    {      java.lang.reflect.Method[] realDM = realclass.getMethods();      allmethods = new Method[realDM.length];      for (int i = 0; i < realDM.length; ++i)      {        allmethods[i] = new Method(realDM[i], this);      }    }    return allmethods;  }  /**   * Returns the Java language modifiers for this class   * or interface, encoded in an integer. The modifiers   * consist of the Java Virtual Machine's constants for   * public, protected, private, final, and interface; they   * should be decoded using the methods of class   * Modifier.   *   * The modifier encodings are defined in The Java   * Virtual Machine Specification, table 4.1.   *   * See Also:   * java.lang.reflect.Modifier   *   */  public int getModifiers()  {    return modifiers;  }  /**   *   Set the Java language modifiers for this class   *   or interface, encoded in an integer. The modifiers   *   consist of the Java Virtual Machine's constants for   *   public, protected, private, final, and interface; they   *   should be decoded using the methods of class   *   Modifier.   *   *   The modifier encodings are defined in The Java   *   Virtual Machine Specification, table 4.1.   *   *   See Also:   *   java.lang.reflect.Modifier   *   * @param modifiers   *   * @throws SynthesisException   */  public void setModifiers(int modifiers) throws SynthesisException  {    if (this.realclass != null)      throw new SynthesisException(SynthesisException.REIFIED);    this.modifiers = modifiers;  }  /**   * Retrieve the fully-qualified classname. If it's an array,   * it will be returned in JVM syntax, not Java syntax.   *   * @return java.lang.String   * @since 12/95   */  public java.lang.String getName()  {    return name;  }  /**   * Like getName, but back-convert array notation escapes.   * ***** DOESN'T YET HANDLE ARRAYS OF PRIMITIVES!   *   * @return java.lang.String   * @since 3/2000   */  public java.lang.String getJavaName()  {    if (name.charAt(0) != '[')      return name;    // Object array syntax is [Ltypename;     // add another [ for each level of array    int count = name.lastIndexOf('[');    StringBuffer jname = new StringBuffer(name.substring(count + 2));    // Trim the trailing ';'    jname.setLength(jname.length() - 1);    while (count-- >= 0)    {      jname.append("[]");    }    return jname.toString();  }  /**   * Extract just the local name of this class, minus the package   * prefix.   *   * ***** I don't think this handles array types properly yet.   *   * @return java.lang.String   * @since 12/99   */  public java.lang.String getShortName()  {    int start = name.lastIndexOf(".");    if (start != 0 || name.charAt(0) == '.')      ++start;    if (declaringclass != null)    {      int d = name.lastIndexOf('$', start);      if (d != 0)        start = d + 1;    }    return name.substring(start);  }  /**   * Like getShortName, but back-convert array notation escapes.   * ***** DOESN'T YET HANDLE ARRAYS OF PRIMITIVES!   *   * @return java.lang.String   * @since 3/2000   */  public java.lang.String getJavaShortName()  {    String shortname = getShortName();    if (shortname.charAt(0) != '[')      return shortname;    // Object array syntax is [Ltypename;     // add another [ for each level of array    int count = shortname.lastIndexOf('[');    StringBuffer jname = new StringBuffer(shortname.substring(count + 2));    // Trim the trailing ';'    jname.setLength(jname.length() - 1);    while (count-- >= 0)    {      jname.append("[]");    }    return jname.toString();  }  /**   * Extract the package name for this class.   * ***** I don't think this handles array classes properly yet.   *   * @return java.lang.String   * @since 12/95   */  public java.lang.String getPackageName()  {    int start = name.lastIndexOf(".");    return name.substring(0, start);  }  /**   * If this synthetic class is a wrapper for a "real"   * java.lang.Class -- either because it was instantiated as such   * or because it has been compiled -- this method will return   * that class. Otherwise it returns null.   * Creation date: (12-25-99 12:26:01 PM)   * @return org.apache.xml.utils.synthetic.Class   */  public java.lang.Class getRealClass()  {    return realclass;  }  /**   * This call is intended to allow an existing org.apache.xml.utils.synthetic.Class   * to be switched from purely descriptive mode to proxy mode   * ("reified").   * The primary intent is to allow a org.apache.xml.utils.synthetic.Class to be   * "compiled in place"   * <p>   * This should have the side-effect of limiting further mutation   * of the org.apache.xml.utils.synthetic.Class to things which can not be obtained   * from the real Class object, to avoid "lying" to the user   * <p>   * NOTE: Not all information defined by the Java libraries is   * in fact available in all Java environments. We assume the   * calls will work; if they return null or empty lists, there's   * nothing we can do about it. Note that this may mean that a   * reified class tells us less about itself than the   * synthetic description used to generate it.   * <p>   * Creation date: (12-25-99 12:26:01 PM)   * @param java.lang.class realclass nonsynthetic Class object to proxy   *   * @param realclass   *   * @throws SynthesisException   */  public void setRealClass(java.lang.Class realclass)          throws SynthesisException  {    if (this.realclass != null)      throw new SynthesisException(SynthesisException.REIFIED);    this.realclass = realclass;    this.modifiers = realclass.getModifiers();    this.isInterface = realclass.isInterface();    // DEFERRED -- set them null now, reconstruct when requested    this.declaringclass = null;    this.interfaces = null;    this.declaredconstructors = null;    this.allconstructors = null;    this.declaredmethods = null;    this.allmethods = null;    this.declaredfields = null;    this.allfields = null;    this.declaredclasses = null;    this.allclasses = null;    this.superclass = null;  }  /**   * Set the superclass for this synthetic class.   * Object is equivalent to Null.   * Creation date: (12-25-99 12:26:01 PM)   *   * @param superclass   * @return org.apache.xml.utils.synthetic.Class   *   * @throws SynthesisException   */  public void setSuperClass(Class superclass) throws SynthesisException  {    if (realclass != null)      throw new SynthesisException(SynthesisException.REIFIED);    this.superclass = superclass;  }  /**   * Set the superclass for this synthetic class.   * Creation date: (12-25-99 12:26:01 PM)   *   * @param superclass   * @return org.apache.xml.utils.synthetic.Class   *   * @throws ClassNotFoundException   * @throws SynthesisException   */  public void setSuperClass(java.lang.Class superclass)          throws ClassNotFoundException, SynthesisException  {    if (realclass != null)      throw new SynthesisException(SynthesisException.REIFIED);    this.superclass = Class.forClass(superclass);  }  /**   * 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.   * the URL object having the specified name, or   * null if no resource with the specified name   * is found.   */  public java.net.URL getResource(String name)  {    throw new java.lang.IllegalStateException();  }  /**   * 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.   * <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   * the InputStream object having the   * specified name, or null if no resource with   * the specified name is found.   */  public java.io.InputStream getResourceAsStream(String name)  {    throw new java.lang.IllegalStateException();  }  /**   * Get the signers of this class.   *   */  public Object[] getSigners()  {    throw new java.lang.IllegalStateException();  }  /**   * If this object represents any class other than the   * class Object, then the object that represents the   * superclass of that class is returned.   * <p>   * If this object is the one that represents the class   * Object or this object represents an interface, null is   * returned.   *   * the superclass of the class represented by this   * object.   */  public Class getSuperclass()  {    if (realclass != null && superclass == null)    {      superclass = forClass(realclass.getSuperclass());      // getDeclaredClasses(); // Sets superclass as a side-effect    }    if (superclass == null)      superclass = forClass(Object.class);    return superclass;  }  /**   * If this Class object represents an array type, returns   * true, otherwise returns false.   *   */  public boolean isArray()  {    return realclass != null && realclass.isArray();  }  /**   * Determines if the class or interface represented by   * this Class object is either the same as, or is a

⌨️ 快捷键说明

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