001: /*
002: * Bytecode Analysis Framework
003: * Copyright (C) 2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba.bcp;
021:
022: import edu.umd.cs.findbugs.annotations.Nullable;
023: import edu.umd.cs.findbugs.ba.vna.ValueNumber;
024:
025: public class FieldVariable implements Variable {
026: private final ValueNumber ref;
027: private final String className;
028: private final String fieldName;
029: private final String fieldSig;
030:
031: /**
032: * Constructor for static fields.
033: *
034: * @param className the class name
035: * @param fieldName the field name
036: * @param fieldSig the field signature
037: */
038: public FieldVariable(String className, String fieldName,
039: String fieldSig) {
040: this (null, className, fieldName, fieldSig);
041: }
042:
043: /**
044: * Constructor for instance fields.
045: *
046: * @param ref ValueNumber of the object reference
047: * @param className the class name
048: * @param fieldName the field name
049: * @param fieldSig the field signature
050: */
051: public FieldVariable(@Nullable
052: ValueNumber ref, String className, String fieldName, String fieldSig) {
053: this .ref = ref;
054: this .className = className;
055: this .fieldName = fieldName;
056: this .fieldSig = fieldSig;
057: }
058:
059: /**
060: * Return whether or not this is a static field.
061: */
062: public boolean isStatic() {
063: return ref == null;
064: }
065:
066: /**
067: * Get the class name.
068: */
069: public String getClassName() {
070: return className;
071: }
072:
073: /**
074: * Get the field name.
075: */
076: public String getFieldName() {
077: return fieldName;
078: }
079:
080: /**
081: * Get the field signature.
082: */
083: public String getFieldSig() {
084: return fieldSig;
085: }
086:
087: public boolean sameAs(Variable other) {
088: if (!(other instanceof FieldVariable))
089: return false;
090: FieldVariable otherField = (FieldVariable) other;
091: if (isStatic() != otherField.isStatic())
092: return false;
093: return (ref == null || ref.equals(otherField.ref))
094: && className.equals(otherField.className)
095: && fieldName.equals(otherField.fieldName)
096: && fieldSig.equals(otherField.fieldSig);
097: }
098:
099: @Override
100: public String toString() {
101: StringBuffer buf = new StringBuffer();
102: buf.append(className);
103: buf.append('.');
104: buf.append(fieldName);
105: return buf.toString();
106: }
107: }
108:
109: // vim:ts=4
|