|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.rej.java.ClassFile
public class ClassFile
ClassFile
objects represent .class files. They're constructed
either by parsing a byte array or a stream with net.sf.rej.java.Disassembler
, using the Constructor or using the net.sf.rej.java.ClassFactory
class.
Nested Class Summary | |
---|---|
static class |
ClassFile.OffsetTag
|
Constructor Summary | |
---|---|
ClassFile()
Initializes this ClassFile object. |
Method Summary | |
---|---|
void |
add(Field field)
Adds a field to this class. |
void |
add(Method method)
Adds a method to this class. |
boolean |
equals(java.lang.Object obj)
Checks for equality. |
int |
getAccessFlags()
Returns the class-level access flags of this class. |
java.lang.String |
getAccessString()
Returns the class-level access modifiers of the class modeled by this object as a String. |
Attributes |
getAttributes()
Returns an Attributes object, containing the class-level attributes of this
class - if it has any. |
byte[] |
getData()
Serializes this class. |
java.util.List<Field> |
getFields()
Returns a read-only list of the fields in this class. |
java.lang.String |
getFullClassName()
Returns the full class name, including the package definition part. |
java.util.List<Interface> |
getInterfaces()
Returns a read-only list of the interfaces implemented by this class. |
java.lang.String |
getJavaVersionCompabilityString()
Returns a String describing the Java version compability of this class. |
byte[] |
getMagic()
Returns the default magic for Java class files. |
int |
getMajorVersion()
Returns the major version of this class. |
java.util.List<Method> |
getMethods()
Returns a read-only list of the methods in this class. |
int |
getMinorVersion()
Returns the minor version of this class. |
java.util.Map<java.lang.Object,Range> |
getOffsetMap()
Returns a map of offsets of each significant element of the class file. |
java.lang.String |
getPackageName()
Returns the name of the package defined for the class presented by this object. |
ConstantPool |
getPool()
Returns the ConstantPool object which models the constant pool associated with this ClassFile object. |
java.lang.String |
getShortClassName()
Returns the short name of this class, in other words, the name without the package definition part. |
int |
getSuperClass()
Returns the index to the constant pool ClassRef item which describes the parent class of the class represented by this ClassFile
object. |
java.lang.String |
getSuperClassName()
Returns the full class name of the parent class of the class modeled by this object. |
int |
getThisClass()
Returns the index to the constant pool ClassRef item which describes the class represented by this ClassFile object. |
ClassVersion |
getVersion()
Returns the major and minor version of this class in a ClassVersion
object. |
int |
hashCode()
|
void |
remove(Field field)
Removes the given field from this class. |
void |
remove(Method method)
Removes the given method from this class. |
void |
setAccessFlags(int accessFlags)
Sets the class-level access flags of this class. |
void |
setAttributes(Attributes attributes)
Sets the attributes object for this class, discarding the old one. |
void |
setFields(java.util.List<Field> fields)
Sets all the fields for this class. |
void |
setInterfaces(java.util.List<Interface> interfaces)
Sets all the interfaces for this class. |
void |
setMajorVersion(int majorVersion)
Sets the major version of this class. |
void |
setMethods(java.util.List<Method> methods)
Sets all the methods for this class. |
void |
setMinorVersion(int minorVersion)
Sets the minor version of this class. |
void |
setPool(ConstantPool pool)
Sets the constant pool for this class. |
void |
setSuperClass(int superClass)
Sets the index to the constant pool ClassRef item which defines the parent class of the class modeled by this ClassFile object. |
void |
setThisClass(int thisClass)
Sets the index to the constant pool ClassRef item which defines the class modeled by this ClassFile object. |
void |
setVersion(ClassVersion version)
Sets the major and minor versions of this class. |
void |
validateMagic(byte[] magic)
Validates the magic given as a parameter. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ClassFile()
ClassFile
object. Note that
this object is not yet valid for deserialization until several
attributes of this class have been set.
Method Detail |
---|
public int getAccessFlags()
net.sf.rej.java.AccessFlags
.
public int getMajorVersion()
net.sf.rej.java.ClassVersion
class.
public int getMinorVersion()
net.sf.rej.java.ClassVersion
class.
public void setMajorVersion(int majorVersion)
net.sf.rej.java.ClassVersion
class.
majorVersion
- the new major version for this class.public void setMinorVersion(int minorVersion)
net.sf.rej.java.ClassVersion
class.
minorVersion
- the new minor version for this class.public ClassVersion getVersion()
ClassVersion
object. For a more thorough description
of how the version maps into different Java compability settings,
see the net.sf.rej.java.ClassVersion
class.
public void setVersion(ClassVersion version)
version
- public java.util.List<Method> getMethods()
net.sf.rej.java.Method
objects.
Modifying this list does not affect this class.
Modifying the methods contained in the list does affect this class.
public void add(Method method)
net.sf.rej.java.Method
objects, see net.sf.rej.java.MethodFactory
class.
method
- a method (or static code block, or constructor)
to add to this class.public void add(Field field)
net.sf.rej.java.Field
objects, see net.sf.rej.java.FieldFactory
class.
field
- a field to add to this class.public java.util.List<Interface> getInterfaces()
net.sf.rej.java.Interface
objects. Modifying this list does not affect this class. Modifying
the Interface
objects contained in the list does affect this
class.
public int getThisClass()
ClassFile
object.
public Attributes getAttributes()
Attributes
object, containing the class-level attributes of this
class - if it has any. The object returned is not a copy and any modifications
to it or the attributes contained in it will affect this class.
public int getSuperClass()
ClassFile
object.
public java.util.List<Field> getFields()
net.sf.rej.java.Field
objects.
Modifying the list returned will not affect this class.
Modifying the fields contained in the list will affect this class.
public ConstantPool getPool()
ClassFile
object. The object returned is not a copy
and any modification to it will modify this class file as well.
public byte[] getMagic()
0xcafebabe
public void setAccessFlags(int accessFlags)
net.sf.rej.java.AccessFlags
.
accessFlags
- the class-level access-flags.public void setMethods(java.util.List<Method> methods)
methods
- the list of methods (or static code block, or constructor)
for this class.public void setInterfaces(java.util.List<Interface> interfaces)
interfaces
- the list of interfaces for this class.public void setThisClass(int thisClass)
ClassFile
object.
thisClass
- index to the constant pool.public void setAttributes(Attributes attributes)
attributes
- an attributes object containing 0-n attributes.public void setSuperClass(int superClass)
ClassFile
object.
superClass
- index to the constant pool.public void setFields(java.util.List<Field> fields)
fields
- the list of fields for this class.public void setPool(ConstantPool pool)
pool
- new constant pool.public void validateMagic(byte[] magic) throws java.lang.RuntimeException
RuntimeException
is thrown.
magic
- the magic to validate.
java.lang.RuntimeException
- the validation failed.public byte[] getData()
ClassLoader
.
public java.util.Map<java.lang.Object,Range> getOffsetMap()
ClassFile
object is modified. The keys in the map are
of type OffsetTag
, Interface
,
Field
and Method
.
public java.lang.String getShortClassName()
java.lang.String
this method returns "String".
public java.lang.String getFullClassName()
"net.sf.rej.java.ClassFile"
.
public java.lang.String getSuperClassName()
ClassFile
object modeling
the class java.lang.String
this method will return
"java.lang.Object"
.
public java.lang.String getAccessString()
public java.lang.String getPackageName()
String
is returned.
public void remove(Method method)
Method
class the removal only works
if the Method
object given as parameter is one of the
Method
objects stored in this class's list of methods.
method
- the method to remove.public void remove(Field field)
Field
class the removal only works
if the Field
object given as parameter is one of the
Field
objects stored in this class's list of fields.
field
- the field to remove.public java.lang.String getJavaVersionCompabilityString()
The Java virtual machine implementation of Sun’s JDK release 1.0.2 supports class file format versions 45.0 through 45.3 inclusive. Sun’s JDK releases 1.1.X can support class file formats of versions in the range 45.0 through 45.65535 inclusive. For implementations of version 1.k of the Java 2 platform can support class file formats of versions in the range 45.0 through 44+k.0 inclusive.
String
such as "1.5".public boolean equals(java.lang.Object obj)
ClassFile
objects.
equals
in class java.lang.Object
obj
- the object to compare to this object.
public int hashCode()
hashCode
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |