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 ICodeBaseEntry
private static final String[]
private ClassParser.Constant[]
private final ClassDescriptor
private final DataInputStream
-
Constructor Summary
ConstructorsConstructorDescriptionClassParser
(DataInputStream in, ClassDescriptor expectedClassDescriptor, ICodeBaseEntry codeBaseEntry) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkConstantPoolIndex
(int index) Check that a constant pool index is valid.private void
checkConstantTag
(ClassParser.Constant constant, int expectedTag) Check that a constant has the expected tag.private Collection
<ClassDescriptor> Extract references to other classes.static void
extractReferencedClassesFromSignature
(Set<ClassDescriptor> referencedClassSet, String signature) private ClassDescriptor
getClassDescriptor
(int index) Get the ClassDescriptor of a class referenced in the constant pool.private String
getClassName
(int index) Get a class name from a CONSTANT_Class.private String
getSignatureFromNameAndType
(int index) Get the signature from a CONSTANT_NameAndType.private String
getUtf8String
(int refIndex) Get the UTF-8 string constant at given constant pool index.void
parse
(ClassInfo.Builder builder) Parse the class data into a ClassInfo object containing (some of) the class's symbolic information.void
parse
(ClassNameAndSuperclassInfo.Builder builder) Parse the class data into a ClassNameAndSuperclassInfo object containing (some of) the class's symbolic information.private ClassParser.Constant
Read 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:ClassParserInterface
Parse the class data into a ClassNameAndSuperclassInfo object containing (some of) the class's symbolic information.- Specified by:
parse
in 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:ClassParserInterface
Parse the class data into a ClassInfo object containing (some of) the class's symbolic information.- Specified by:
parse
in 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:
InvalidClassFileFormatException
IOException
-
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
-