1 | package de.uka.ipd.sdq.pcmsolver.transformations.pcm2regex; |
2 | |
3 | import org.eclipse.emf.ecore.EObject; |
4 | |
5 | import de.uka.ipd.sdq.spa.expression.Alternative; |
6 | import de.uka.ipd.sdq.spa.expression.Loop; |
7 | import de.uka.ipd.sdq.spa.expression.Sequence; |
8 | import de.uka.ipd.sdq.spa.expression.Symbol; |
9 | import de.uka.ipd.sdq.spa.expression.util.ExpressionSwitch; |
10 | |
11 | public class ExpressionPrinter extends ExpressionSwitch{ |
12 | |
13 | private static String newline = System.getProperty("line.separator"); |
14 | |
15 | private StringBuilder outputStr = new StringBuilder(); |
16 | |
17 | public ExpressionPrinter(){ |
18 | } |
19 | |
20 | public String getOutput(){ |
21 | return outputStr.toString(); |
22 | } |
23 | |
24 | @Override |
25 | public Object caseAlternative(Alternative object) { |
26 | //System.out.print("("); |
27 | outputStr.append("("); |
28 | doSwitch(object.getLeftOption().getRegexp()); |
29 | outputStr.append("|"); |
30 | doSwitch(object.getRightOption().getRegexp()); |
31 | outputStr.append(")"); |
32 | return object; |
33 | |
34 | } |
35 | |
36 | @Override |
37 | public Object caseLoop(Loop object) { |
38 | outputStr.append("("); |
39 | doSwitch(object.getRegExp()); |
40 | outputStr.append(")*"); |
41 | return object; |
42 | } |
43 | |
44 | @Override |
45 | public Object caseSequence(Sequence object) { |
46 | doSwitch(object.getLeftRegExp()); |
47 | outputStr.append(""); |
48 | doSwitch(object.getRightRegExp()); |
49 | return object; |
50 | } |
51 | |
52 | @Override |
53 | public Object doSwitch(EObject theEObject) { |
54 | if (theEObject == null){ |
55 | outputStr.append("!null!"); |
56 | return null; |
57 | } else { |
58 | return super.doSwitch(theEObject); |
59 | } |
60 | } |
61 | |
62 | @Override |
63 | public Object caseSymbol(Symbol object) { |
64 | // outputStr.append("0"); |
65 | |
66 | if (object.getName() == null || object.getName().equals("")){ |
67 | //System.out.print("0"); |
68 | outputStr.append("0"); |
69 | } else { |
70 | //System.out.print(object.getName()); |
71 | outputStr.append(object.getName()); |
72 | } |
73 | return object; |
74 | } |
75 | |
76 | |
77 | |
78 | } |