Package de.inetsoftware.classparser
Class ClassFile
- java.lang.Object
-
- de.inetsoftware.classparser.ClassFile
-
public class ClassFile extends java.lang.Object
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 Modifier and Type Class Description static class
ClassFile.Type
-
Field Summary
Fields Modifier and Type Field Description private int
accessFlags
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>
annotations
private Attributes
attributes
private BootstrapMethod[]
bootstrapMethods
private ConstantPool
constantPool
private FieldInfo[]
fields
private ConstantClass[]
interfaces
private int
majorVersion
private MethodInfo[]
methods
private int
minorVersion
private ConstantClass
superClass
private java.lang.String
superSignature
private ConstantClass
thisClass
private java.lang.String
thisSignature
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getAccessFlags()
The access flags of the class.java.util.Map<java.lang.String,java.lang.Object>
getAnnotation(java.lang.String annotation)
Get a single annotation or nullBootstrapMethod
getBootstrapMethod(int methodIdx)
Get the x-the BootstrapMethod.ConstantPool
getConstantPool()
Get the constant pool of the the current class.FieldInfo
getField(java.lang.String name)
FieldInfo[]
getFields()
Get the fields of the class.ConstantClass[]
getInterfaces()
MethodInfo
getMethod(java.lang.String name, java.lang.String signature)
Find a method via name and signature.MethodInfo[]
getMethods()
java.lang.String
getSourceFile()
Get value of SourceFile if available.ConstantClass
getSuperClass()
java.lang.String
getSuperSignature()
Get the signature of the super class with generic types.ConstantClass
getThisClass()
java.lang.String
getThisSignature()
Get the signature of the class with generic types.ClassFile.Type
getType()
Get the type of class.boolean
isAbstract()
If the class is abstractboolean
isEnum()
If the class is an Enumvoid
partial(ClassFile partialClassFile)
Extends this class with the methods and fields of the partial class.private void
patchConstantPool(java.lang.String origClassName, ConstantClass thisClass)
Replace the reference to the Class in the the constant pool.private FieldInfo[]
readFields(java.io.DataInputStream input)
private MethodInfo[]
readMethods(java.io.DataInputStream input)
-
-
-
Field Detail
-
minorVersion
private final int minorVersion
-
majorVersion
private final int majorVersion
-
constantPool
private final ConstantPool constantPool
-
accessFlags
private final int accessFlags
-
thisClass
private final ConstantClass thisClass
-
superClass
private final ConstantClass superClass
-
interfaces
private final ConstantClass[] interfaces
-
fields
private FieldInfo[] fields
-
methods
private MethodInfo[] methods
-
attributes
private final Attributes attributes
-
thisSignature
private java.lang.String thisSignature
-
superSignature
private java.lang.String superSignature
-
annotations
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>> annotations
-
bootstrapMethods
private BootstrapMethod[] bootstrapMethods
-
-
Constructor Detail
-
ClassFile
public ClassFile(java.io.InputStream stream) throws java.io.IOException
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:
java.io.IOException
- if this input stream reaches the end before reading the class file.
-
ClassFile
public ClassFile(java.lang.String className, ClassFile classFile)
Create a replaced instance.- Parameters:
className
- the class name that should be replacedclassFile
- the replacing class file data
-
-
Method Detail
-
patchConstantPool
private void patchConstantPool(java.lang.String origClassName, ConstantClass thisClass)
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
public java.lang.String getSourceFile() throws java.io.IOException
Get value of SourceFile if available.- Returns:
- the source file name or null.
- Throws:
java.io.IOException
- if an I/O error occurs.
-
getAnnotation
@Nullable public java.util.Map<java.lang.String,java.lang.Object> getAnnotation(java.lang.String annotation) throws java.io.IOException
Get a single annotation or null- Parameters:
annotation
- the class name of the annotation- Returns:
- the value or null if not exists
- Throws:
java.io.IOException
- if any I/O error occur
-
getBootstrapMethod
public BootstrapMethod getBootstrapMethod(int methodIdx) throws java.io.IOException
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:
java.io.IOException
- if any error occur
-
getConstantPool
public ConstantPool getConstantPool()
Get the constant pool of the the current class.- Returns:
- the constant pool
-
getThisClass
public ConstantClass getThisClass()
-
getSuperClass
public ConstantClass getSuperClass()
-
getInterfaces
public ConstantClass[] getInterfaces()
-
getMethods
public MethodInfo[] getMethods()
-
getMethod
public MethodInfo getMethod(java.lang.String name, java.lang.String signature)
Find a method via name and signature.- Parameters:
name
- the namesignature
- the signature- Returns:
- the method or null if not found
-
getField
public FieldInfo getField(java.lang.String name)
-
getFields
public FieldInfo[] 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:
Class.isInterface()
-
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
private FieldInfo[] readFields(java.io.DataInputStream input) throws java.io.IOException
- Throws:
java.io.IOException
-
readMethods
private MethodInfo[] readMethods(java.io.DataInputStream input) throws java.io.IOException
- Throws:
java.io.IOException
-
getThisSignature
public java.lang.String getThisSignature()
Get the signature of the class with generic types.- Returns:
- the signature
-
getSuperSignature
public java.lang.String getSuperSignature()
Get the signature of the super class with generic types.- Returns:
- the signature
-
getType
public ClassFile.Type getType()
Get the type of class.- Returns:
- the type of the class
-
partial
public void partial(ClassFile partialClassFile) throws java.io.IOException
Extends this class with the methods and fields of the partial class.- Parameters:
partialClassFile
- extension of the class- Throws:
java.io.IOException
- If any I/O error occur
-
-