1
2
3
4 package net.sourceforge.pmd.lang.dfa;
5
6
7
8
9
10 public class VariableAccess {
11
12 public static final int DEFINITION = 0;
13 public static final int REFERENCING = 1;
14 public static final int UNDEFINITION = 2;
15
16 private int accessType;
17 private String variableName;
18
19 public VariableAccess(int accessType, String varName) {
20 this.accessType = accessType;
21 int dotPos = varName.indexOf('.');
22 variableName = dotPos < 0 ?
23 varName :
24 varName.substring(0, dotPos);
25 }
26
27
28 public int getAccessType() {
29 return accessType;
30 }
31
32 public boolean accessTypeMatches(int otherType) {
33 return accessType == otherType;
34 }
35
36 public boolean isDefinition() {
37 return this.accessType == DEFINITION;
38 }
39
40 public boolean isReference() {
41 return this.accessType == REFERENCING;
42 }
43
44 public boolean isUndefinition() {
45 return this.accessType == UNDEFINITION;
46 }
47
48 public String getVariableName() {
49 return variableName;
50 }
51
52 public String toString() {
53 if (isDefinition()) {
54 return "Definition(" + variableName + ")";
55 }
56 if (isReference()) {
57 return "Reference(" + variableName + ")";
58 }
59 if (isUndefinition()) {
60 return "Undefinition(" + variableName + ")";
61 }
62 throw new RuntimeException("Access type was never set");
63 }
64 }