|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.ibm.wala.shrikeCT.ClassWriter
public final class ClassWriter
This class formats and writes class data into JVM format.
| Nested Class Summary | |
|---|---|
static class |
ClassWriter.Element
An Element is an object that can be serialized into a byte buffer. |
static class |
ClassWriter.RawElement
A RawElement is an Element that is already available as some chunk of a byte buffer. |
| Field Summary |
|---|
| Fields inherited from interface com.ibm.wala.shrikeCT.ClassConstants |
|---|
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_Class, CONSTANT_Double, CONSTANT_FieldRef, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodRef, CONSTANT_Long, CONSTANT_MethodRef, CONSTANT_NameAndType, CONSTANT_String, CONSTANT_Utf8, MAGIC |
| Constructor Summary | |
|---|---|
ClassWriter()
Create a blank ClassWriter with no methods, fields, or attributes, an empty constant pool, no super class, no implemented interfaces, no name, majorVersion 46, and minorVersion 0. |
|
| Method Summary | |
|---|---|
void |
addClassAttribute(ClassWriter.Element attribute)
Add an atttribute to the class. |
int |
addCPClass(java.lang.String s)
Add a Class to the constant pool if necessary. |
int |
addCPDouble(double d)
Add a Double to the constant pool if necessary. |
int |
addCPFieldRef(java.lang.String c,
java.lang.String n,
java.lang.String t)
Add a FieldRef to the constant pool if necessary. |
int |
addCPFloat(float f)
Add a Float to the constant pool if necessary. |
int |
addCPInt(int i)
Add an Integer to the constant pool if necessary. |
int |
addCPInterfaceMethodRef(java.lang.String c,
java.lang.String n,
java.lang.String t)
Add an InterfaceMethodRef to the constant pool if necessary. |
int |
addCPLong(long l)
Add a Long to the constant pool if necessary. |
int |
addCPMethodRef(java.lang.String c,
java.lang.String n,
java.lang.String t)
Add a MethodRef to the constant pool if necessary. |
int |
addCPNAT(java.lang.String n,
java.lang.String t)
Add a NameAndType to the constant pool if necessary. |
int |
addCPString(java.lang.String s)
Add a String to the constant pool if necessary. |
int |
addCPUtf8(java.lang.String s)
Add a Utf8 string to the constant pool if necessary. |
void |
addField(int access,
int name,
int type,
ClassWriter.Element[] attributes)
Add a field to the class. |
void |
addField(int access,
java.lang.String name,
java.lang.String type,
ClassWriter.Element[] attributes)
Add a field to the class. |
void |
addMethod(int access,
int name,
int type,
ClassWriter.Element[] attributes)
Add a method to the class. |
void |
addMethod(int access,
java.lang.String name,
java.lang.String type,
ClassWriter.Element[] attributes)
Add a method to the class. |
void |
addRawField(ClassWriter.Element e)
Add a field to the class, the field data given as "raw" bytes (probably obtained from a ClassReader). |
void |
addRawMethod(ClassWriter.Element e)
Add a method to the class, the method data given as "raw" bytes (probably obtained from a ClassReader). |
byte[] |
makeBytes()
After you've added everything you need to the class, call this method to generate the actual class file data. |
void |
setAccessFlags(int f)
Set the access flags for the class. |
static void |
setDouble(byte[] buf,
int offset,
double v)
Set the 8 bytes at offset 'offset' in 'buf' to the double value in v. |
static void |
setFloat(byte[] buf,
int offset,
float v)
Set the 4 bytes at offset 'offset' in 'buf' to the float value in v. |
void |
setForceAddCPEntries(boolean force)
|
static void |
setInt(byte[] buf,
int offset,
int v)
Set the 4 bytes at offset 'offset' in 'buf' to the signed 32-bit value in v. |
void |
setInterfaceNameIndices(int[] ifaces)
Set the constant pool indices for the names of the implemented interfaces. |
void |
setInterfaceNames(java.lang.String[] ifaces)
Set the names of the implemented interfaces. |
static void |
setLong(byte[] buf,
int offset,
long v)
Set the 8 bytes at offset 'offset' in 'buf' to the signed 64-bit value in v. |
void |
setMajorVersion(int major)
Set the class file format major version. |
void |
setMinorVersion(int minor)
Set the class file format minor version. |
void |
setName(java.lang.String c)
Set the name of the class. |
void |
setNameIndex(int c)
Set the constant pool index for the name of the class. |
void |
setRawCP(ConstantPoolParser cp,
boolean cacheEntries)
Copy a constant pool from some ClassReader into this class. |
void |
setSuperName(java.lang.String c)
Set the name of the superclass; if c is null, then there is no superclass (this must be java/lang/Object). |
void |
setSuperNameIndex(int c)
Set the constant pool index for the name of the superclass. |
static void |
setUByte(byte[] buf,
int offset,
int v)
Set the byte at offset 'offset' in 'buf' to the unsigned 8-bit value in v. |
static void |
setUShort(byte[] buf,
int offset,
int v)
Set the 2 bytes at offset 'offset' in 'buf' to the unsigned 16-bit value in v. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ClassWriter()
| Method Detail |
|---|
public void setMajorVersion(int major)
public void setMinorVersion(int minor)
public void setRawCP(ConstantPoolParser cp,
boolean cacheEntries)
throws InvalidClassFileException,
java.lang.IllegalArgumentException
cacheEntries - records whether to parse the raw constant pool completely so that
if new entries are required which are the same as entries already
in the raw pool, the existing entries in the raw pool are used
instead. Setting this to 'true' produces smaller constant pools
but may slow down performance because the raw pool must be
completely parsed
InvalidClassFileException
java.lang.IllegalArgumentExceptionpublic void setForceAddCPEntries(boolean force)
force - true iff you want the addCP methods to always create a new
constant pool entry and never reuse an existing constant pool
entrypublic int addCPUtf8(java.lang.String s)
public int addCPInt(int i)
public int addCPFloat(float f)
public int addCPLong(long l)
public int addCPDouble(double d)
public int addCPString(java.lang.String s)
public int addCPClass(java.lang.String s)
s - the class name, in JVM format (e.g., java/lang/Object)
public int addCPFieldRef(java.lang.String c,
java.lang.String n,
java.lang.String t)
c - the class name, in JVM format (e.g., java/lang/Object)n - the field namet - the field type, in JVM format (e.g., I, Z, or Ljava/lang/Object;)
public int addCPMethodRef(java.lang.String c,
java.lang.String n,
java.lang.String t)
c - the class name, in JVM format (e.g., java/lang/Object)n - the method namet - the method type, in JVM format (e.g., V(ILjava/lang/Object;) )
public int addCPInterfaceMethodRef(java.lang.String c,
java.lang.String n,
java.lang.String t)
c - the class name, in JVM format (e.g., java/lang/Object)n - the field namet - the method type, in JVM format (e.g., V(ILjava/lang/Object;) )
public int addCPNAT(java.lang.String n,
java.lang.String t)
n - the namet - the type, in JVM format
public void setAccessFlags(int f)
public void setNameIndex(int c)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic void setSuperNameIndex(int c)
public void setInterfaceNameIndices(int[] ifaces)
public void setName(java.lang.String c)
public void setSuperName(java.lang.String c)
public void setInterfaceNames(java.lang.String[] ifaces)
public void addRawMethod(ClassWriter.Element e)
public void addRawField(ClassWriter.Element e)
public void addMethod(int access,
java.lang.String name,
java.lang.String type,
ClassWriter.Element[] attributes)
access - the access flagsname - the method nametype - the method type in JVM format (e.g., V(ILjava/lang/Object;) )attributes - the attributes in raw form, one Element per attribute
public void addField(int access,
java.lang.String name,
java.lang.String type,
ClassWriter.Element[] attributes)
access - the access flagsname - the field nametype - the field type in JVM format (e.g., I, Z, Ljava/lang/Object;)attributes - the attributes in raw form, one Element per attribute
public void addMethod(int access,
int name,
int type,
ClassWriter.Element[] attributes)
access - the access flagsname - the constant pool index of the method nametype - the constant pool index of the method type in JVM format (e.g.,
V(ILjava/lang/Object;) )attributes - the attributes in raw form, one Element per attribute
public void addField(int access,
int name,
int type,
ClassWriter.Element[] attributes)
access - the access flagsname - the constant pool index of the field nametype - the constant pool index of the field type in JVM format (e.g., I,
Z, Ljava/lang/Object;)attributes - the attributes in raw form, one Element per attributepublic void addClassAttribute(ClassWriter.Element attribute)
attribute - the attribute in raw form
public byte[] makeBytes()
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static void setUByte(byte[] buf,
int offset,
int v)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if buf is null
public static void setInt(byte[] buf,
int offset,
int v)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if buf is null
public static void setLong(byte[] buf,
int offset,
long v)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static void setFloat(byte[] buf,
int offset,
float v)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static void setDouble(byte[] buf,
int offset,
double v)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static void setUShort(byte[] buf,
int offset,
int v)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - if buf is null
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||