KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > bcp > FieldVariable


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.bcp;
21
22 import edu.umd.cs.findbugs.annotations.Nullable;
23 import edu.umd.cs.findbugs.ba.vna.ValueNumber;
24
25 public class FieldVariable implements Variable {
26     private final ValueNumber ref;
27     private final String JavaDoc className;
28     private final String JavaDoc fieldName;
29     private final String JavaDoc fieldSig;
30
31     /**
32      * Constructor for static fields.
33      *
34      * @param className the class name
35      * @param fieldName the field name
36      * @param fieldSig the field signature
37      */

38     public FieldVariable(String JavaDoc className, String JavaDoc fieldName, String JavaDoc fieldSig) {
39         this(null, className, fieldName, fieldSig);
40     }
41
42     /**
43      * Constructor for instance fields.
44      *
45      * @param ref ValueNumber of the object reference
46      * @param className the class name
47      * @param fieldName the field name
48      * @param fieldSig the field signature
49      */

50     public FieldVariable(@Nullable ValueNumber ref, String JavaDoc className, String JavaDoc fieldName, String JavaDoc fieldSig) {
51         this.ref = ref;
52         this.className = className;
53         this.fieldName = fieldName;
54         this.fieldSig = fieldSig;
55     }
56
57     /**
58      * Return whether or not this is a static field.
59      */

60     public boolean isStatic() {
61         return ref == null;
62     }
63
64     /**
65      * Get the class name.
66      */

67     public String JavaDoc getClassName() {
68         return className;
69     }
70
71     /**
72      * Get the field name.
73      */

74     public String JavaDoc getFieldName() {
75         return fieldName;
76     }
77
78     /**
79      * Get the field signature.
80      */

81     public String JavaDoc getFieldSig() {
82         return fieldSig;
83     }
84
85     public boolean sameAs(Variable other) {
86         if (!(other instanceof FieldVariable))
87             return false;
88         FieldVariable otherField = (FieldVariable) other;
89         if (isStatic() != otherField.isStatic())
90             return false;
91         return (ref == null || ref.equals(otherField.ref))
92                 && className.equals(otherField.className)
93                 && fieldName.equals(otherField.fieldName)
94                 && fieldSig.equals(otherField.fieldSig);
95     }
96
97     @Override JavaDoc
98          public String JavaDoc toString() {
99         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
100         buf.append(className);
101         buf.append('.');
102         buf.append(fieldName);
103         return buf.toString();
104     }
105 }
106
107 // vim:ts=4
108
Popular Tags