1 |
| |
2 |
| |
3 |
| |
4 |
| package net.sourceforge.pmd.dfa.variableaccess; |
5 |
| |
6 |
| |
7 |
| |
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 |
194
| public VariableAccess(int accessType, String varName) {
|
19 |
194
| this.accessType = accessType;
|
20 |
194
| if (varName.indexOf(".") == -1) {
|
21 |
191
| this.variableName = varName;
|
22 |
| } else { |
23 |
3
| this.variableName = varName.substring(0, varName.indexOf("."));
|
24 |
| } |
25 |
| } |
26 |
| |
27 |
| |
28 |
0
| public int getAccessType() {
|
29 |
0
| return accessType;
|
30 |
| } |
31 |
| |
32 |
0
| public boolean accessTypeMatches(int otherType) {
|
33 |
0
| return accessType == otherType;
|
34 |
| } |
35 |
| |
36 |
5
| public boolean isDefinition() {
|
37 |
5
| return this.accessType == DEFINITION;
|
38 |
| } |
39 |
| |
40 |
3
| public boolean isReference() {
|
41 |
3
| return this.accessType == REFERENCING;
|
42 |
| } |
43 |
| |
44 |
2
| public boolean isUndefinition() {
|
45 |
2
| return this.accessType == UNDEFINITION;
|
46 |
| } |
47 |
| |
48 |
4
| public String getVariableName() {
|
49 |
4
| return variableName;
|
50 |
| } |
51 |
| |
52 |
5
| public String toString() {
|
53 |
2
| if (isDefinition()) return "Definition(" + variableName + ")";
|
54 |
1
| if (isReference()) return "Reference(" + variableName + ")";
|
55 |
2
| if (isUndefinition()) return "Undefinition(" + variableName + ")";
|
56 |
0
| throw new RuntimeException("Access type was never set");
|
57 |
| } |
58 |
| } |