Package org.jboss.classfilewriter
Class ClassFile
- java.lang.Object
-
- org.jboss.classfilewriter.ClassFile
-
- All Implemented Interfaces:
WritableEntry
public class ClassFile extends java.lang.Object implements WritableEntry
-
-
Field Summary
Fields Modifier and Type Field Description private int
accessFlags
private java.util.List<Attribute>
attributes
private byte[]
bytecode
private ConstPool
constPool
private static java.lang.reflect.Method
defineClass1
private static java.lang.reflect.Method
defineClass2
private java.util.Set<ClassField>
fields
private java.util.List<java.lang.String>
interfaces
private java.util.Set<ClassMethod>
methods
private java.lang.String
name
private AnnotationsAttribute
runtimeVisibleAnnotationsAttribute
private java.lang.String
superclass
private int
version
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassMethod
addConstructor(java.lang.reflect.Constructor<?> method)
Adds a constructor with the same signiture as the given constrcutor, including exception typesClassField
addField(int accessFlags, java.lang.String name, java.lang.Class<?> type)
ClassField
addField(int accessFlags, java.lang.String name, java.lang.Class<?> type, java.lang.String genericSignature)
ClassField
addField(int accessFlags, java.lang.String name, java.lang.String descriptor)
Adds a field with the given name and descriptor.ClassField
addField(int accessFlags, java.lang.String name, java.lang.String descriptor, java.lang.String signature)
ClassField
addField(java.lang.reflect.Field field)
void
addInterface(java.lang.String iface)
ClassMethod
addMethod(int accessFlags, java.lang.String name, java.lang.String returnType, java.lang.String... parameters)
ClassMethod
addMethod(java.lang.reflect.Method method)
Adds a method with the same signiture as the given method, including exception typesjava.lang.Class<?>
define(java.lang.ClassLoader loader)
java.lang.Class<?>
define(java.lang.ClassLoader loader, java.security.ProtectionDomain domain)
Definines the class using the given ClassLoader and ProtectionDomainConstPool
getConstPool()
java.lang.String
getDescriptor()
returns the type descriptor for the classjava.util.Set<ClassField>
getFields()
java.util.List<java.lang.String>
getInterfaces()
java.util.Set<ClassMethod>
getMethods()
java.lang.String
getName()
Returns the generated class nameAnnotationsAttribute
getRuntimeVisibleAnnotationsAttribute()
java.lang.String
getSuperclass()
byte[]
toBytecode()
void
write(ByteArrayDataOutputStream stream)
-
-
-
Field Detail
-
name
private final java.lang.String name
-
superclass
private final java.lang.String superclass
-
accessFlags
private final int accessFlags
-
version
private final int version
-
constPool
private final ConstPool constPool
-
interfaces
private final java.util.List<java.lang.String> interfaces
-
fields
private final java.util.Set<ClassField> fields
-
methods
private final java.util.Set<ClassMethod> methods
-
bytecode
private byte[] bytecode
-
attributes
private final java.util.List<Attribute> attributes
-
runtimeVisibleAnnotationsAttribute
private final AnnotationsAttribute runtimeVisibleAnnotationsAttribute
-
defineClass1
private static java.lang.reflect.Method defineClass1
-
defineClass2
private static java.lang.reflect.Method defineClass2
-
-
Method Detail
-
addInterface
public void addInterface(java.lang.String iface)
-
addField
public ClassField addField(int accessFlags, java.lang.String name, java.lang.String descriptor)
Adds a field with the given name and descriptor.
-
addField
public ClassField addField(int accessFlags, java.lang.String name, java.lang.String descriptor, java.lang.String signature)
-
addField
public ClassField addField(int accessFlags, java.lang.String name, java.lang.Class<?> type)
-
addField
public ClassField addField(int accessFlags, java.lang.String name, java.lang.Class<?> type, java.lang.String genericSignature)
-
addField
public ClassField addField(java.lang.reflect.Field field)
-
addMethod
public ClassMethod addMethod(int accessFlags, java.lang.String name, java.lang.String returnType, java.lang.String... parameters)
-
addMethod
public ClassMethod addMethod(java.lang.reflect.Method method)
Adds a method with the same signiture as the given method, including exception typesThe new method will have the same modifier as the original method, except that the abstract and native flags will be stripped.
TODO: annotations and signiture attribute
-
addConstructor
public ClassMethod addConstructor(java.lang.reflect.Constructor<?> method)
Adds a constructor with the same signiture as the given constrcutor, including exception typesTODO: annotations and signiture attribute
-
write
public void write(ByteArrayDataOutputStream stream) throws java.io.IOException
- Specified by:
write
in interfaceWritableEntry
- Throws:
java.io.IOException
-
define
public java.lang.Class<?> define(java.lang.ClassLoader loader)
-
define
public java.lang.Class<?> define(java.lang.ClassLoader loader, java.security.ProtectionDomain domain)
Definines the class using the given ClassLoader and ProtectionDomain
-
toBytecode
public byte[] toBytecode()
-
getConstPool
public ConstPool getConstPool()
-
getDescriptor
public java.lang.String getDescriptor()
returns the type descriptor for the class- Returns:
-
getRuntimeVisibleAnnotationsAttribute
public AnnotationsAttribute getRuntimeVisibleAnnotationsAttribute()
-
getName
public java.lang.String getName()
Returns the generated class name- Returns:
- The generated class name
-
getSuperclass
public java.lang.String getSuperclass()
- Returns:
- The generated superclass name
-
getInterfaces
public java.util.List<java.lang.String> getInterfaces()
- Returns:
- The interfaces implemented by this class
-
getFields
public java.util.Set<ClassField> getFields()
- Returns:
- This class's fields
-
getMethods
public java.util.Set<ClassMethod> getMethods()
- Returns:
- This classes methods
-
-