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 intaccessFlagsprivate java.util.List<Attribute>attributesprivate byte[]bytecodeprivate ConstPoolconstPoolprivate static java.lang.reflect.MethoddefineClass1private static java.lang.reflect.MethoddefineClass2private java.util.Set<ClassField>fieldsprivate java.util.List<java.lang.String>interfacesprivate java.util.Set<ClassMethod>methodsprivate java.lang.Stringnameprivate AnnotationsAttributeruntimeVisibleAnnotationsAttributeprivate java.lang.Stringsuperclassprivate intversion
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassMethodaddConstructor(java.lang.reflect.Constructor<?> method)Adds a constructor with the same signiture as the given constrcutor, including exception typesClassFieldaddField(int accessFlags, java.lang.String name, java.lang.Class<?> type)ClassFieldaddField(int accessFlags, java.lang.String name, java.lang.Class<?> type, java.lang.String genericSignature)ClassFieldaddField(int accessFlags, java.lang.String name, java.lang.String descriptor)Adds a field with the given name and descriptor.ClassFieldaddField(int accessFlags, java.lang.String name, java.lang.String descriptor, java.lang.String signature)ClassFieldaddField(java.lang.reflect.Field field)voidaddInterface(java.lang.String iface)ClassMethodaddMethod(int accessFlags, java.lang.String name, java.lang.String returnType, java.lang.String... parameters)ClassMethodaddMethod(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 ProtectionDomainConstPoolgetConstPool()java.lang.StringgetDescriptor()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.StringgetName()Returns the generated class nameAnnotationsAttributegetRuntimeVisibleAnnotationsAttribute()java.lang.StringgetSuperclass()byte[]toBytecode()voidwrite(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:
writein 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
-
-