Package edu.umd.cs.findbugs.ba
Class AnalysisContext
java.lang.Object
edu.umd.cs.findbugs.ba.AnalysisContext
- All Implemented Interfaces:
AutoCloseable
A context for analysis of a complete project. This serves as the repository
for whole-program information and data structures.
NOTE: this class is slated to become obsolete. New code should use the IAnalysisCache object returned by Global.getAnalysisCache() to access all analysis information (global databases, class and method analyses, etc.)
- Author:
- David Hovemeyer
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClasspathEntry
(String url) Add an entry to the Repository's classpath.void
static boolean
void
void
Clear the ClassContext cache.void
Clear the BCEL Repository in preparation for analysis.void
close()
static AnalysisContext
Get the AnalysisContext associated with this threadstatic XFactory
final boolean
getBoolProperty
(int prop) Get a boolean property.getClassContext
(org.apache.bcel.classfile.JavaClass javaClass) Get the ClassContext for a class.Get stats about hit rate for ClassContext cache.int
getClassSize
(ClassDescriptor desc) protected <E> E
getDatabase
(Class<E> cls) final String
Get the interprocedural database input directory.final String
Get the interprocedural database output directory.Get the property database recording the types of values stored into fields.Get the lookup failure callback.Get the property database recording which methods always return nonnull valuesGet the SourceFinder, for finding source files.Get the SourceInfoMap.Get the Subtypes2 inheritance hierarchy database.Get the property database recording which methods unconditionally dereference parameters.Get Collection of all XClass objects seen so far.void
Instantiate the CheckReturnAnnotationDatabase.boolean
boolean
isApplicationClass
(String className) Return whether or not the given class is an application class.boolean
isApplicationClass
(org.apache.bcel.classfile.JavaClass cls) Return whether or not the given class is an application class.boolean
isTooBig
(ClassDescriptor desc) final void
If possible, load default (built-in) interprocedural property databases.final void
If possible, load interprocedural property databases.<DatabaseType extends PropertyDatabase<KeyType,
Property>, KeyType extends FieldOrMethodDescriptor, Property>
DatabaseTypeloadPropertyDatabase
(DatabaseType database, String fileName, String description) Load an interprocedural property database.<DatabaseType extends PropertyDatabase<KeyType,
Property>, KeyType extends FieldOrMethodDescriptor, Property>
DatabaseTypeloadPropertyDatabaseFromResource
(DatabaseType database, String resourceName, String description) Load an interprocedural property database.void
logAnError
(String msg) static void
Report an errorstatic void
Report an errororg.apache.bcel.classfile.JavaClass
lookupClass
(ClassDescriptor classDescriptor) Lookup a class.org.apache.bcel.classfile.JavaClass
lookupClass
(String className) Lookup a class.final String
lookupSourceFile
(String dottedClassName) Lookup a class's source filestatic org.apache.bcel.classfile.JavaClass
lookupSystemClass
(String className) This is equivalent to Repository.lookupClass() or this.lookupClass(), except it uses the original Repository instead of the current one.static void
static void
static void
static void
static void
file a ClassNotFoundException with the lookupFailureCallbackvoid
setAppClassList
(List<ClassDescriptor> appClassCollection) final void
setBoolProperty
(int prop, boolean value) Set a boolean property.void
setBridgeMethod
(MethodInfo from, MethodInfo to) void
setClassBeingAnalyzed
(ClassDescriptor classBeingAnalyzed) void
setClassSummary
(ClassSummary classSummary) static void
setCurrentAnalysisContext
(AnalysisContext analysisContext) Set the current analysis context for this thread.final void
setDatabaseInputDir
(String databaseInputDir) Set the interprocedural database input directory.final void
setDatabaseOutputDir
(String databaseOutputDir) Set the interprocedural database output directory.void
setFieldSummary
(FieldSummary fieldSummary) boolean
setMissingClassWarningsSuppressed
(boolean value) void
setUnreadFields
(UnreadFields unreadFields) <DatabaseType extends PropertyDatabase<KeyType,
Property>, KeyType extends FieldOrMethodDescriptor, Property>
voidstorePropertyDatabase
(DatabaseType database, String fileName, String description) Write an interprocedural property database.boolean
void
updateDatabases
(int pass) After a pass has been completed, allow the analysis context to update information.
-
Field Details
-
DEBUG
public static final boolean DEBUG -
IGNORE_BUILTIN_MODELS
public static final boolean IGNORE_BUILTIN_MODELS -
DEFAULT_NONNULL_PARAM_DATABASE_FILENAME
- See Also:
-
DEFAULT_CHECK_FOR_NULL_PARAM_DATABASE_FILENAME
- See Also:
-
DEFAULT_NULL_RETURN_VALUE_ANNOTATION_DATABASE
- See Also:
-
UNCONDITIONAL_DEREF_DB_FILENAME
- See Also:
-
NONNULL_RETURN_DB_FILENAME
- See Also:
-
UNCONDITIONAL_DEREF_DB_RESOURCE
- See Also:
-
NONNULL_RETURN_DB_RESOURCE
- See Also:
-
DEFAULT_NULL_RETURN_VALUE_DB_FILENAME
- See Also:
-
lookupFailureCallback
-
-
Constructor Details
-
AnalysisContext
-
-
Method Details
-
currentAnalysisContext
Get the AnalysisContext associated with this thread -
currentXFactory
-
getClassBeingAnalyzed
-
setClassBeingAnalyzed
-
clearClassBeingAnalyzed
public void clearClassBeingAnalyzed() -
getClassSummary
-
setClassSummary
-
getEqualsKindSummary
-
getFieldSummary
-
setFieldSummary
-
getUnreadFieldsData
-
getUnreadFields
-
unreadFieldsAvailable
public boolean unreadFieldsAvailable() -
setUnreadFields
-
reportMissingClass
file a ClassNotFoundException with the lookupFailureCallback- See Also:
-
reportMissingClass
-
analyzingApplicationClass
public static boolean analyzingApplicationClass() -
reportMissingClass
-
reportMissingClass
-
logError
Report an error -
logError
Report an error -
logAnError
-
analysisSkippedDueToInvokeDynamic
-
setMissingClassWarningsSuppressed
public boolean setMissingClassWarningsSuppressed(boolean value) -
isApplicationClass
public boolean isApplicationClass(org.apache.bcel.classfile.JavaClass cls) Return whether or not the given class is an application class.- Parameters:
cls
- the class to lookup- Returns:
- true if the class is an application class, false if not an application class or if the class cannot be located
-
isApplicationClass
Return whether or not the given class is an application class.- Parameters:
className
- name of a class- Returns:
- true if the class is an application class, false if not an application class or if the class cannot be located
-
isApplicationClass
-
getClassSize
-
isTooBig
-
lookupClass
public org.apache.bcel.classfile.JavaClass lookupClass(@Nonnull ClassDescriptor classDescriptor) throws ClassNotFoundException Lookup a class. Use this method instead of Repository.lookupClass().- Parameters:
classDescriptor
- descriptor specifying the class to look up- Returns:
- the class
- Throws:
ClassNotFoundException
- if the class can't be found
-
lookupSystemClass
public static org.apache.bcel.classfile.JavaClass lookupSystemClass(@Nonnull String className) throws ClassNotFoundException This is equivalent to Repository.lookupClass() or this.lookupClass(), except it uses the original Repository instead of the current one. This can be important because URLClassPathRepository objects are closed after an analysis, so JavaClass objects obtained from them are no good on subsequent runs.- Parameters:
className
- the name of the class- Returns:
- the JavaClass representing the class
- Throws:
ClassNotFoundException
-
lookupSourceFile
Lookup a class's source file- Parameters:
dottedClassName
- the name of the class- Returns:
- the source file for the class, or
SourceLineAnnotation.UNKNOWN_SOURCE_FILE
if unable to determine
-
loadInterproceduralDatabases
public final void loadInterproceduralDatabases()If possible, load interprocedural property databases. -
loadDefaultInterproceduralDatabases
public final void loadDefaultInterproceduralDatabases()If possible, load default (built-in) interprocedural property databases. These are the databases for things like Java core APIs that unconditional dereference parameters. -
setBoolProperty
Set a boolean property.- Parameters:
prop
- the property to setvalue
- the value of the property
-
getBoolProperty
Get a boolean property.- Parameters:
prop
- the property- Returns:
- value of the property; defaults to false if the property has not had a value assigned explicitly
-
setDatabaseInputDir
Set the interprocedural database input directory.- Parameters:
databaseInputDir
- the interprocedural database input directory
-
getDatabaseInputDir
Get the interprocedural database input directory.- Returns:
- the interprocedural database input directory
-
setDatabaseOutputDir
Set the interprocedural database output directory.- Parameters:
databaseOutputDir
- the interprocedural database output directory
-
getDatabaseOutputDir
Get the interprocedural database output directory.- Returns:
- the interprocedural database output directory
-
loadPropertyDatabase
public <DatabaseType extends PropertyDatabase<KeyType,Property>, DatabaseType loadPropertyDatabaseKeyType extends FieldOrMethodDescriptor, Property> (DatabaseType database, String fileName, String description) Load an interprocedural property database.- Type Parameters:
DatabaseType
- actual type of the databaseKeyType
- type of key (e.g., method or field)Property
- type of properties stored in the database- Parameters:
database
- the empty database objectfileName
- file to load database fromdescription
- description of the database (for diagnostics)- Returns:
- the database object, or null if the database couldn't be loaded
-
loadPropertyDatabaseFromResource
public <DatabaseType extends PropertyDatabase<KeyType,Property>, DatabaseType loadPropertyDatabaseFromResourceKeyType extends FieldOrMethodDescriptor, Property> (DatabaseType database, String resourceName, String description) Load an interprocedural property database.- Type Parameters:
DatabaseType
- actual type of the databaseKeyType
- type of key (e.g., method or field)Property
- type of properties stored in the database- Parameters:
database
- the empty database objectresourceName
- name of resource to load the database fromdescription
- description of the database (for diagnostics)- Returns:
- the database object, or null if the database couldn't be loaded
-
storePropertyDatabase
public <DatabaseType extends PropertyDatabase<KeyType,Property>, void storePropertyDatabaseKeyType extends FieldOrMethodDescriptor, Property> (DatabaseType database, String fileName, String description) Write an interprocedural property database.- Type Parameters:
DatabaseType
- actual type of the databaseKeyType
- type of key (e.g., method or field)Property
- type of properties stored in the database- Parameters:
database
- the databasefileName
- name of database filedescription
- description of the database
-
setCurrentAnalysisContext
Set the current analysis context for this thread.- Parameters:
analysisContext
- the current analysis context for this thread
-
removeCurrentAnalysisContext
public static void removeCurrentAnalysisContext() -
getXClassCollection
Get Collection of all XClass objects seen so far.- Returns:
- Collection of all XClass objects seen so far
-
getSuppressionMatcher
-
addClasspathEntry
Add an entry to the Repository's classpath.- Parameters:
url
- the classpath entry URL- Throws:
IOException
-
clearClassContextCache
public void clearClassContextCache()Clear the ClassContext cache. This should be done between analysis passes. -
clearRepository
public void clearRepository()Clear the BCEL Repository in preparation for analysis. -
getAnnotationRetentionDatabase
-
getCheckReturnAnnotationDatabase
-
getClassContext
Get the ClassContext for a class.- Parameters:
javaClass
- the class- Returns:
- the ClassContext for that class
-
getClassContextStats
Get stats about hit rate for ClassContext cache.- Returns:
- stats about hit rate for ClassContext cache
-
getFieldStoreTypeDatabase
Get the property database recording the types of values stored into fields.- Returns:
- the database, or null if there is no database available
-
getJCIPAnnotationDatabase
-
getLookupFailureCallback
Get the lookup failure callback. -
getSourceFinder
Get the SourceFinder, for finding source files. -
getSourceInfoMap
Get the SourceInfoMap. -
getUnconditionalDerefParamDatabase
Get the property database recording which methods unconditionally dereference parameters.- Returns:
- the database, or null if there is no database available
-
initDatabases
public void initDatabases()Instantiate the CheckReturnAnnotationDatabase. Do this after the repository has been set up. -
lookupClass
public org.apache.bcel.classfile.JavaClass lookupClass(@Nonnull @DottedClassName String className) throws ClassNotFoundException Lookup a class. Use this method instead of Repository.lookupClass().- Parameters:
className
- the name of the class- Returns:
- the JavaClass representing the class
- Throws:
ClassNotFoundException
- (but not really)
-
getInnerClassAccessMap
-
setAppClassList
-
updateDatabases
public void updateDatabases(int pass) After a pass has been completed, allow the analysis context to update information.- Parameters:
pass
- -- the first pass is pass 0
-
getReturnValueNullnessPropertyDatabase
Get the property database recording which methods always return nonnull values- Returns:
- the database, or null if there is no database available
-
getSubtypes2
Get the Subtypes2 inheritance hierarchy database. -
getDirectlyRelevantTypeQualifiersDatabase
-
getBridgeTo
-
getBridgeFrom
-
setBridgeMethod
-
getNullnessAnnotationDatabase
-
getDatabase
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-