KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > dfa > variableaccess > VariableAccess


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 JavaDoc variableName;
17
18     public VariableAccess(int accessType, String JavaDoc 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 JavaDoc getVariableName() {
48         return variableName;
49     }
50
51     public String JavaDoc toString() {
52         if (isDefinition()) return "Definition(" + variableName + ")";
53         if (isReference()) return "Reference(" + variableName + ")";
54         if (isUndefinition()) return "Undefinition(" + variableName + ")";
55         throw new RuntimeException JavaDoc("Access type was never set");
56     }
57 }
58
Popular Tags