edu.umd.cs.findbugs.ba
Class AnalysisContext

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.AnalysisContext

public class AnalysisContext
extends java.lang.Object

A context for analysis of a complete project. This serves as the repository for whole-program information and data structures.

Author:
David Hovemeyer

Field Summary
 java.util.Map<java.lang.Object,java.lang.Object> analysisLocals
           
static java.lang.String DEFAULT_CHECK_FOR_NULL_PARAM_DATABASE_FILENAME
           
static java.lang.String DEFAULT_NONNULL_PARAM_DATABASE_FILENAME
           
static java.lang.String DEFAULT_NULL_RETURN_VALUE_ANNOTATION_DATABASE
           
static java.lang.String DEFAULT_NULL_RETURN_VALUE_DB_FILENAME
           
static java.lang.String UNCONDITIONAL_DEREF_DB_FILENAME
           
 
Constructor Summary
AnalysisContext(RepositoryLookupFailureCallback lookupFailureCallback)
          Constructor.
 
Method Summary
 void addApplicationClassToRepository(org.apache.bcel.classfile.JavaClass appClass)
          Add an application class to the repository.
 void addClasspathEntry(java.lang.String url)
          Add an entry to the Repository's classpath.
 void clearClassContextCache()
          Clear the ClassContext cache.
 void clearRepository()
          Clear the BCEL Repository in preparation for analysis.
static AnalysisContext currentAnalysisContext()
          Get the AnalysisContext associated with this thread
 boolean getBoolProperty(int prop)
          Get a boolean property.
 CheckReturnAnnotationDatabase getCheckReturnAnnotationDatabase()
           
 ClassContext getClassContext(org.apache.bcel.classfile.JavaClass javaClass)
          Get the ClassContext for a class.
 java.lang.String getDatabaseInputDir()
          Get the interprocedural database input directory.
 java.lang.String getDatabaseOutputDir()
          Get the interprocedural database output directory.
 FieldStoreTypeDatabase getFieldStoreTypeDatabase()
          Get the property database recording the types of values stored into fields.
 RepositoryLookupFailureCallback getLookupFailureCallback()
          Get the lookup failure callback.
 NullnessAnnotationDatabase getNullnessAnnotationDatabase()
           
 SourceFinder getSourceFinder()
          Get the SourceFinder, for finding source files.
 SourceInfoMap getSourceInfoMap()
          Get the SourceInfoMap.
 Subtypes getSubtypes()
          Get the Subtypes database.
 ParameterNullnessPropertyDatabase getUnconditionalDerefParamDatabase()
           
 void initDatabases()
          Instantiate the CheckReturnAnnotationDatabase.
 boolean isApplicationClass(org.apache.bcel.classfile.JavaClass cls)
          Return whether or not the given class is an application class.
 boolean isApplicationClass(java.lang.String className)
          Return whether or not the given class is an application class.
 void loadInterproceduralDatabases()
          If possible, load interprocedural property databases.
<DatabaseType extends PropertyDatabase<KeyType,Property>,KeyType,Property>
DatabaseType
loadPropertyDatabase(DatabaseType database, java.lang.String fileName, java.lang.String description)
          Load an interprocedural property database.
 org.apache.bcel.classfile.JavaClass lookupClass(java.lang.String className)
          Lookup a class.
 java.lang.String lookupSourceFile(java.lang.String className)
          Lookup a class's sourfe file
static void reportMissingClass(java.lang.ClassNotFoundException e)
           
 void setBoolProperty(int prop, boolean value)
          Set a boolean property.
 void setDatabaseInputDir(java.lang.String databaseInputDir)
          Set the interprocedural database input directory.
 void setDatabaseOutputDir(java.lang.String databaseOutputDir)
          Set the interprocedural database output directory.
 void setSourcePath(java.util.List<java.lang.String> sourcePath)
          Set the source path.
 void setUnconditionalDerefParamDatabase(ParameterNullnessPropertyDatabase unconditionalDerefParamDatabase)
           
<DatabaseType extends PropertyDatabase<KeyType,Property>,KeyType,Property>
void
storePropertyDatabase(DatabaseType database, java.lang.String fileName, java.lang.String description)
          Write an interprocedural property database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

DEFAULT_NULL_RETURN_VALUE_DB_FILENAME

public static final java.lang.String DEFAULT_NULL_RETURN_VALUE_DB_FILENAME
See Also:
Constant Field Values

analysisLocals

public java.util.Map<java.lang.Object,java.lang.Object> analysisLocals
Constructor Detail

AnalysisContext

public AnalysisContext(RepositoryLookupFailureCallback lookupFailureCallback)
Constructor.

Method Detail

getNullnessAnnotationDatabase

public NullnessAnnotationDatabase getNullnessAnnotationDatabase()

getCheckReturnAnnotationDatabase

public CheckReturnAnnotationDatabase getCheckReturnAnnotationDatabase()

initDatabases

public void initDatabases()
Instantiate the CheckReturnAnnotationDatabase. Do this after the repository has been set up.


currentAnalysisContext

public static AnalysisContext currentAnalysisContext()
Get the AnalysisContext associated with this thread


reportMissingClass

public static void reportMissingClass(java.lang.ClassNotFoundException e)

getLookupFailureCallback

public RepositoryLookupFailureCallback getLookupFailureCallback()
Get the lookup failure callback.


setSourcePath

public void setSourcePath(java.util.List<java.lang.String> sourcePath)
Set the source path.


getSourceFinder

public SourceFinder getSourceFinder()
Get the SourceFinder, for finding source files.


getSubtypes

public Subtypes getSubtypes()
Get the Subtypes database.

Returns:
the Subtypes database

clearRepository

public void clearRepository()
Clear the BCEL Repository in preparation for analysis.


clearClassContextCache

public void clearClassContextCache()
Clear the ClassContext cache. This should be done between analysis passes.


addClasspathEntry

public void addClasspathEntry(java.lang.String url)
                       throws java.io.IOException
Add an entry to the Repository's classpath.

Parameters:
url - the classpath entry URL
Throws:
java.io.IOException

addApplicationClassToRepository

public void addApplicationClassToRepository(org.apache.bcel.classfile.JavaClass appClass)
Add an application class to the repository.

Parameters:
appClass - the application class

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(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

lookupClass

public org.apache.bcel.classfile.JavaClass lookupClass(@NonNull
                                                       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

lookupSourceFile

public java.lang.String lookupSourceFile(@NonNull
                                         java.lang.String className)
Lookup a class's sourfe file

Parameters:
className - the name of the class
Returns:
the source file for the class, or SourceLineAnnotation.UNKNOWN_SOURCE_FILE if unable to determine

getClassContext

public ClassContext getClassContext(org.apache.bcel.classfile.JavaClass javaClass)
Get the ClassContext for a class.

Parameters:
javaClass - the class
Returns:
the ClassContext for that class

loadInterproceduralDatabases

public void loadInterproceduralDatabases()
If possible, load interprocedural property databases.


setBoolProperty

public void setBoolProperty(int prop,
                            boolean value)
Set a boolean property.

Parameters:
prop - the property to set
value - the value of the property

getBoolProperty

public 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 SourceInfoMap getSourceInfoMap()
Get the SourceInfoMap.


setDatabaseInputDir

public void setDatabaseInputDir(java.lang.String databaseInputDir)
Set the interprocedural database input directory.

Parameters:
databaseInputDir - the interprocedural database input directory

getDatabaseInputDir

public java.lang.String getDatabaseInputDir()
Get the interprocedural database input directory.

Returns:
the interprocedural database input directory

setDatabaseOutputDir

public void setDatabaseOutputDir(java.lang.String databaseOutputDir)
Set the interprocedural database output directory.

Parameters:
databaseOutputDir - the interprocedural database output directory

getDatabaseOutputDir

public java.lang.String getDatabaseOutputDir()
Get the interprocedural database output directory.

Returns:
the interprocedural database output directory

getFieldStoreTypeDatabase

public 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

setUnconditionalDerefParamDatabase

public void setUnconditionalDerefParamDatabase(ParameterNullnessPropertyDatabase unconditionalDerefParamDatabase)

getUnconditionalDerefParamDatabase

public ParameterNullnessPropertyDatabase getUnconditionalDerefParamDatabase()

loadPropertyDatabase

public <DatabaseType extends PropertyDatabase<KeyType,Property>,KeyType,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 database
KeyType - type of key (e.g., method or field)
Property - type of properties stored in the database
Parameters:
database - the empty database object
fileName - file to load database from
description - 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,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 database
KeyType - type of key (e.g., method or field)
Property - type of properties stored in the database
Parameters:
database - the database
fileName - name of database file
description - description of the database