Class ClassFile

java.lang.Object
org.fife.rsta.ac.java.classreader.ClassFile
All Implemented Interfaces:
AccessFlags

public class ClassFile extends Object implements AccessFlags
Class representing a ClassFile structure.
Version:
1.0
  • Field Details

    • DEBUG

      private static final boolean DEBUG
      See Also:
    • minorVersion

      private int minorVersion
      The class file's minor version number.
    • majorVersion

      private int majorVersion
      The class file's major version number.
    • constantPool

      private ConstantPoolInfo[] constantPool
      Constant pool infos.
    • accessFlags

      private int accessFlags
      Permissions and properties of this class or interface.
    • thisClass

      private int thisClass
      Index into constantPool for a ConstantClassInfo structure representing the class or interface defined in this class file.
    • superClass

      private int superClass
      Index into constantPool for a ConstantClassInfo structure representing the superclass of this class or interface. If this value is 0 then this class must be class java.lang.Object. If this is an interface, then this index must point to information about class java.lang.Object.
    • interfaces

      int[] interfaces
      Indices into constantPool for ConstantClassInfos representing the implemented interfaces of this class or interface.
    • fields

      private FieldInfo[] fields
      Structures giving complete descriptions of the fields in this class or interface.
    • methods

      private MethodInfo[] methods
      Structures giving complete descriptions of the methods in this class or interface.
    • deprecated

      private boolean deprecated
      Whether this class is deprecated.
    • attributes

      private AttributeInfo[] attributes
      Attributes of this class or interface.
    • paramTypes

      private List<String> paramTypes
      Parameter types, such as "String" in List<String>.
    • typeMap

      private Map<String,String> typeMap
      A mapping of type parameters to type arguments. This is set via setTypeParamsToTypeArgs(Map) during code completion of members of an instance variable whose type is represented by this class file. This ClassFile doesn't use this field itself; rather, it's there for consumers (such as the Java code completion API) to use.
    • DEPRECATED

      public static final String DEPRECATED
      See Also:
    • ENCLOSING_METHOD

      public static final String ENCLOSING_METHOD
      See Also:
    • INNER_CLASSES

      public static final String INNER_CLASSES
      See Also:
    • RUNTIME_VISIBLE_ANNOTATIONS

      public static final String RUNTIME_VISIBLE_ANNOTATIONS
      See Also:
    • SIGNATURE

      public static final String SIGNATURE
      See Also:
    • SOURCE_FILE

      public static final String SOURCE_FILE
      See Also:
    • BOOTSTRAP_METHODS

      public static final String BOOTSTRAP_METHODS
      See Also:
  • Constructor Details

  • Method Details

    • debugPrint

      private void debugPrint(String text)
    • getAccessFlags

      public int getAccessFlags()
      Returns the access flags for this class or interface.
      Returns:
      The access flags, as a bit field.
      See Also:
    • getAttribute

      public AttributeInfo getAttribute(int index)
      Returns the specified attribute of this class file.
      Parameters:
      index - The index of the attribute.
      Returns:
      The attribute.
      See Also:
    • getAttributeCount

      public int getAttributeCount()
      Returns the number of attributes of this class file.
      Returns:
      The number of attributes.
      See Also:
    • getClassName

      public String getClassName(boolean fullyQualified)
      Returns the name of this class or interface.
      Parameters:
      fullyQualified - Whether the name should be fully-qualified.
      Returns:
      The name of this class or interface.
      See Also:
    • getClassNameFromConstantPool

      protected String getClassNameFromConstantPool(int cpIndex, boolean fullyQualified)
      Given an index into the constant pool of a ConstantClassInfo, this method returns the fully-qualified name of the class it points to.
      Parameters:
      cpIndex - The index into the constant pool. Note that this value is 1-based.
      fullyQualified - Whether the returned class name should be fully qualified.
      Returns:
      The fully-qualified class or interface name.
    • getConstantPoolCount

      public int getConstantPoolCount()
      Returns the size of the constant pool, plus 1.
      Returns:
      The size of the constant pool, plus 1.
      See Also:
    • getConstantPoolInfo

      public ConstantPoolInfo getConstantPoolInfo(int index)
      Returns the constant pool entry at the specified index. Note that constant pool entries are 1-based (that is, valid indices are 1 - getConstantPoolCount()-1).
      Parameters:
      index - The index into the constant pool to retrieve.
      Returns:
      The constant pool entry, or null if index is 0 (e.g. this ClassFile object represents java.lang.Object).
      See Also:
    • getFieldCount

      public int getFieldCount()
      Returns the number of fields declared in this class file.
      Returns:
      The number of fields.
      See Also:
    • getFieldInfo

      public FieldInfo getFieldInfo(int index)
      Returns the specified field's information.
      Parameters:
      index - The index of the field info.
      Returns:
      The field's information.
      See Also:
    • getFieldInfoByName

      public FieldInfo getFieldInfoByName(String name)
      Returns a field's information by name.
      Parameters:
      name - The name of the field.
      Returns:
      The field's information.
      See Also:
    • getImplementedInterfaceCount

      public int getImplementedInterfaceCount()
      Returns the number of interfaces this class or interface implements.
      Returns:
      The number of implemented interfaces.
      See Also:
    • getImplementedInterfaceName

      public String getImplementedInterfaceName(int index, boolean fullyQualified)
      Returns the specified interface implemented by this class or interface.
      Parameters:
      index - The index of the interface.
      fullyQualified - Whether the returned interface name should be fully qualified.
      Returns:
      The interface name.
      See Also:
    • getMethodCount

      public int getMethodCount()
      Returns the number of methods defined/declared in this class or interface.
      Returns:
      The number of methods.
      See Also:
    • getMethodInfo

      public MethodInfo getMethodInfo(int index)
      Returns information about the specified method defined/declared in this class file.
      Parameters:
      index - The index of the method.
      Returns:
      Information about the method.
      See Also:
    • getMethodInfoByName

      public List<MethodInfo> getMethodInfoByName(String name)
      Returns all method overloads with the specified name.
      Parameters:
      name - The method name.
      Returns:
      Any method overloads with the given name, or null if none. This is a list of MethodInfos.
      See Also:
    • getMethodInfoByName

      public List<MethodInfo> getMethodInfoByName(String name, int argCount)
      Returns all method overloads with the specified name and number of arguments.
      Parameters:
      name - The method name.
      argCount - The number of arguments. If this is less than zero, all overloads will be returned, regardless of argument count.
      Returns:
      Any method overloads with the given name and argument count, or null if none. This is a list of MethodInfos.
      See Also:
    • getPackageName

      public String getPackageName()
      Returns the package for this class or interface.
      Returns:
      The package, or null if this class or interface is not in a package.
      See Also:
    • getParamTypes

      public List<String> getParamTypes()
    • getSuperClassName

      public String getSuperClassName(boolean fullyQualified)
      Returns the fully-qualified name of the superclass of this class or interface.
      Parameters:
      fullyQualified - Whether the returned value should be fully qualified.
      Returns:
      The name of the superclass of this class or interface. If this is an interface, then "java.lang.Object" is returned. If this class file represents java.lang.Object, then null is returned.
      See Also:
    • getTypeArgument

      public String getTypeArgument(String typeParam)
      Returns the currently set type argument for the specified type parameter.
      Parameters:
      typeParam - The type parameter.
      Returns:
      The type argument, or "Object" if no type parameters have been set. This is because, if the user types, say, "java.util.List list;" in Java 5+, the type defaults to Object. The code completion API may set the type argument mapping to null if no type arguments are scanned, thus we need to return Object in this case.
      See Also:
    • getUtf8ValueFromConstantPool

      public String getUtf8ValueFromConstantPool(int index)
      Returns the string value represented by a ConstantUtf8Info entry in the constant pool.
      Parameters:
      index - The index into the constant pool of a ConstantUtf8Info structure. This should be 1-based.
      Returns:
      The string represented.
    • getVersionString

      public String getVersionString()
      Returns the version number of this class, as a string.
      Returns:
      The class's version number, in the form major.minor.
    • init

      private void init(DataInputStream in) throws IOException
      Parses the class file from a given input stream.
      Parameters:
      in - The input stream to read from.
      Throws:
      IOException - If an error occurs reading the class file.
    • isDeprecated

      public boolean isDeprecated()
      Returns whether this class is deprecated.
      Returns:
      Whether this class is deprecated.
    • readAccessFlags

      private void readAccessFlags(DataInputStream in) throws IOException
      Reads this class or interface's access flags.
      Parameters:
      in - The input stream to read from.
      Throws:
      IOException - If an error occurs reading the access flags.
    • readAttribute

      private AttributeInfo readAttribute(DataInputStream in) throws IOException
      Reads a single attribute of this class file.
      Parameters:
      in - The input stream to read from.
      Returns:
      The attribute.
      Throws:
      IOException - If an IO error occurs.
    • readAttributes

      private void readAttributes(DataInputStream in) throws IOException
      Reads this class file's attributes.
      Parameters:
      in - The input stream to read from.
      Throws:
      IOException - If an IO error occurs.
    • readConstantPoolInfos

      private void readConstantPoolInfos(DataInputStream in) throws IOException
      Reads the constant pool.
      Parameters:
      in - The input stream to read from.
      Throws:
      IOException - If an IO error occurs.
    • readFields

      private void readFields(DataInputStream in) throws IOException
      Reads the "fields" information.
      Parameters:
      in - The input stream to read from.
      Throws:
      IOException - If an IO error occurs.
    • readHeader

      private void readHeader(DataInputStream in) throws IOException
      Reads the 0xCAFEBABE class file header.
      Parameters:
      in - The input stream to read from.
      Throws:
      IOException - If the header is invalid.
    • readInterfaces

      private void readInterfaces(DataInputStream in) throws IOException
      Reads the array of indices into the constant pool for the names of the interfaces implemented by this class or interface.
      Parameters:
      in - The input stream to read from.
      Throws:
      IOException - If an IO error occurs reading the input stream.
    • readMethods

      private void readMethods(DataInputStream in) throws IOException
      Throws:
      IOException
    • readSuperClass

      private void readSuperClass(DataInputStream in) throws IOException
      Throws:
      IOException
    • readThisClass

      private void readThisClass(DataInputStream in) throws IOException
      Throws:
      IOException
    • readVersion

      private void readVersion(DataInputStream in) throws IOException
      Reads the class file's major and minor version numbers.
      Parameters:
      in - The input stream to read from.
      Throws:
      IOException - If the version numbers are invalid.
    • setTypeParamsToTypeArgs

      public void setTypeParamsToTypeArgs(Map<String,String> typeMap)
      Sets a mapping of type parameters of this class to type arguments for a particular instance of this class. Note that ClassFile does not directly use this field; it is there for code completion API's to use to extract the necessary types of arguments, return values, etc., of methods (see the MethodInfo class).
      Parameters:
      typeMap - A mapping of type parameters to type arguments (both Strings).
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object