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