01: package spoon.reflect.eval.observer;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05:
06: import spoon.reflect.eval.SymbolicEvaluationPath;
07: import spoon.reflect.eval.SymbolicEvaluationStep;
08: import spoon.reflect.eval.SymbolicEvaluator;
09: import spoon.reflect.eval.SymbolicEvaluatorObserver;
10: import spoon.support.reflect.eval.VisitorSymbolicEvaluator;
11:
12: /**
13: * This symbolic evaluator observer will create all the evaluation paths for a
14: * given evaluator. Note that it is costful to memorize all the evaluation paths
15: * and this observer should not be used on large programs (or programs which are
16: * known to generate a great deal of evaluation paths.
17: * <p>
18: * Once the evaluation is done, call {@link #getPaths()} to get the paths.
19: */
20: public class SymbolicEvaluationPathsMaker implements
21: SymbolicEvaluatorObserver {
22:
23: Collection<SymbolicEvaluationPath> paths = new ArrayList<SymbolicEvaluationPath>();
24: SymbolicEvaluationPath currentPath;
25:
26: /**
27: * The default constructor.
28: */
29: public SymbolicEvaluationPathsMaker() {
30: }
31:
32: public void onStartPath(SymbolicEvaluator evaluator) {
33: currentPath = new SymbolicEvaluationPath();
34: paths.add(currentPath);
35: }
36:
37: public void onExitStep(VisitorSymbolicEvaluator evaluator,
38: SymbolicEvaluationStep step) {
39: currentPath.addStep(step);
40: }
41:
42: public void onEndPath(SymbolicEvaluator evaluator) {
43: }
44:
45: public void onEnterStep(SymbolicEvaluator evaluator,
46: SymbolicEvaluationStep step) {
47: currentPath.addStep(step);
48: }
49:
50: /**
51: * Get the paths that where constructed during the evaluation of the
52: * observed evaluator.
53: *
54: * @return a collection of symbolic evaluation paths (not a copy: it can be
55: * cleared to reset the observer's state)
56: */
57: public Collection<SymbolicEvaluationPath> getPaths() {
58: return paths;
59: }
60:
61: }
|