class.java

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

JAVA
2,182
字号
   * declared field of the class or interface represented   * by this Class object.   *    * @throws NoSuchFieldException   * if a field with the specified name is not found.   * @throws SecurityException   * if access to the information is denied.   */  public Field getDeclaredField(String name)          throws NoSuchFieldException, SecurityException  {    throw new java.lang.IllegalStateException();  }  /**   * Adds a Field description for  the class or   * interface represented by this Class object   *   *   * @param name The name of the field.   *   * @return The field description.   *    * @throws SynthesisException   * if the class has been reified.   */  public Field declareField(String name) throws SynthesisException  {    if (realclass != null)      throw new SynthesisException(SynthesisException.REIFIED);    Field newfield = new Field(name, this);    Field[] scratch = new Field[declaredfields.length + 1];    System.arraycopy(declaredfields, 0, scratch, 0, declaredfields.length);    scratch[declaredfields.length] = newfield;    declaredfields = scratch;    scratch = new Field[allfields.length + 1];    System.arraycopy(allfields, 0, scratch, 0, allfields.length);    scratch[allfields.length] = newfield;    allfields = scratch;    return newfield;  }  /**   * Returns an array of Field objects reflecting all the   * fields declared by the class or interface represented   * by this Class object. This includes public,   * protected, default (package) access, and private   * fields, but excludes inherited fields. Returns an   * array of length 0 if the class or interface declares   * no fields, or if this Class object represents a   * primitive type. See The Java Language   * Specification, sections 8.2 and 8.3.   *   *   * @return array of Field objects reflecting all the   * fields declared by the class or interface represented   * by this Class object.   *    * @throws SecurityException   * if access to the information is denied.   */  public Field[] getDeclaredFields() throws SecurityException  {    if (realclass != null && declaredfields == null)    {      java.lang.reflect.Field[] realDF = realclass.getDeclaredFields();      declaredfields = new Field[realDF.length];      for (int i = 0; i < realDF.length; ++i)      {        declaredfields[i] = new Field(realDF[i], this);      }    }    return declaredfields;  }  /**   * Returns a Method object that reflects the specified   * declared method of the class or interface   * represented by this Class object. The name   * parameter is a String that specifies the simple   * name of the desired method, and the   * parameterTypes parameter is an array of Class   * objects that identify the method's formal parameter   * types, in declared order.   *   *   * @param name String that specifies the simple   * name of the desired method.   *    * @param parameterTypes array of Class   * objects that identify the method's formal parameter   * types, in declared order.   *   * @return Method object that reflects the specified   * declared method 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 Method getDeclaredMethod(String name, Class parameterTypes[])          throws NoSuchMethodException, SecurityException  {    throw new java.lang.IllegalStateException();  }  /**   * Adds a Method description for  the class or   * interface represented by this Class object   *   *   * @param name Name of method.   *   * @return The method object.   *    * @throws SynthesisException   * if the class has been reified.   */  public Method declareMethod(String name) throws SynthesisException  {    if (realclass != null)      throw new SynthesisException(SynthesisException.REIFIED);    Method newMethod = new Method(name, this);    Method[] scratch = new Method[declaredmethods.length + 1];    System.arraycopy(declaredmethods, 0, scratch, 0, declaredmethods.length);    scratch[declaredmethods.length] = newMethod;    declaredmethods = scratch;    scratch = new Method[allmethods.length + 1];    System.arraycopy(allmethods, 0, scratch, 0, allmethods.length);    scratch[allmethods.length] = newMethod;    allmethods = scratch;    return newMethod;  }  /**   * Returns an array of Method objects reflecting all   * the methods declared by the class or interface   * represented by this Class object. This includes   * public, protected, default (package) access, and   * private methods, but excludes inherited methods.   * Returns an array of length 0 if the class or interface   * declares no methods, or if this Class object   * represents a primitive type.   * <p>   * See The Java Language Specification, section 8.2.   *   * @return array of Method objects reflecting all   * the methods declared by the class or interface   * represented by this Class object.   *    * @throws SecurityException   * if access to the information is denied.   */  public Method[] getDeclaredMethods() throws SecurityException  {    if (realclass != null && declaredmethods == null)    {      java.lang.reflect.Method[] realDM = realclass.getDeclaredMethods();      declaredmethods = new Method[realDM.length];      for (int i = 0; i < realDM.length; ++i)      {        declaredmethods[i] = new Method(realDM[i], this);      }    }    return declaredmethods;  }  /**   * This method is not implemented in VAJava 3.0   * <p>   * If the class or interface represented by this Class   * object is a member of another class, returns the   * Class object representing the class of which it is a   * member (its declaring class). Returns null if this   * class or interface is not a member of any other   * class.   *   */  public Class getDeclaringClass()  {    if (realclass != null && declaringclass == null)    {      java.lang.Class dc = realclass.getDeclaringClass();      if (dc == null)        declaringclass = null;      else        declaringclass = forClass(dc);    }    return declaringclass;  }  /**   * Declare that this class is an inner class of another.   *   * @param newclass   *   * @throws SynthesisException   */  private void addInnerClass(Class newclass) throws SynthesisException  {    if (realclass != null)      throw new SynthesisException(SynthesisException.REIFIED);    if (newclass.getDeclaringClass() != this)      throw new SynthesisException(SynthesisException.WRONG_OWNER);    Class[] scratch = new Class[innerclasses.length + 1];    System.arraycopy(innerclasses, 0, scratch, 0, innerclasses.length);    scratch[innerclasses.length] = newclass;    innerclasses = scratch;  }  /**   * Declare a class contained within this class. This doesn't   * address anonymous classes (those go inside method bodies   * and similar code), just local classes.   * <p>   * ***** This requires lookup methods that operate in the   * context of a specific class, and per-class registries!   *   * @param className Local name of inner class to create. This should _not_ be a   * qualified name, unlike the normal forName() call. Its   * hierarchy is established by the class within which it is   * created.   * @return org.apache.xml.utils.synthetic.Class object for the contained class.   * @throws org.apache.xml.utils.synthetic.SynthesisException if class could not be created.   * @since 2/2000   *   * @throws SynthesisException   */  public Class declareInnerClass(String className) throws SynthesisException  {    if (realclass != null)      throw new SynthesisException(SynthesisException.REIFIED);    String relativeName = getName() + "$" + className;    Class newclass = (Class) (global_classtable.get(relativeName));    if (newclass != null)      throw new SynthesisException(SynthesisException.SYNTAX,                                   "Inner class " + name + " already exists");    newclass = new Class(className);    newclass.declaringclass = this;    Class[] scratch = new Class[innerclasses.length + 1];    System.arraycopy(innerclasses, 0, scratch, 0, innerclasses.length);    scratch[innerclasses.length] = newclass;    innerclasses = scratch;    return newclass;  }  /**   * Fetch a list of classes contained within this class.   * This doesn't address anonymous classes (those go   * inside method bodies and similar code), just local classes.   *   * @return org.apache.xml.utils.synthetic.Class[] object for the contained classes.   * This may be empty if none such exist, or if the class is   * reified (since reflection doesn't report this information).   * @since 3/2000   */  public Class[] getInnerClasses()  {    return innerclasses;  }  /**   * Returns a Field object that reflects the specified   * public member field of the class or interface   * represented by this Class object. The name   * parameter is a String specifying the simple name of   * the desired field.   * <p>   * The field to be reflected is located by searching all   * the member fields of the class or interface   * represented by this Class object for a public field   * with the specified name.   * <p>   * See The Java Language Specification, sections 8.2   * and 8.3.   *   *   * @param name   *   * @throws NoSuchFieldException   * if a field with the specified name is not   * found.   * @throws SecurityException   * if access to the information is denied.   */  public Field getField(String name)          throws NoSuchFieldException, SecurityException  {    throw new java.lang.IllegalStateException();  }  /**   * Returns an array containing Field objects   * reflecting all the accessible public fields of the   * class or interface represented by this Class object.   * Returns an array of length 0 if the class or interface   * has no accessible public fields, or if it represents   * an array type or a primitive type.   * <p>   * Specifically, if this Class object represents a class,   * returns the public fields of this class and of all its   * superclasses. If this Class object represents an   * interface, returns the fields of this interface and of   * all its superinterfaces. If this Class object   * represents an array type or a primitive type, returns   * an array of length 0.   * <p>   * The implicit length field for array types is not   * reflected by this method. User code should use the   * methods of class Array to manipulate arrays.   * <p>   * See The Java Language Specification, sections 8.2   * and 8.3.   *   *   * @throws SecurityException   * if access to the information is denied.   */  public Field[] getFields() throws SecurityException  {    if (realclass != null && allfields == null)    {      java.lang.reflect.Field[] realDF = realclass.getFields();      allfields = new Field[realDF.length];      for (int i = 0; i < realDF.length; ++i)      {        allfields[i] = new Field(realDF[i], this);      }    }    return allfields;  }  /**   * Determines the interfaces implemented by the   * class or interface represented by this object.   * <p>   * If this object represents a class, the return value is   * an array containing objects representing all   * interfaces implemented by the class. The order of   * the interface objects in the array corresponds to the   * order of the interface names in the implements   * clause of the declaration of the class represented by   * this object.   * <p>   * If this object represents an interface, the array   * contains objects representing all interfaces   * extended by the interface. The order of the   * interface objects in the array corresponds to the   * order of the interface names in the extends clause   * of the declaration of the interface represented by   * this object.   * <p>   * If the class or interface implements no interfaces,   * the method returns an array of length 0.   *   * an array of interfaces implemented by this   * class.   */  public Class[] getInterfaces()  {    if (realclass != null && interfaces == null)    {      java.lang.Class[] realI = realclass.getInterfaces();      interfaces = new Class[realI.length];      for (int i = 0; i < realI.length; ++i)      {        interfaces[i] = forClass(realI[i]);      }    }    return interfaces;  }  /**   * Adds an "implements" description for the class or   * interface represented by this Class object   *   *   * @param newclass   * @throws SynthesisException   * if the class has been reified.   */  public void addImplements(Class newclass) throws SynthesisException  {    if (realclass != null)      throw new SynthesisException(SynthesisException.REIFIED);    Class[] scratch = new Class[interfaces.length + 1];

⌨️ 快捷键说明

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