1:
37:
38:
39: package ;
40:
41: import ;
42:
43:
54: public abstract class ScannerState
55: {
56:
57: static final int TRANSITION_METHOD_INVOCATION = 0;
58:
59: static final int TRANSITION_STATIC_METHOD_INVOCATION = 1;
60:
61: static final int TRANSITION_STATIC_FIELD_ACCESS = 2;
62:
63: static final int TRANSITION_CLASS_RESOLUTION = 3;
64:
65: static final int TRANSITION_OBJECT_INSTANTIATION = 4;
66:
67: static final int TRANSITION_PRIMITIVE_INSTANTIATION = 5;
68:
69: static final int TRANSITION_OBJECT_ARRAY_INSTANTIATION = 6;
70:
71: static final int TRANSITION_PRIMITIVE_ARRAY_INSTANTIATION = 7;
72:
73: static final int TRANSITION_ARRAY_SET = 8;
74:
75: static final int TRANSITION_ARRAY_GET = 9;
76:
77: static final int TRANSITION_LIST_SET = 10;
78:
79: static final int TRANSITION_LIST_GET = 11;
80:
81: static final int TRANSITION_NULL_OBJECT = 12;
82:
83: static final int TRANSITION_STRING_REFERENCE = 13;
84:
85: static final int TRANSITION_OBJECT_REFERENCE = 14;
86:
87: static final int TRANSITION_FIRST = 0;
88:
89: static final int TRANSITION_LAST = 14;
90:
91: static final String DEFAULT_STATE_NAME = "default";
92:
93: String defaultSuccessor = DEFAULT_STATE_NAME;
94:
95: static String[] transitionNames = { "METHOD_INVOCATION", "STATIC_METHOD_INVOCATION",
96: "STATIC_FIELD_ACCESS", "CLASS_RESOLUTION",
97: "OBJECT_INSTANTIATION",
98: "PRIMITIVE_INSTANTIATION", "OBJECT_ARRAY_INSTANTIATION",
99: "PRIMITIVE_ARRAY_INSTANTIATION",
100: "ARRAY_SET", "ARRAY_GET", "LIST_SET", "LIST_GET",
101: "NULL_OBJECT", "STRING_REFERENCE", "OBJECT_REFERENCE" };
102:
103:
107: HashMap transitions = new HashMap();
108:
109: int calls;
110:
111: Context context;
112:
113: String name;
114:
115: final void init(String newName)
116: {
117: assert (name == null);
118:
119: name = newName;
120: }
121:
122: final String getName()
123: {
124: return name;
125: }
126:
127: final void enter(Context ctx)
128: {
129: calls++;
130: context = ctx;
131:
132: enterImpl(ctx);
133: }
134:
135: protected void enterImpl(Context ctx)
136: {
137: }
138:
139: final Context context()
140: {
141: return context;
142: }
143:
144: final int getCalls()
145: {
146: return calls;
147: }
148:
149:
158: final void putSuccessor(int transition, String stateName)
159: {
160: assert (transition >= TRANSITION_FIRST && transition <= TRANSITION_LAST) :
161: "Transition identifier '" + transition + "' is unknown.";
162:
163: transitions.put(new Integer(transition), stateName);
164: }
165:
166:
175: final String getSuccessor(int transition)
176: {
177: String state = (String) transitions.get(new Integer(transition));
178:
179: return (state == null) ? defaultSuccessor : state;
180: }
181:
182:
187: final void setDefaultSuccessor(String newDefaultSuccessor)
188: {
189: defaultSuccessor = newDefaultSuccessor;
190: }
191:
192: abstract void methodInvocation(String methodName);
193:
194: abstract void staticMethodInvocation(String className, String methodName);
195:
196: abstract void staticFieldAccess(String className, String fieldName);
197:
198: abstract void classResolution(String className);
199:
200: abstract void objectInstantiation(String className, ObjectId objectId);
201:
202: abstract void primitiveInstantiation(String primitiveName,
203: String valueAsString);
204:
205: abstract void objectArrayInstantiation(String arrayClassName, String lengthAsString, ObjectId objectId);
206:
207: abstract void primitiveArrayInstantiation(String arrayClassName, String lengthAsString, ObjectId objectId);
208:
209: abstract void arraySet(String indexAsString);
210:
211: abstract void arrayGet(String indexAsString);
212:
213: abstract void listGet();
214:
215: abstract void listSet();
216:
217: abstract void nullObject();
218:
219: abstract void stringReference(String string);
220:
221: abstract void objectReference(ObjectId id);
222:
223:
230: abstract void end();
231:
232: void enter()
233: {
234: }
235:
236: }