1
2
3
4 package net.sourceforge.pmd.dfa.variableaccess;
5
6 /***
7 * @author raik
8 */
9 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 if (varName.indexOf(".") == -1) {
21 this.variableName = varName;
22 } else {
23 this.variableName = varName.substring(0, varName.indexOf("."));
24 }
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 public boolean isReference() {
40 return this.accessType == REFERENCING;
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()) return "Definition(" + variableName + ")";
52 if (isReference()) return "Reference(" + variableName + ")";
53 if (isUndefinition()) return "Undefinition(" + variableName + ")";
54 throw new RuntimeException("Access type was never set");
55 }
56 }