Class ClassParser
java.lang.Object
edu.umd.cs.findbugs.classfile.engine.ClassParser
- All Implemented Interfaces:
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 ClassesModifier and TypeClassDescription(package private) static class(package private) static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ICodeBaseEntryprivate static final String[]private ClassParser.Constant[]private final ClassDescriptorprivate final DataInputStream -
Constructor Summary
ConstructorsConstructorDescriptionClassParser(DataInputStream in, ClassDescriptor expectedClassDescriptor, ICodeBaseEntry codeBaseEntry) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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 Collection<ClassDescriptor> Extract references to other classes.static voidextractReferencedClassesFromSignature(Set<ClassDescriptor> referencedClassSet, String signature) private ClassDescriptorgetClassDescriptor(int index) Get the ClassDescriptor of a class referenced in the constant pool.private StringgetClassName(int index) Get a class name from a CONSTANT_Class.private StringgetSignatureFromNameAndType(int index) Get the signature from a CONSTANT_NameAndType.private 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.ConstantRead a constant from the constant pool.
-
Field Details
-
in
-
expectedClassDescriptor
-
codeBaseEntry
-
constantPool
-
CONSTANT_FORMAT_MAP
-
-
Constructor Details
-
ClassParser
public ClassParser(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 Details
-
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
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 Collection<ClassDescriptor> extractReferencedClasses() throws InvalidClassFileFormatExceptionExtract references to other classes.- Returns:
- array of ClassDescriptors of referenced classes
- Throws:
InvalidClassFileFormatException
-
extractReferencedClassesFromSignature
public static void extractReferencedClassesFromSignature(Set<ClassDescriptor> referencedClassSet, String signature) -
readConstant
Read a constant from the constant pool. Return null for- Returns:
- a StaticConstant
- Throws:
InvalidClassFileFormatExceptionIOException
-
getClassName
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
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
Get 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
Check 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
Get the signature from a CONSTANT_NameAndType.- Parameters:
index- the index of the CONSTANT_NameAndType- Returns:
- the signature
- Throws:
InvalidClassFileFormatException
-