Package edu.umd.cs.findbugs.ba
Class AnalysisContext
- java.lang.Object
-
- edu.umd.cs.findbugs.ba.AnalysisContext
-
- Direct Known Subclasses:
AnalysisCacheToAnalysisContextAdapter
@NotThreadSafe public abstract class AnalysisContext extends java.lang.ObjectA 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:
IAnalysisCache,Global
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEBUGstatic java.lang.StringDEFAULT_CHECK_FOR_NULL_PARAM_DATABASE_FILENAMEstatic java.lang.StringDEFAULT_NONNULL_PARAM_DATABASE_FILENAMEstatic java.lang.StringDEFAULT_NULL_RETURN_VALUE_ANNOTATION_DATABASEstatic java.lang.StringDEFAULT_NULL_RETURN_VALUE_DB_FILENAMEstatic booleanIGNORE_BUILTIN_MODELSstatic java.lang.StringNONNULL_RETURN_DB_FILENAMEstatic java.lang.StringNONNULL_RETURN_DB_RESOURCEprotected Projectprojectstatic java.lang.StringUNCONDITIONAL_DEREF_DB_FILENAMEstatic java.lang.StringUNCONDITIONAL_DEREF_DB_RESOURCE
-
Constructor Summary
Constructors Modifier Constructor Description protectedAnalysisContext()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddClasspathEntry(java.lang.String url)Add an entry to the Repository's classpath.abstract voidclearClassContextCache()Clear the ClassContext cache.abstract voidclearRepository()Clear the BCEL Repository in preparation for analysis.static AnalysisContextcurrentAnalysisContext()Get the AnalysisContext associated with this threadstatic XFactorycurrentXFactory()abstract AnnotationRetentionDatabasegetAnnotationRetentionDatabase()booleangetBoolProperty(int prop)Get a boolean property.abstract CheckReturnAnnotationDatabasegetCheckReturnAnnotationDatabase()abstract ClassContextgetClassContext(org.apache.bcel.classfile.JavaClass javaClass)Get the ClassContext for a class.abstract java.lang.StringgetClassContextStats()Get stats about hit rate for ClassContext cache.ClassSummarygetClassSummary()java.lang.StringgetDatabaseInputDir()Get the interprocedural database input directory.java.lang.StringgetDatabaseOutputDir()Get the interprocedural database output directory.abstract DirectlyRelevantTypeQualifiersDatabasegetDirectlyRelevantTypeQualifiersDatabase()EqualsKindSummarygetEqualsKindSummary()abstract FieldStoreTypeDatabasegetFieldStoreTypeDatabase()Get the property database recording the types of values stored into fields.FieldSummarygetFieldSummary()abstract InnerClassAccessMapgetInnerClassAccessMap()abstract JCIPAnnotationDatabasegetJCIPAnnotationDatabase()abstract RepositoryLookupFailureCallbackgetLookupFailureCallback()Get the lookup failure callback.abstract INullnessAnnotationDatabasegetNullnessAnnotationDatabase()abstract ReturnValueNullnessPropertyDatabasegetReturnValueNullnessPropertyDatabase()Get the property database recording which methods always return nonnull valuesabstract SourceFindergetSourceFinder()Get the SourceFinder, for finding source files.abstract SourceInfoMapgetSourceInfoMap()Get the SourceInfoMap.abstract Subtypes2getSubtypes2()Get the Subtypes2 inheritance hierarchy database.abstract ParameterNullnessPropertyDatabasegetUnconditionalDerefParamDatabase()Get the property database recording which methods unconditionally dereference parameters.UnreadFieldsgetUnreadFields()java.util.Collection<XClass>getXClassCollection()Get Collection of all XClass objects seen so far.abstract voidinitDatabases()Instantiate the CheckReturnAnnotationDatabase.booleanisApplicationClass(ClassDescriptor desc)booleanisApplicationClass(java.lang.String className)Return whether or not the given class is an application class.booleanisApplicationClass(org.apache.bcel.classfile.JavaClass cls)Return whether or not the given class is an application class.booleanisTooBig(ClassDescriptor desc)voidloadDefaultInterproceduralDatabases()If possible, load default (built-in) interprocedural property databases.voidloadInterproceduralDatabases()If possible, load interprocedural property databases.<DatabaseType extends PropertyDatabase<KeyType,Property>,KeyType extends FieldOrMethodDescriptor,Property>
DatabaseTypeloadPropertyDatabase(DatabaseType database, java.lang.String fileName, java.lang.String description)Load an interprocedural property database.<DatabaseType extends PropertyDatabase<KeyType,Property>,KeyType extends FieldOrMethodDescriptor,Property>
DatabaseTypeloadPropertyDatabaseFromResource(DatabaseType database, java.lang.String resourceName, java.lang.String description)Load an interprocedural property database.static voidlogError(java.lang.String msg)Report an errorstatic voidlogError(java.lang.String msg, java.lang.Exception e)Report an errororg.apache.bcel.classfile.JavaClasslookupClass(ClassDescriptor classDescriptor)Lookup a class.abstract org.apache.bcel.classfile.JavaClasslookupClass(java.lang.String className)Lookup a class.java.lang.StringlookupSourceFile(java.lang.String dottedClassName)Lookup a class's source filestatic org.apache.bcel.classfile.JavaClasslookupSystemClass(java.lang.String className)This is equivalent to Repository.lookupClass() or this.lookupClass(), except it uses the original Repository instead of the current one.static voidremoveCurrentAnalysisContext()static voidreportMissingClass(java.lang.ClassNotFoundException e)file a ClassNotFoundException with the lookupFailureCallbackvoidsetBoolProperty(int prop, boolean value)Set a boolean property.voidsetClassSummary(ClassSummary classSummary)static voidsetCurrentAnalysisContext(AnalysisContext analysisContext)Set the current analysis context for this thread.voidsetDatabaseInputDir(java.lang.String databaseInputDir)Set the interprocedural database input directory.voidsetDatabaseOutputDir(java.lang.String databaseOutputDir)Set the interprocedural database output directory.voidsetFieldSummary(FieldSummary fieldSummary)booleansetMissingClassWarningsSuppressed(boolean value)voidsetProject(Project project)Set the source path.voidsetUnreadFields(UnreadFields unreadFields)<DatabaseType extends PropertyDatabase<KeyType,Property>,KeyType extends FieldOrMethodDescriptor,Property>
voidstorePropertyDatabase(DatabaseType database, java.lang.String fileName, java.lang.String description)Write an interprocedural property database.booleanunreadFieldsAvailable()abstract voidupdateDatabases(int pass)After a pass has been completed, allow the analysis context to update information.
-
-
-
Field Detail
-
DEBUG
public static final boolean DEBUG
-
IGNORE_BUILTIN_MODELS
public static final boolean IGNORE_BUILTIN_MODELS
-
DEFAULT_NONNULL_PARAM_DATABASE_FILENAME
public static final java.lang.String DEFAULT_NONNULL_PARAM_DATABASE_FILENAME
- See Also:
- Constant Field Values
-
DEFAULT_CHECK_FOR_NULL_PARAM_DATABASE_FILENAME
public static final java.lang.String DEFAULT_CHECK_FOR_NULL_PARAM_DATABASE_FILENAME
- See Also:
- Constant Field Values
-
DEFAULT_NULL_RETURN_VALUE_ANNOTATION_DATABASE
public static final java.lang.String DEFAULT_NULL_RETURN_VALUE_ANNOTATION_DATABASE
- See Also:
- Constant Field Values
-
UNCONDITIONAL_DEREF_DB_FILENAME
public static final java.lang.String UNCONDITIONAL_DEREF_DB_FILENAME
- See Also:
- Constant Field Values
-
NONNULL_RETURN_DB_FILENAME
public static final java.lang.String NONNULL_RETURN_DB_FILENAME
- See Also:
- Constant Field Values
-
UNCONDITIONAL_DEREF_DB_RESOURCE
public static final java.lang.String UNCONDITIONAL_DEREF_DB_RESOURCE
- See Also:
- Constant Field Values
-
NONNULL_RETURN_DB_RESOURCE
public static final java.lang.String NONNULL_RETURN_DB_RESOURCE
- See Also:
- Constant Field Values
-
DEFAULT_NULL_RETURN_VALUE_DB_FILENAME
public static final java.lang.String DEFAULT_NULL_RETURN_VALUE_DB_FILENAME
- See Also:
- Constant Field Values
-
project
protected Project project
-
-
Method Detail
-
getNullnessAnnotationDatabase
public abstract INullnessAnnotationDatabase getNullnessAnnotationDatabase()
-
getCheckReturnAnnotationDatabase
public abstract CheckReturnAnnotationDatabase getCheckReturnAnnotationDatabase()
-
getAnnotationRetentionDatabase
public abstract AnnotationRetentionDatabase getAnnotationRetentionDatabase()
-
getJCIPAnnotationDatabase
public abstract JCIPAnnotationDatabase getJCIPAnnotationDatabase()
-
initDatabases
public abstract void initDatabases()
Instantiate the CheckReturnAnnotationDatabase. Do this after the repository has been set up.
-
updateDatabases
public abstract 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
-
currentAnalysisContext
public static AnalysisContext currentAnalysisContext()
Get the AnalysisContext associated with this thread
-
currentXFactory
public static XFactory currentXFactory()
-
getClassSummary
public ClassSummary getClassSummary()
-
setClassSummary
public void setClassSummary(@NonNull ClassSummary classSummary)
-
getEqualsKindSummary
public EqualsKindSummary getEqualsKindSummary()
-
getFieldSummary
public FieldSummary getFieldSummary()
-
setFieldSummary
public void setFieldSummary(@NonNull FieldSummary fieldSummary)
-
getUnreadFields
public UnreadFields getUnreadFields()
-
unreadFieldsAvailable
public boolean unreadFieldsAvailable()
-
setUnreadFields
public void setUnreadFields(@NonNull UnreadFields unreadFields)
-
getDirectlyRelevantTypeQualifiersDatabase
public abstract DirectlyRelevantTypeQualifiersDatabase getDirectlyRelevantTypeQualifiersDatabase()
-
reportMissingClass
public static void reportMissingClass(java.lang.ClassNotFoundException e)
file a ClassNotFoundException with the lookupFailureCallback- See Also:
getLookupFailureCallback()
-
logError
public static void logError(java.lang.String msg, java.lang.Exception e)Report an error
-
logError
public static void logError(java.lang.String msg)
Report an error
-
setMissingClassWarningsSuppressed
public boolean setMissingClassWarningsSuppressed(boolean value)
-
getLookupFailureCallback
public abstract RepositoryLookupFailureCallback getLookupFailureCallback()
Get the lookup failure callback.
-
setProject
public final void setProject(Project project)
Set the source path.
-
getSourceFinder
public abstract SourceFinder getSourceFinder()
Get the SourceFinder, for finding source files.
-
clearRepository
public abstract void clearRepository()
Clear the BCEL Repository in preparation for analysis.
-
clearClassContextCache
public abstract void clearClassContextCache()
Clear the ClassContext cache. This should be done between analysis passes.
-
addClasspathEntry
public abstract void addClasspathEntry(java.lang.String url) throws java.io.IOExceptionAdd an entry to the Repository's classpath.- Parameters:
url- the classpath entry URL- Throws:
java.io.IOException
-
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
public boolean isApplicationClass(@DottedClassName java.lang.String className)
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
public boolean isApplicationClass(ClassDescriptor desc)
-
isTooBig
public boolean isTooBig(ClassDescriptor desc)
-
lookupClass
public abstract org.apache.bcel.classfile.JavaClass lookupClass(@NonNull @DottedClassName java.lang.String className) throws java.lang.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:
java.lang.ClassNotFoundException- (but not really)
-
lookupClass
public org.apache.bcel.classfile.JavaClass lookupClass(@NonNull ClassDescriptor classDescriptor) throws java.lang.ClassNotFoundException
Lookup a class. Use this method instead of Repository.lookupClass().- Parameters:
classDescriptor- descriptor specifying the class to look up- Returns:
- the class
- Throws:
java.lang.ClassNotFoundException- if the class can't be found
-
lookupSystemClass
public static org.apache.bcel.classfile.JavaClass lookupSystemClass(@NonNull java.lang.String className) throws java.lang.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:
java.lang.ClassNotFoundException
-
lookupSourceFile
public final java.lang.String lookupSourceFile(@NonNull @DottedClassName java.lang.String dottedClassName)
Lookup a class's source file- Parameters:
dottedClassName- the name of the class- Returns:
- the source file for the class, or
SourceLineAnnotation.UNKNOWN_SOURCE_FILEif unable to determine
-
getClassContext
public abstract ClassContext getClassContext(org.apache.bcel.classfile.JavaClass javaClass)
Get the ClassContext for a class.- Parameters:
javaClass- the class- Returns:
- the ClassContext for that class
-
getClassContextStats
public abstract java.lang.String getClassContextStats()
Get stats about hit rate for ClassContext cache.- Returns:
- stats about hit rate for ClassContext cache
-
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
public final void setBoolProperty(int prop, boolean value)Set a boolean property.- Parameters:
prop- the property to setvalue- the value of the property
-
getBoolProperty
public final boolean getBoolProperty(int prop)
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
-
getSourceInfoMap
public abstract SourceInfoMap getSourceInfoMap()
Get the SourceInfoMap.
-
setDatabaseInputDir
public final void setDatabaseInputDir(java.lang.String databaseInputDir)
Set the interprocedural database input directory.- Parameters:
databaseInputDir- the interprocedural database input directory
-
getDatabaseInputDir
public final java.lang.String getDatabaseInputDir()
Get the interprocedural database input directory.- Returns:
- the interprocedural database input directory
-
setDatabaseOutputDir
public final void setDatabaseOutputDir(java.lang.String databaseOutputDir)
Set the interprocedural database output directory.- Parameters:
databaseOutputDir- the interprocedural database output directory
-
getDatabaseOutputDir
public final java.lang.String getDatabaseOutputDir()
Get the interprocedural database output directory.- Returns:
- the interprocedural database output directory
-
getFieldStoreTypeDatabase
public abstract FieldStoreTypeDatabase getFieldStoreTypeDatabase()
Get the property database recording the types of values stored into fields.- Returns:
- the database, or null if there is no database available
-
getUnconditionalDerefParamDatabase
public abstract ParameterNullnessPropertyDatabase getUnconditionalDerefParamDatabase()
Get the property database recording which methods unconditionally dereference parameters.- Returns:
- the database, or null if there is no database available
-
getReturnValueNullnessPropertyDatabase
public abstract ReturnValueNullnessPropertyDatabase getReturnValueNullnessPropertyDatabase()
Get the property database recording which methods always return nonnull values- Returns:
- the database, or null if there is no database available
-
loadPropertyDatabase
public <DatabaseType extends PropertyDatabase<KeyType,Property>,KeyType extends FieldOrMethodDescriptor,Property> DatabaseType loadPropertyDatabase(DatabaseType database, java.lang.String fileName, java.lang.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>,KeyType extends FieldOrMethodDescriptor,Property> DatabaseType loadPropertyDatabaseFromResource(DatabaseType database, java.lang.String resourceName, java.lang.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>,KeyType extends FieldOrMethodDescriptor,Property> void storePropertyDatabase(DatabaseType database, java.lang.String fileName, java.lang.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
-
getInnerClassAccessMap
public abstract InnerClassAccessMap getInnerClassAccessMap()
-
setCurrentAnalysisContext
public static void setCurrentAnalysisContext(AnalysisContext analysisContext)
Set the current analysis context for this thread.- Parameters:
analysisContext- the current analysis context for this thread
-
removeCurrentAnalysisContext
public static void removeCurrentAnalysisContext()
-
getSubtypes2
public abstract Subtypes2 getSubtypes2()
Get the Subtypes2 inheritance hierarchy database.
-
getXClassCollection
public java.util.Collection<XClass> getXClassCollection()
Get Collection of all XClass objects seen so far.- Returns:
- Collection of all XClass objects seen so far
-
-