KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Bytecode Analysis Framework
3  * Copyright (C) 2003,2004 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.classfile.Method;
23 import org.apache.bcel.generic.InstructionHandle;
24
25 public class ReturnPathAnalysis extends ForwardDataflowAnalysis<ReturnPath> implements EdgeTypes {
26     public ReturnPathAnalysis(DepthFirstSearch dfs) {
27         super(dfs);
28     }
29
30     public ReturnPath createFact() {
31         return new ReturnPath(ReturnPath.TOP);
32     }
33
34     public void copy(ReturnPath source, ReturnPath dest) {
35         dest.copyFrom(source);
36     }
37
38     public void initEntryFact(ReturnPath fact) {
39         fact.setKind(ReturnPath.RETURNS);
40     }
41
42     public void initResultFact(ReturnPath result) {
43         result.setKind(ReturnPath.TOP);
44     }
45
46     public void makeFactTop(ReturnPath fact) {
47         fact.setKind(ReturnPath.TOP);
48     }
49
50     public boolean isTop(ReturnPath fact) {
51         return fact.getKind() == ReturnPath.TOP;
52     }
53     public boolean same(ReturnPath fact1, ReturnPath fact2) {
54         return fact1.sameAs(fact2);
55     }
56
57     @Override JavaDoc
58          public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, ReturnPath fact)
59             throws DataflowAnalysisException {
60         // Nothing to do
61
}
62
63     @Override JavaDoc
64          public boolean isFactValid(ReturnPath fact) {
65         return true;
66     }
67
68     public void meetInto(ReturnPath fact, Edge edge, ReturnPath result) throws DataflowAnalysisException {
69         switch (edge.getType()) {
70         case UNHANDLED_EXCEPTION_EDGE:
71             fact = new ReturnPath(ReturnPath.UE);
72             break;
73         case EXIT_EDGE:
74             fact = new ReturnPath(ReturnPath.EXIT);
75             break;
76         }
77
78         result.mergeWith(fact);
79     }
80
81     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
82         if (argv.length != 1) {
83             System.err.println("Usage: " + ReturnPathAnalysis.class.getName() + " <classfile>");
84             System.exit(1);
85         }
86
87         DataflowTestDriver<ReturnPath, ReturnPathAnalysis> driver = new DataflowTestDriver<ReturnPath, ReturnPathAnalysis>() {
88             @Override JavaDoc
89                          public Dataflow<ReturnPath, ReturnPathAnalysis>
90                     createDataflow(ClassContext classContext, Method method)
91                     throws CFGBuilderException, DataflowAnalysisException {
92                 return classContext.getReturnPathDataflow(method);
93             }
94         };
95
96         driver.execute(argv[0]);
97     }
98 }
99
100 // vim:ts=4
101
Popular Tags