View Javadoc

1   /*
2    * Created on 14.07.2004
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      // TODO completely encapsulate this somehow?
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()) return "Definition(" + variableName + ")";
54          if (isReference()) return "Reference(" + variableName + ")";
55          if (isUndefinition()) return "Undefinition(" + variableName + ")";
56          throw new RuntimeException("Access type was never set");
57      }
58  }