KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > reflect > eval > SymbolicEvaluationPath


1 package spoon.reflect.eval;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 /**
7  * This class defines a symbolic evaluation path as a list of abstract
8  * evaluation steps (see {@link spoon.reflect.eval.SymbolicEvaluationStep}).
9  */

10 public class SymbolicEvaluationPath {
11
12     /**
13      * Creates a symbolic evaluation path.
14      */

15     public SymbolicEvaluationPath() {
16     }
17     
18     List JavaDoc<SymbolicEvaluationStep> steps = new ArrayList JavaDoc<SymbolicEvaluationStep>();
19
20     /**
21      * Creates and adds a step to this path.
22      *
23      * @param kind
24      * the step kind
25      * @param evaluator
26      * the current evaluator (its state is used to initialize the new
27      * step).
28      */

29     public void addStep(StepKind kind, SymbolicEvaluator evaluator) {
30         steps
31                 .add(new SymbolicEvaluationStep(kind, new SymbolicStackFrame(evaluator.getStack()
32                         .getFrameStack().peek()), new SymbolicHeap(evaluator
33                         .getHeap())));
34     }
35
36     /**
37      * Gets the ith step.
38      */

39     public SymbolicEvaluationStep getStep(int i) {
40         return steps.get(i);
41     }
42
43     /**
44      * Returns the evaluation steps list.
45      */

46     public List JavaDoc<SymbolicEvaluationStep> getSteps() {
47         return steps;
48     }
49     
50     /**
51      * Gets the number of steps in this path.
52      */

53     public int getStepCount() {
54         return steps.size();
55     }
56
57     /**
58      * Dumps this path on the screen.
59      */

60     public void dump() {
61         for (int i = 0; i < steps.size(); i++) {
62             System.out.println((i + 1) + "\t" + steps.get(i).getKind() + " "
63                     + steps.get(i).getFrame());
64             steps.get(i).getHeap().dump();
65         }
66     }
67
68     /**
69      * A string representation.
70      */

71     @Override JavaDoc
72     public String JavaDoc toString() {
73         String JavaDoc res="";
74         for (int i = 0; i < steps.size(); i++) {
75             res+=steps.get(i).getKind()+"("+steps.get(i).getFrame().getExecutable().getSimpleName()+");";
76         }
77         return res;
78     }
79     
80 }
81
Popular Tags