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 class
ClassParser.Constant
(package private) static interface
ClassParser.FieldOrMethodDescriptorCreator<E>
-
Field Summary
Fields Modifier and Type Field Description private ICodeBaseEntry
codeBaseEntry
private static java.lang.String[]
CONSTANT_FORMAT_MAP
private ClassParser.Constant[]
constantPool
private ClassDescriptor
expectedClassDescriptor
private java.io.DataInputStream
in
-
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 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 java.util.Collection<ClassDescriptor>
extractReferencedClasses()
Extract references to other classes.static void
extractReferencedClassesFromSignature(java.util.Set<ClassDescriptor> referencedClassSet, java.lang.String signature)
private ClassDescriptor
getClassDescriptor(int index)
Get the ClassDescriptor of a class referenced in the constant pool.private java.lang.String
getClassName(int index)
Get a class name from a CONSTANT_Class.private java.lang.String
getSignatureFromNameAndType(int index)
Get the signature from a CONSTANT_NameAndType.private java.lang.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
readConstant()
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: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
public void parse(ClassInfo.Builder builder) throws InvalidClassFileFormatException
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 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:
InvalidClassFileFormatException
java.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 InvalidClassFileFormatException
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
private void checkConstantPoolIndex(int index) throws InvalidClassFileFormatException
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
private java.lang.String getSignatureFromNameAndType(int index) throws InvalidClassFileFormatException
Get the signature from a CONSTANT_NameAndType.- Parameters:
index
- the index of the CONSTANT_NameAndType- Returns:
- the signature
- Throws:
InvalidClassFileFormatException
-
-