Class AnalysisCache

java.lang.Object
edu.umd.cs.findbugs.classfile.impl.AnalysisCache
All Implemented Interfaces:
IAnalysisCache

public class AnalysisCache extends Object implements IAnalysisCache
Implementation of IAnalysisCache. This object is responsible for registering class and method analysis engines and caching analysis results.
Author:
David Hovemeyer
  • Method Details

    • getAnalysisLocals

      public final Map<?,?> getAnalysisLocals()
      Description copied from interface: IAnalysisCache
      Get map of analysis-local objects.
      Specified by:
      getAnalysisLocals in interface IAnalysisCache
    • getClassPath

      public IClassPath getClassPath()
      Description copied from interface: IAnalysisCache
      Get the classpath from which classes are loaded.
      Specified by:
      getClassPath in interface IAnalysisCache
      Returns:
      the classpath
    • purgeAllMethodAnalysis

      public void purgeAllMethodAnalysis()
      Description copied from interface: IAnalysisCache
      Purge all method analysis results for all methods.
      Specified by:
      purgeAllMethodAnalysis in interface IAnalysisCache
    • purgeClassAnalysis

      public void purgeClassAnalysis(Class<?> analysisClass)
      Description copied from interface: IAnalysisCache
      Purge all class analysis results of a particular kind
      Specified by:
      purgeClassAnalysis in interface IAnalysisCache
    • dispose

      public void dispose()
      Cleans up all cached data
    • getClassAnalysis

      @CheckForNull public Map<ClassDescriptor,Object> getClassAnalysis(Class<?> analysisClass)
      Parameters:
      analysisClass - non null analysis type
      Returns:
      map with analysis data for given type, can be null
    • reuseClassAnalysis

      public <E> void reuseClassAnalysis(Class<E> analysisClass, Map<ClassDescriptor,Object> map)
      Adds the data for given analysis type from given map to the cache
      Parameters:
      analysisClass - non null analysis type
      map - non null, pre-filled map with analysis data for given type
    • getClassAnalysis

      public <E> E getClassAnalysis(Class<E> analysisClass, @Nonnull ClassDescriptor classDescriptor) throws CheckedAnalysisException
      Description copied from interface: IAnalysisCache
      Get an analysis of the given class.
      Specified by:
      getClassAnalysis in interface IAnalysisCache
      Type Parameters:
      E - the type of the analysis (e.g., FoobarAnalysis)
      Parameters:
      analysisClass - the analysis class object (e.g., FoobarAnalysis.class)
      classDescriptor - the descriptor of the class to analyze
      Returns:
      the analysis object (e.g., instance of FoobarAnalysis for the class)
      Throws:
      CheckedAnalysisException - if an error occurs performing the analysis
    • probeClassAnalysis

      public <E> E probeClassAnalysis(Class<E> analysisClass, @Nonnull ClassDescriptor classDescriptor)
      Description copied from interface: IAnalysisCache
      See if the cache contains a cached class analysis result for given class descriptor.
      Specified by:
      probeClassAnalysis in interface IAnalysisCache
      Parameters:
      analysisClass - analysis result class
      classDescriptor - the class descriptor
      Returns:
      a cached analysis result, or null if there is no cached analysis result
    • getMethodAnalysis

      public <E> E getMethodAnalysis(Class<E> analysisClass, @Nonnull MethodDescriptor methodDescriptor) throws CheckedAnalysisException
      Description copied from interface: IAnalysisCache
      Get an analysis of the given method.
      Specified by:
      getMethodAnalysis in interface IAnalysisCache
      Type Parameters:
      E - the type of the analysis (e.g., FoobarAnalysis)
      Parameters:
      analysisClass - the analysis class object (e.g., FoobarAnalysis.class)
      methodDescriptor - the descriptor of the method to analyze
      Returns:
      the analysis object (e.g., instance of FoobarAnalysis for the method)
      Throws:
      CheckedAnalysisException - if an error occurs performing the analysis
    • eagerlyPutMethodAnalysis

      public <E> void eagerlyPutMethodAnalysis(Class<E> analysisClass, @Nonnull MethodDescriptor methodDescriptor, E analysisObject)
      Description copied from interface: IAnalysisCache
      Eagerly put a method analysis object in the cache. This can be necessary if an method analysis engine invokes other analysis engines that might recursively require the analysis being produced.
      Specified by:
      eagerlyPutMethodAnalysis in interface IAnalysisCache
      Type Parameters:
      E - the type of the analysis (e.g., FoobarAnalysis)
      Parameters:
      analysisClass - the analysis class object (e.g., FoobarAnalysis.class)
      methodDescriptor - the descriptor of the method to analyze
      analysisObject -
    • purgeMethodAnalyses

      public void purgeMethodAnalyses(@Nonnull MethodDescriptor methodDescriptor)
      Description copied from interface: IAnalysisCache
      Purge all analysis results for given method. This can be called when a CFG is pruned and we want to compute more accurate analysis results on the new CFG.
      Specified by:
      purgeMethodAnalyses in interface IAnalysisCache
      Parameters:
      methodDescriptor - method whose analysis results should be purged
    • registerClassAnalysisEngine

      public <E> void registerClassAnalysisEngine(Class<E> analysisResultType, IClassAnalysisEngine<E> classAnalysisEngine)
      Description copied from interface: IAnalysisCache
      Register the given class analysis engine as producing the analysis result type whose Class is given.
      Specified by:
      registerClassAnalysisEngine in interface IAnalysisCache
      Type Parameters:
      E - analysis result type
      Parameters:
      analysisResultType - analysis result type Class object
      classAnalysisEngine - the class analysis engine to register
    • registerMethodAnalysisEngine

      public <E> void registerMethodAnalysisEngine(Class<E> analysisResultType, IMethodAnalysisEngine<E> methodAnalysisEngine)
      Description copied from interface: IAnalysisCache
      Register the given method analysis engine as producing the analysis result type whose Class is given.
      Specified by:
      registerMethodAnalysisEngine in interface IAnalysisCache
      Type Parameters:
      E - analysis result type
      Parameters:
      analysisResultType - analysis result type Class object
      methodAnalysisEngine - the method analysis engine to register
    • registerDatabaseFactory

      public <E> void registerDatabaseFactory(Class<E> databaseClass, IDatabaseFactory<E> databaseFactory)
      Description copied from interface: IAnalysisCache
      Register a database factory.
      Specified by:
      registerDatabaseFactory in interface IAnalysisCache
      Type Parameters:
      E - type of database
      Parameters:
      databaseClass - Class of database
      databaseFactory - the database factory
    • getDatabase

      public <E> E getDatabase(Class<E> databaseClass)
      Description copied from interface: IAnalysisCache
      Get a database. Note: an unchecked analysis exception will be thrown if the database cannot be instantiated. Since instantiation of most kinds of databases simply involves creating an object (and not opening a file or other failure-prone operation), throwing a CheckedAnalysisException creates too great of an exception-handling burden on analyses and detectors which use databases.
      Specified by:
      getDatabase in interface IAnalysisCache
      Type Parameters:
      E - type of database
      Parameters:
      databaseClass - Class of database
      Returns:
      the database (which is created by a database factory if required)
    • getOptionalDatabase

      @CheckForNull public <E> E getOptionalDatabase(Class<E> databaseClass)
      Specified by:
      getOptionalDatabase in interface IAnalysisCache
    • getDatabase

      public <E> E getDatabase(Class<E> databaseClass, boolean optional)
    • eagerlyPutDatabase

      public <E> void eagerlyPutDatabase(Class<E> databaseClass, E database)
      Description copied from interface: IAnalysisCache
      Eagerly install a database. This avoids the need to register a database factory.
      Specified by:
      eagerlyPutDatabase in interface IAnalysisCache
      Type Parameters:
      E - type of database
      Parameters:
      databaseClass - Class of database
      database - database object
    • getErrorLogger

      public IErrorLogger getErrorLogger()
      Description copied from interface: IAnalysisCache
      Get the error logger.
      Specified by:
      getErrorLogger in interface IAnalysisCache
      Returns:
      the error logger
    • getProfiler

      public Profiler getProfiler()
      Description copied from interface: IAnalysisCache
      Get the analysis profiler instance, never null
      Specified by:
      getProfiler in interface IAnalysisCache