KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > ResourceTracker


1 /*
2  * Bytecode Analysis Framework
3  * Copyright (C) 2003-2005 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.ba;
21
22 import org.apache.bcel.generic.ConstantPoolGen;
23 import org.apache.bcel.generic.InstructionHandle;
24
25 /**
26  * A ResourceTracker is used with ResourceValueAnalysis to determine
27  * where in a method a certain kind of resource is created, and
28  * to model the effect of instructions on the state of that resource.
29  *
30  * @author David Hovemeyer
31  * @see ResourceValueAnalysis
32  */

33 public interface ResourceTracker <Resource> {
34     /**
35      * Determine if the given instruction is the site where a resource
36      * is created.
37      *
38      * @param basicBlock basic block containing the instruction
39      * @param handle the instruction
40      * @param cpg the ConstantPoolGen for the method
41      * @return an opaque Resource object if it is a creation site, or
42      * null if it is not a creation site
43      */

44     public Resource isResourceCreation(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg)
45             throws DataflowAnalysisException;
46
47     /**
48      * Determine if the given instruction is the site where a resource
49      * is closed.
50      *
51      * @param basicBlock basic block containing the instruction
52      * @param handle the instruction
53      * @param cpg the ConstantPoolGen for the method
54      * @param resource the resource, as returned by isResourceCreation()
55      * @param frame the ResourceValueFrame representing the stack prior to executing
56      * the instruction
57      * @return true if the resource is closed here, false otherwise
58      */

59     public boolean isResourceClose(BasicBlock basicBlock, InstructionHandle handle, ConstantPoolGen cpg, Resource resource,
60                                    ResourceValueFrame frame) throws DataflowAnalysisException;
61
62     /**
63      * Create a ResourceValueFrameModelingVisitor to model the effect
64      * of instructions on the state of the resource.
65      *
66      * @param resource the resource we are tracking
67      * @param cpg the ConstantPoolGen of the method
68      * @return a ResourceValueFrameModelingVisitor
69      */

70     public ResourceValueFrameModelingVisitor createVisitor(Resource resource, ConstantPoolGen cpg);
71
72     /**
73      * Determine whether the analysis should ignore exception edges
74      * on which only implicit exceptions are propagated.
75      * This allows different resource types to be tracked
76      * with varying precision. For example, we might want
77      * to ignore implicit exceptions for stream objects,
78      * but treat them as significant for database resources.
79      *
80      * @param resource the resource being tracked
81      * @return true if implicit exceptions are significant,
82      * false if they should be ignore
83      */

84     public boolean ignoreImplicitExceptions(Resource resource);
85
86     /**
87      * Determine whether the analysis should ignore given exception edge.
88      * This allows the analysis to customize which kinds of exceptions are
89      * significant.
90      *
91      * @param edge the exception edge
92      * @param resource the resource
93      * @param cpg the ConstantPoolGen
94      * @return true if exception edge should be ignored, false if it should be considered
95      */

96     public boolean ignoreExceptionEdge(Edge edge, Resource resource, ConstantPoolGen cpg);
97
98     /**
99      * Return if the given parameter slot contains the
100      * resource instance upon entry to the method.
101      * This is for resources passed as parameters.
102      *
103      * @param resource the resource
104      * @param slot the local variable slot
105      * @return true if the slot contains the resource instance,
106      * false otherwise
107      */

108     public boolean isParamInstance(Resource resource, int slot);
109 }
110
111 // vim:ts=4
112
Popular Tags