KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > obl > Obligation


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.obl;
21
22 import org.apache.bcel.generic.ObjectType;
23
24 import edu.umd.cs.findbugs.ba.ObjectTypeFactory;
25
26 /**
27  * An obligation that must be cleaned up by error handling code.
28  * Examples include open streams and database connections.
29  *
30  * <p>See Weimer and Necula,
31  * <a HREF="http://doi.acm.org/10.1145/1028976.1029011"
32  * >Finding and preventing run-time error handling mistakes</a>,
33  * OOPSLA 2004.</p>
34  *
35  * @author David Hovemeyer
36  */

37 public class Obligation {
38     private final String JavaDoc className;
39     private final ObjectType type;
40     private final int id;
41
42     public Obligation(String JavaDoc className, int id) {
43         this.className = className;
44         this.type = ObjectTypeFactory.getInstance(className);
45         this.id = id;
46     }
47
48     public String JavaDoc getClassName() {
49         return className;
50     }
51     
52     public ObjectType getType() {
53         return type;
54     }
55
56     public int getId() {
57         return id;
58     }
59     
60     @Override JavaDoc
61     public String JavaDoc toString() {
62         // Make dataflow output more compact by dropping package
63
int lastDot = className.lastIndexOf('.');
64         return lastDot >= 0 ? className.substring(lastDot+1) : className;
65     }
66 }
67
68 // vim:ts=4
69
Popular Tags