KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class ReturnPath {
23     /**
24      * Top value.
25      */

26     public static final int TOP = 0;
27     /**
28      * Method "returns" by exiting the process.
29      */

30     public static final int EXIT = 1;
31     /**
32      * Method returns by throwing an unhandled exception.
33      */

34     public static final int UE = 2;
35     /**
36      * Method returns either by exiting or throwing an unhandled exception.
37      */

38     public static final int EXIT_UE = 3;
39     /**
40      * Method may return normally.
41      */

42     public static final int RETURNS = 4;
43
44     private int kind;
45
46     public ReturnPath(int kind) {
47         this.kind = kind;
48     }
49
50     public int getKind() {
51         return kind;
52     }
53
54     public void setKind(int kind) {
55         this.kind = kind;
56     }
57
58     public void copyFrom(ReturnPath other) {
59         this.kind = other.kind;
60     }
61
62     public boolean sameAs(ReturnPath other) {
63         return this.kind == other.kind;
64     }
65
66     private static final int[][] mergeMatrix = {
67         // TOP EXIT UE EXIT_UE RETURNS
68
{TOP, }, // TOP
69
{EXIT, EXIT, }, // EXIT
70
{UE, EXIT_UE, UE, }, // UE
71
{EXIT_UE, EXIT_UE, EXIT_UE, EXIT_UE, }, // EXIT_UE
72
{RETURNS, RETURNS, RETURNS, RETURNS, RETURNS}, // RETURNS
73
};
74
75     public void mergeWith(ReturnPath other) {
76         int max = Math.max(this.kind, other.kind);
77         int min = Math.min(this.kind, other.kind);
78         this.kind = mergeMatrix[max][min];
79     }
80
81     @Override JavaDoc
82          public String JavaDoc toString() {
83         switch (kind) {
84         case TOP:
85             return "[TOP]";
86         case EXIT:
87             return "[EXIT]";
88         case UE:
89             return "[UE]";
90         case EXIT_UE:
91             return "[EXIT_UE]";
92         case RETURNS:
93             return "[RETURNS]";
94         default:
95             throw new IllegalStateException JavaDoc();
96         }
97     }
98 }
99
100 // vim:ts=4
101
Popular Tags