edu.umd.cs.findbugs
Class ResourceTrackingDetector<Resource,ResourceTrackerType extends ResourceTracker<Resource>>

java.lang.Object
  extended by edu.umd.cs.findbugs.ResourceTrackingDetector<Resource,ResourceTrackerType>
All Implemented Interfaces:
Detector
Direct Known Subclasses:
FindOpenStream, FindUnreleasedLock

public abstract class ResourceTrackingDetector<Resource,ResourceTrackerType extends ResourceTracker<Resource>>
extends java.lang.Object
implements Detector

Abstract implementation of a Detector to find methods where a particular kind of created resource is not cleaned up or closed properly. Subclasses should override the abstract methods to determine what kinds of resources are tracked by the detector.

Author:
David Hovemeyer

Field Summary
private  AnalysisContext analysisContext
           
protected  BugReporter bugReporter
           
private static boolean DEBUG
           
private static java.lang.String DEBUG_METHOD_NAME
           
 
Fields inherited from interface edu.umd.cs.findbugs.Detector
EXP_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
 
Constructor Summary
ResourceTrackingDetector(BugReporter bugReporter)
           
 
Method Summary
 void analyzeMethod(ClassContext classContext, org.apache.bcel.classfile.Method method, ResourceTrackerType resourceTracker, ResourceCollection<Resource> resourceCollection)
           
private  ResourceCollection<Resource> buildResourceCollection(ClassContext classContext, org.apache.bcel.classfile.Method method, ResourceTrackerType resourceTracker)
           
protected  AnalysisContext getAnalysisContext()
          Get the AnalysisContext.
abstract  ResourceTrackerType getResourceTracker(ClassContext classContext, org.apache.bcel.classfile.Method method)
           
abstract  void inspectResult(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.generic.MethodGen methodGen, CFG cfg, Dataflow<ResourceValueFrame,ResourceValueAnalysis<Resource>> dataflow, Resource resource)
           
abstract  boolean prescreen(ClassContext classContext, org.apache.bcel.classfile.Method method)
           
 void report()
          This method is called after all classes to be visited.
 void setAnalysisContext(AnalysisContext analysisContext)
          Set the AnalysisContext that will be used.
 void visitClassContext(ClassContext classContext)
          Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG

DEBUG_METHOD_NAME

private static final java.lang.String DEBUG_METHOD_NAME

bugReporter

protected BugReporter bugReporter

analysisContext

private AnalysisContext analysisContext
Constructor Detail

ResourceTrackingDetector

public ResourceTrackingDetector(BugReporter bugReporter)
Method Detail

prescreen

public abstract boolean prescreen(ClassContext classContext,
                                  org.apache.bcel.classfile.Method method)

getResourceTracker

public abstract ResourceTrackerType getResourceTracker(ClassContext classContext,
                                                       org.apache.bcel.classfile.Method method)
                                                                                  throws DataflowAnalysisException,
                                                                                         CFGBuilderException
Throws:
DataflowAnalysisException
CFGBuilderException

inspectResult

public abstract void inspectResult(org.apache.bcel.classfile.JavaClass javaClass,
                                   org.apache.bcel.generic.MethodGen methodGen,
                                   CFG cfg,
                                   Dataflow<ResourceValueFrame,ResourceValueAnalysis<Resource>> dataflow,
                                   Resource resource)

setAnalysisContext

public void setAnalysisContext(AnalysisContext analysisContext)
Description copied from interface: Detector
Set the AnalysisContext that will be used. This is called before visitClassContext() is called on any class to be analyzed.

Specified by:
setAnalysisContext in interface Detector
Parameters:
analysisContext - the AnalysisContext

getAnalysisContext

protected AnalysisContext getAnalysisContext()
Get the AnalysisContext.

Returns:
the AnalysisContext

visitClassContext

public void visitClassContext(ClassContext classContext)
Description copied from interface: Detector
Visit the ClassContext for a class which should be analyzed for instances of bug patterns.

Specified by:
visitClassContext in interface Detector
Parameters:
classContext - the ClassContext

buildResourceCollection

private ResourceCollection<Resource> buildResourceCollection(ClassContext classContext,
                                                             org.apache.bcel.classfile.Method method,
                                                             ResourceTrackerType resourceTracker)
                                                      throws CFGBuilderException,
                                                             DataflowAnalysisException
Throws:
CFGBuilderException
DataflowAnalysisException

analyzeMethod

public void analyzeMethod(ClassContext classContext,
                          org.apache.bcel.classfile.Method method,
                          ResourceTrackerType resourceTracker,
                          ResourceCollection<Resource> resourceCollection)
                   throws CFGBuilderException,
                          DataflowAnalysisException
Throws:
CFGBuilderException
DataflowAnalysisException

report

public void report()
Description copied from interface: Detector
This method is called after all classes to be visited. It should be used by any detectors which accumulate information over all visited classes to generate results.

Specified by:
report in interface Detector