KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > type > ThrownException


1 /*
2  * Bytecode Analysis Framework
3  * Copyright (C) 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.type;
21
22 import org.apache.bcel.generic.ObjectType;
23
24 /**
25  * An exception thrown from an instruction.
26  * These can be implicit (i.e., runtime exceptions and errors),
27  * or explicit (athrow, or declared exception from called method).
28  * This information is used in TypeAnalysis in order to determine:
29  * <ul>
30  * <li> what exceptions can be thrown along exception edges, and
31  * <li> which exceptions are explicit (declared or explicitly thrown)
32  * and which are implicit (result of failed runtime checks)
33  * </ul>
34  *
35  * @author David Hovemeyer
36  * @see ExceptionSet
37  * @see TypeAnalysis
38  */

39 public class ThrownException {
40     private ObjectType type;
41     private boolean explicit;
42
43     /**
44      * Constructor.
45      *
46      * @param type type of exception
47      * @param explicit true if explicit, false if implicit
48      */

49     public ThrownException(ObjectType type, boolean explicit) {
50         this.type = type;
51         this.explicit = explicit;
52     }
53
54     /**
55      * Return an identical copy of this object.
56      */

57     public ThrownException duplicate() {
58         return new ThrownException(type, explicit);
59     }
60
61     /**
62      * Get the exception type.
63      */

64     public ObjectType getType() {
65         return type;
66     }
67
68     /**
69      * Return whether or not the exception is explicit.
70      */

71     public boolean isExplicit() {
72         return explicit;
73     }
74
75     /**
76      * Set whether or not the exception is explicit.
77      */

78     public void setExplicit(boolean explicit) {
79         this.explicit = explicit;
80     }
81
82     @Override JavaDoc
83          public int hashCode() {
84         return type.hashCode();
85     }
86
87     @Override JavaDoc
88          public boolean equals(Object JavaDoc o) {
89         if (o == null) return false;
90         if (o.getClass() != this.getClass()) return false;
91
92         ThrownException other = (ThrownException) o;
93         return this.type.equals(other.type) && this.explicit == other.explicit;
94     }
95 }
96
97 // vim:ts=4
98
Popular Tags