Package de.inetsoftware.classparser
Class ClassFile
- java.lang.Object
-
- de.inetsoftware.classparser.ClassFile
-
public class ClassFile extends java.lang.Objecthttp://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 classClassFile.Type
-
Field Summary
Fields Modifier and Type Field Description private intaccessFlagsprivate java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>annotationsprivate Attributesattributesprivate BootstrapMethod[]bootstrapMethodsprivate ConstantPoolconstantPoolprivate FieldInfo[]fieldsprivate ConstantClass[]interfacesprivate intmajorVersionprivate MethodInfo[]methodsprivate intminorVersionprivate ConstantClasssuperClassprivate java.lang.StringsuperSignatureprivate ConstantClassthisClassprivate java.lang.StringthisSignature
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetAccessFlags()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 nullBootstrapMethodgetBootstrapMethod(int methodIdx)Get the x-the BootstrapMethod.ConstantPoolgetConstantPool()Get the constant pool of the the current class.FieldInfogetField(java.lang.String name)FieldInfo[]getFields()Get the fields of the class.ConstantClass[]getInterfaces()MethodInfogetMethod(java.lang.String name, java.lang.String signature)Find a method via name and signature.MethodInfo[]getMethods()java.lang.StringgetSourceFile()Get value of SourceFile if available.ConstantClassgetSuperClass()java.lang.StringgetSuperSignature()Get the signature of the super class with generic types.ConstantClassgetThisClass()java.lang.StringgetThisSignature()Get the signature of the class with generic types.ClassFile.TypegetType()Get the type of class.booleanisAbstract()If the class is abstractbooleanisEnum()If the class is an Enumvoidpartial(ClassFile partialClassFile)Extends this class with the methods and fields of the partial class.private voidpatchConstantPool(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.IOExceptionLoad 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.IOExceptionGet 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.IOExceptionGet 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
-
-