Package de.inetsoftware.classparser
Class ClassFile
java.lang.Object
de.inetsoftware.classparser.ClassFile
http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html
http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
private final Attributes
private BootstrapMethod[]
private final ConstantPool
private FieldInfo[]
private final ConstantClass[]
private final int
private MethodInfo[]
private final int
private final ConstantClass
private String
private final ConstantClass
private String
-
Constructor Summary
ConstructorsConstructorDescriptionClassFile
(InputStream stream) Load a class file and create a model of the class.Create a replaced instance. -
Method Summary
Modifier and TypeMethodDescriptionint
The access flags of the class.getAnnotation
(String annotation) Get a single annotation or nullgetBootstrapMethod
(int methodIdx) Get the x-the BootstrapMethod.Get the constant pool of the the current class.Get the fields of the class.Find a method via name and signature.Get value of SourceFile if available.Get the signature of the super class with generic types.Get the signature of the class with generic types.getType()
Get the type of class.boolean
If the class is abstractboolean
isEnum()
If the class is an Enumvoid
Extends this class with the methods and fields of the partial class.private void
patchConstantPool
(String origClassName, ConstantClass thisClass) Replace the reference to the Class in the the constant pool.private FieldInfo[]
readFields
(DataInputStream input) private MethodInfo[]
readMethods
(DataInputStream input)
-
Field Details
-
minorVersion
private final int minorVersion -
majorVersion
private final int majorVersion -
constantPool
-
accessFlags
private final int accessFlags -
thisClass
-
superClass
-
interfaces
-
fields
-
methods
-
attributes
-
thisSignature
-
superSignature
-
annotations
-
bootstrapMethods
-
-
Constructor Details
-
ClassFile
Load a class file and create a model of the class.- Parameters:
stream
- The InputStream of the class file. Will be closed if finish.- Throws:
IOException
- if this input stream reaches the end before reading the class file.
-
ClassFile
Create a replaced instance.- Parameters:
className
- the class name that should be replacedclassFile
- the replacing class file data
-
-
Method Details
-
patchConstantPool
Replace the reference to the Class in the the constant pool.- Parameters:
origClassName
- the class name that should be replaced.thisClass
- the reference of the class that should be used.
-
getSourceFile
Get value of SourceFile if available.- Returns:
- the source file name or null.
- Throws:
IOException
- if an I/O error occurs.
-
getAnnotation
Get a single annotation or null- Parameters:
annotation
- the class name of the annotation- Returns:
- the value or null if not exists
- Throws:
IOException
- if any I/O error occur
-
getBootstrapMethod
Get the x-the BootstrapMethod. Bootstrap methods are used for creating an lambda object.- Parameters:
methodIdx
- the index of the method- Returns:
- the method
- Throws:
IOException
- if any error occur
-
getConstantPool
Get the constant pool of the the current class.- Returns:
- the constant pool
-
getThisClass
-
getSuperClass
-
getInterfaces
-
getMethods
-
getMethod
Find a method via name and signature.- Parameters:
name
- the namesignature
- the signature- Returns:
- the method or null if not found
-
getField
-
getFields
Get the fields of the class.- Returns:
- the fields
-
getAccessFlags
public int getAccessFlags()The access flags of the class. http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.1-200-E http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#23242- Returns:
- the flag
- See Also:
-
isAbstract
public boolean isAbstract()If the class is abstract- Returns:
- true, if abstract class
-
isEnum
public boolean isEnum()If the class is an Enum- Returns:
- true, if Enum class
-
readFields
- Throws:
IOException
-
readMethods
- Throws:
IOException
-
getThisSignature
Get the signature of the class with generic types.- Returns:
- the signature
-
getSuperSignature
Get the signature of the super class with generic types.- Returns:
- the signature
-
getType
Get the type of class.- Returns:
- the type of the class
-
partial
Extends this class with the methods and fields of the partial class.- Parameters:
partialClassFile
- extension of the class- Throws:
IOException
- If any I/O error occur
-