Class ClassParser
- java.lang.Object
-
- edu.umd.cs.findbugs.classfile.engine.ClassParser
-
- All Implemented Interfaces:
ClassParserInterface
public class ClassParser extends java.lang.Object implements ClassParserInterface
Parse a class to extract symbolic information. see http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classClassParser.Constant(package private) static interfaceClassParser.FieldOrMethodDescriptorCreator<E>
-
Field Summary
Fields Modifier and Type Field Description private ICodeBaseEntrycodeBaseEntryprivate static java.lang.String[]CONSTANT_FORMAT_MAPprivate ClassParser.Constant[]constantPoolprivate ClassDescriptorexpectedClassDescriptorprivate java.io.DataInputStreamin
-
Constructor Summary
Constructors Constructor Description ClassParser(java.io.DataInputStream in, ClassDescriptor expectedClassDescriptor, ICodeBaseEntry codeBaseEntry)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckConstantPoolIndex(int index)Check that a constant pool index is valid.private voidcheckConstantTag(ClassParser.Constant constant, int expectedTag)Check that a constant has the expected tag.private java.util.Collection<ClassDescriptor>extractReferencedClasses()Extract references to other classes.static voidextractReferencedClassesFromSignature(java.util.Set<ClassDescriptor> referencedClassSet, java.lang.String signature)private ClassDescriptorgetClassDescriptor(int index)Get the ClassDescriptor of a class referenced in the constant pool.private java.lang.StringgetClassName(int index)Get a class name from a CONSTANT_Class.private java.lang.StringgetSignatureFromNameAndType(int index)Get the signature from a CONSTANT_NameAndType.private java.lang.StringgetUtf8String(int refIndex)Get the UTF-8 string constant at given constant pool index.voidparse(ClassInfo.Builder builder)Parse the class data into a ClassInfo object containing (some of) the class's symbolic information.voidparse(ClassNameAndSuperclassInfo.Builder builder)Parse the class data into a ClassNameAndSuperclassInfo object containing (some of) the class's symbolic information.private ClassParser.ConstantreadConstant()Read a constant from the constant pool.
-
-
-
Field Detail
-
in
private final java.io.DataInputStream in
-
expectedClassDescriptor
private final ClassDescriptor expectedClassDescriptor
-
codeBaseEntry
private final ICodeBaseEntry codeBaseEntry
-
constantPool
private ClassParser.Constant[] constantPool
-
CONSTANT_FORMAT_MAP
private static final java.lang.String[] CONSTANT_FORMAT_MAP
-
-
Constructor Detail
-
ClassParser
public ClassParser(java.io.DataInputStream in, @CheckForNull ClassDescriptor expectedClassDescriptor, ICodeBaseEntry codeBaseEntry)Constructor.- Parameters:
in- the DataInputStream to read class data fromexpectedClassDescriptor- ClassDescriptor expected: null if unknowncodeBaseEntry- codebase entry class is loaded from
-
-
Method Detail
-
parse
public void parse(ClassNameAndSuperclassInfo.Builder builder) throws InvalidClassFileFormatException
Description copied from interface:ClassParserInterfaceParse the class data into a ClassNameAndSuperclassInfo object containing (some of) the class's symbolic information.- Specified by:
parsein interfaceClassParserInterface- Parameters:
builder- a ClassNameAndSuperclassInfo object to be filled in with (some of) the class's symbolic information- Throws:
InvalidClassFileFormatException
-
parse
public void parse(ClassInfo.Builder builder) throws InvalidClassFileFormatException
Description copied from interface:ClassParserInterfaceParse the class data into a ClassInfo object containing (some of) the class's symbolic information.- Specified by:
parsein interfaceClassParserInterface- Parameters:
builder- a ClassInfo object to be filled in with (some of) the class's symbolic information- Throws:
InvalidClassFileFormatException
-
extractReferencedClasses
private java.util.Collection<ClassDescriptor> extractReferencedClasses() throws InvalidClassFileFormatException
Extract references to other classes.- Returns:
- array of ClassDescriptors of referenced classes
- Throws:
InvalidClassFileFormatException
-
extractReferencedClassesFromSignature
public static void extractReferencedClassesFromSignature(java.util.Set<ClassDescriptor> referencedClassSet, java.lang.String signature)
-
readConstant
private ClassParser.Constant readConstant() throws InvalidClassFileFormatException, java.io.IOException
Read a constant from the constant pool. Return null for- Returns:
- a StaticConstant
- Throws:
InvalidClassFileFormatExceptionjava.io.IOException
-
getClassName
@SlashedClassName private java.lang.String getClassName(int index) throws InvalidClassFileFormatException
Get a class name from a CONSTANT_Class. Note that this may be an array (e.g., "[Ljava/lang/String;").- Parameters:
index- index of the constant- Returns:
- the class name
- Throws:
InvalidClassFileFormatException
-
getClassDescriptor
private ClassDescriptor getClassDescriptor(int index) throws InvalidClassFileFormatException
Get the ClassDescriptor of a class referenced in the constant pool.- Parameters:
index- index of the referenced class in the constant pool- Returns:
- the ClassDescriptor of the referenced class
- Throws:
InvalidClassFileFormatException
-
getUtf8String
private java.lang.String getUtf8String(int refIndex) throws InvalidClassFileFormatExceptionGet the UTF-8 string constant at given constant pool index.- Parameters:
refIndex- the constant pool index- Returns:
- the String at that index
- Throws:
InvalidClassFileFormatException
-
checkConstantPoolIndex
private void checkConstantPoolIndex(int index) throws InvalidClassFileFormatExceptionCheck that a constant pool index is valid.- Parameters:
index- the index to check- Throws:
InvalidClassFileFormatException- if the index is not valid
-
checkConstantTag
private void checkConstantTag(ClassParser.Constant constant, int expectedTag) throws InvalidClassFileFormatException
Check that a constant has the expected tag.- Parameters:
constant- the constant to checkexpectedTag- the expected constant tag- Throws:
InvalidClassFileFormatException- if the constant's tag does not match the expected tag
-
getSignatureFromNameAndType
private java.lang.String getSignatureFromNameAndType(int index) throws InvalidClassFileFormatExceptionGet the signature from a CONSTANT_NameAndType.- Parameters:
index- the index of the CONSTANT_NameAndType- Returns:
- the signature
- Throws:
InvalidClassFileFormatException
-
-