01: /*
02: * Created on 14.07.2004
03: */
04: package net.sourceforge.pmd.dfa.variableaccess;
05:
06: /**
07: * @author raik
08: */
09: public class VariableAccess {
10:
11: public static final int DEFINITION = 0;
12: public static final int REFERENCING = 1;
13: public static final int UNDEFINITION = 2;
14:
15: private int accessType;
16: private String variableName;
17:
18: public VariableAccess(int accessType, String varName) {
19: this .accessType = accessType;
20: int dotPos = varName.indexOf('.');
21: variableName = dotPos < 0 ? varName : varName.substring(0,
22: dotPos);
23: }
24:
25: // TODO completely encapsulate this somehow?
26: public int getAccessType() {
27: return accessType;
28: }
29:
30: public boolean accessTypeMatches(int otherType) {
31: return accessType == otherType;
32: }
33:
34: public boolean isDefinition() {
35: return this .accessType == DEFINITION;
36: }
37:
38: public boolean isReference() {
39: return this .accessType == REFERENCING;
40: }
41:
42: public boolean isUndefinition() {
43: return this .accessType == UNDEFINITION;
44: }
45:
46: public String getVariableName() {
47: return variableName;
48: }
49:
50: public String toString() {
51: if (isDefinition())
52: return "Definition(" + variableName + ")";
53: if (isReference())
54: return "Reference(" + variableName + ")";
55: if (isUndefinition())
56: return "Undefinition(" + variableName + ")";
57: throw new RuntimeException("Access type was never set");
58: }
59: }
|