|
1 |
| package com.agical.rmock.core.describe.impl; |
|
2 |
| |
|
3 |
| import java.io.IOException; |
|
4 |
| import java.io.Writer; |
|
5 |
| |
|
6 |
| import com.agical.rmock.core.describe.ExpressionDescriber; |
|
7 |
| import com.agical.rmock.core.match.Constraint; |
|
8 |
| import com.agical.rmock.core.match.Expression; |
|
9 |
| import com.agical.rmock.core.match.Reference; |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| public class ExpressionDescriberImpl implements ExpressionDescriber { |
|
18 |
| private boolean inArray; |
|
19 |
| private boolean firstElement; |
|
20 |
| private final Writer output; |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
25
| public ExpressionDescriberImpl(Writer output) {
|
|
26 |
25
| this.output = output;
|
|
27 |
| } |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
21
| public void describe(Constraint constraint) throws IOException {
|
|
34 |
21
| output.write(constraint.getName());
|
|
35 |
21
| output.write('(');
|
|
36 |
21
| Reference reference = constraint.getReference();
|
|
37 |
21
| if (reference != null) {
|
|
38 |
20
| reference.describeWith(this);
|
|
39 |
| } |
|
40 |
21
| output.write(')');
|
|
41 |
| } |
|
42 |
| |
|
43 |
1
| public void beginGroup() throws IOException {
|
|
44 |
1
| output.write('(');
|
|
45 |
| } |
|
46 |
| |
|
47 |
1
| public void describeInverted(Expression expression) throws IOException {
|
|
48 |
1
| output.write('!');
|
|
49 |
1
| expression.describeWith(this);
|
|
50 |
| |
|
51 |
| } |
|
52 |
| |
|
53 |
1
| public void operator(String operator) throws IOException {
|
|
54 |
1
| output.write(" ");
|
|
55 |
1
| output.write(operator);
|
|
56 |
1
| output.write(" ");
|
|
57 |
| } |
|
58 |
| |
|
59 |
1
| public void endGroup() throws IOException {
|
|
60 |
1
| output.write(')');
|
|
61 |
| } |
|
62 |
| |
|
63 |
22
| public void describeReference(String referenceDescription) throws IOException {
|
|
64 |
22
| if (inArray && !firstElement) {
|
|
65 |
1
| output.write(", ");
|
|
66 |
| } |
|
67 |
22
| firstElement = false;
|
|
68 |
22
| output.write(referenceDescription);
|
|
69 |
| } |
|
70 |
| |
|
71 |
1
| public void beginArray(Class type, int length) throws IOException {
|
|
72 |
1
| output.write(type.getName());
|
|
73 |
1
| output.write("["+length+"]");
|
|
74 |
1
| output.write('{');
|
|
75 |
1
| inArray=true;
|
|
76 |
1
| firstElement = true;
|
|
77 |
| } |
|
78 |
| |
|
79 |
1
| public void endArray() throws IOException {
|
|
80 |
1
| output.write('}');
|
|
81 |
1
| inArray = false;
|
|
82 |
1
| firstElement = false;
|
|
83 |
| } |
|
84 |
| } |