Overview | Package | Class | Use | Tree | Deprecated | Index
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javassist.bytecode
Class ClassFile

    java.lang.Object
      |
      +--javassist.bytecode.ClassFile

public final class ClassFile
extends java.lang.Object

`ClassFile` represents a Java `.class` file, which consists of a constant pool, methods, fields, and attributes.

See Also:
  `CtClass.getClassFile()`

Constructor Summary
`ClassFile(boolean isInterface, java.lang.String classname, java.lang.String superclass)` Constructs a class file including no members.
`ClassFile(java.io.DataInputStream in)` Constructs a class file from a byte stream.

Method Summary
`void` | `addAttribute(AttributeInfo info)` Appends an attribute.
`void` | `addField(FieldInfo finfo)` Appends a field to the class.
`void` | `addInterface(java.lang.String name)` Appends an interface to the interfaces implemented by the class.
`void` | `addMethod(MethodInfo minfo)` Appends a method to the class.
`int` | `getAccessFlags()` Returns access flags.
`AttributeInfo` | `getAttribute(java.lang.String name)` Returns the attribute with the specified name.
`java.util.List` | `getAttributes()` Returns all the attributes.
`ConstPool` | `getConstPool()` Returns a constant pool table.
`java.util.List` | `getFields()` Returns all the fields declared in the class.
`java.lang.String[]` | `getInterfaces()` Returns the names of the interfaces implemented by the class.
`MethodInfo` | `getMethod(java.lang.String name)` Returns the method with the specified name.
`java.util.List` | `getMethods()` Returns all the methods declared in the class.
`java.lang.String` | `getName()` Returns the class name.
`java.lang.String` | `getSourceFile()` Returns the source file containing this class.
`MethodInfo` | `getStaticInitializer()` Returns a static initializer (class initializer), or null if it does not exist.
`java.lang.String` | `getSuperclass()` Returns the super class name.
`int` | `getSuperclassId()` Returns the index of the constant pool entry representing the super class.
`boolean` | `isAbstract()` Returns true if this is an abstract class or an interface.
`boolean` | `isFinal()` Returns true if this is a final class or interface.
`boolean` | `isInterface()` Returns true if this is an interface.
`void` | `renameClass(java.util.Map classnames)` Replaces all occurrences of several class names in the class file.
`void` | `renameClass(java.lang.String oldname, java.lang.String newname)` Replaces all occurrences of a class name in the class file.
`void` | `setAccessFlags(int acc)` Changes access flags.
`void` | `setInterfaces(java.lang.String[] nameList)` Sets the interfaces.
`void` | `setName(java.lang.String name)` Sets the class name.
`void` | `setSuperclass(java.lang.String superclass)` Sets the super class.
`void` | `write(java.io.DataOutputStream out)` Writes a class file represened by this object into an output stream.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ClassFile

    public ClassFile(java.io.DataInputStream in)
              throws java.io.IOException

  Constructs a class file from a byte stream.

### ClassFile

    public ClassFile(boolean isInterface,
                     java.lang.String classname,
                     java.lang.String superclass)

  Constructs a class file including no members.

Parameters:
  `isInterface` - true if this is an interface. false if this is a class.
  `classname` - a fully-qualified class name
  `superclass` - a fully-qualified super class name

Method Detail

### getConstPool

    public ConstPool getConstPool()

  Returns a constant pool table.

### isInterface

    public boolean isInterface()

  Returns true if this is an interface.

### isFinal

    public boolean isFinal()

  Returns true if this is a final class or interface.

### isAbstract

    public boolean isAbstract()

  Returns true if this is an abstract class or an interface.

### getAccessFlags

    public int getAccessFlags()

  Returns access flags.

  See Also:
    `AccessFlag`

### setAccessFlags

    public void setAccessFlags(int acc)

  Changes access flags.

  See Also:
    `AccessFlag`

### getName

    public java.lang.String getName()

  Returns the class name.

### setName

    public void setName(java.lang.String name)

  Sets the class name. This method substitutes the new name for all occurrences of the old class name in the class file.

### getSuperclass

    public java.lang.String getSuperclass()

  Returns the super class name.

### getSuperclassId

    public int getSuperclassId()

  Returns the index of the constant pool entry representing the super class.

### setSuperclass

    public void setSuperclass(java.lang.String superclass)
                       throws CannotCompileException

  Sets the super class.

  This method modifies constructors so that they call constructors declared in the new super class.

    `CannotCompileException`

### renameClass

    public final void renameClass(java.lang.String oldname,
                                  java.lang.String newname)

  Replaces all occurrences of a class name in the class file.

  If class X is substituted for class Y in the class file, X and Y must have the same signature. If Y provides a method m(), X must provide it even if X inherits m() from the super class. If this fact is not guaranteed, the bytecode verifier may cause an error.

  Parameters:
    `oldname` - the replaced class name
    `newname` - the substituted class name

### renameClass

    public final void renameClass(java.util.Map classnames)

  Replaces all occurrences of several class names in the class file.

  Parameters:
    `classnames` - specifies which class name is replaced with which new name. Class names must be described with the JVM-internal representation like `java/lang/Object`.
  See Also:
    `renameClass(String,String)`

### getInterfaces

    public java.lang.String[] getInterfaces()

  Returns the names of the interfaces implemented by the class.

### setInterfaces

    public void setInterfaces(java.lang.String[] nameList)

  Sets the interfaces.

  Parameters:
    `nameList` - the names of the interfaces.

### addInterface

    public void addInterface(java.lang.String name)

  Appends an interface to the interfaces implemented by the class.

### getFields

    public java.util.List getFields()

  Returns all the fields declared in the class.

  Returns:
    a list of `FieldInfo`.
  See Also:
    `FieldInfo`

### addField

    public void addField(FieldInfo finfo)

  Appends a field to the class.

### getMethods

    public java.util.List getMethods()

  Returns all the methods declared in the class.

  Returns:
    a list of `MethodInfo`.
  See Also:
    `MethodInfo`

### getMethod

    public MethodInfo getMethod(java.lang.String name)

  Returns the method with the specified name. If there are multiple methods with that name, this method returns one of them.

  Returns:
    null if no such a method is found.

### getStaticInitializer

    public MethodInfo getStaticInitializer()

  Returns a static initializer (class initializer), or null if it does not exist.

### addMethod

    public void addMethod(MethodInfo minfo)

  Appends a method to the class.

### getAttributes

    public java.util.List getAttributes()

  Returns all the attributes.

  Returns:
    a list of `AttributeInfo` objects.
  See Also:
    `AttributeInfo`

### getAttribute

    public AttributeInfo getAttribute(java.lang.String name)

  Returns the attribute with the specified name.

  Parameters:
    `name` - attribute name

### addAttribute

    public void addAttribute(AttributeInfo info)

  Appends an attribute. If there is already an attribute with the same name, the new one substitutes for it.

### getSourceFile

    public java.lang.String getSourceFile()

  Returns the source file containing this class.

  Returns:
    null if this information is not available.

### write

    public void write(java.io.DataOutputStream out)
               throws java.io.IOException

  Writes a class file represened by this object into an output stream.

    `java.io.IOException`

Overview | Package | Class | Use | Tree | Deprecated | Index
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Javassist, a Java-bytecode translator toolkit. Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.