View Javadoc

    1   /*
    2    * Created on 14.07.2004
    3    */
    4   package net.sourceforge.pmd.lang.dfa;
    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          int dotPos = varName.indexOf('.');
    21          variableName = dotPos < 0 ?
    22          	varName :
    23          	varName.substring(0, dotPos);
    24      }
    25
    26      // TODO completely encapsulate this somehow?
    27      public int getAccessType() {
    28          return accessType;
    29      }
    30
    31      public boolean accessTypeMatches(int otherType) {
    32          return accessType == otherType;
    33      }
    34
    35      public boolean isDefinition() {
    36          return this.accessType == DEFINITION;
    37      }
    38
    39      public boolean isReference() {
    40          return this.accessType == REFERENCING;
    41      }
    42
    43      public boolean isUndefinition() {
    44          return this.accessType == UNDEFINITION;
    45      }
    46
    47      public String getVariableName() {
    48          return variableName;
    49      }
    50
    51      public String toString() {
    52          if (isDefinition()) {
    53              return "Definition(" + variableName + ")";
    54          }
    55          if (isReference()) {
    56              return "Reference(" + variableName + ")";
    57          }
    58          if (isUndefinition()) {
    59              return "Undefinition(" + variableName + ")";
    60          }
    61          throw new RuntimeException("Access type was never set");
    62      }
    63  }