|
16 | 16 |
|
17 | 17 | package org.springframework.expression.spel.ast;
|
18 | 18 |
|
19 |
| -import java.util.StringJoiner; |
20 | 19 | import java.util.function.Supplier;
|
21 | 20 |
|
22 | 21 | import org.springframework.asm.MethodVisitor;
|
|
25 | 24 | import org.springframework.expression.spel.CodeFlow;
|
26 | 25 | import org.springframework.expression.spel.ExpressionState;
|
27 | 26 | import org.springframework.expression.spel.SpelEvaluationException;
|
| 27 | +import org.springframework.expression.spel.SpelNode; |
28 | 28 |
|
29 | 29 | /**
|
30 | 30 | * Represents a DOT separated expression sequence, such as
|
31 |
| - * {@code 'property1.property2.methodOne()'}. |
| 31 | + * {@code property1.property2.methodOne()}. |
| 32 | + * |
| 33 | + * <p>May also contain array/collection/map indexers, such as |
| 34 | + * {@code property1[0].property2['key']}. |
32 | 35 | *
|
33 | 36 | * @author Andy Clement
|
34 | 37 | * @author Sam Brannen
|
@@ -111,11 +114,19 @@ public boolean isWritable(ExpressionState state) throws EvaluationException {
|
111 | 114 |
|
112 | 115 | @Override
|
113 | 116 | public String toStringAST() {
|
114 |
| - StringJoiner sj = new StringJoiner("."); |
| 117 | + StringBuilder sb = new StringBuilder(); |
115 | 118 | for (int i = 0; i < getChildCount(); i++) {
|
116 |
| - sj.add(getChild(i).toStringAST()); |
| 119 | + sb.append(getChild(i).toStringAST()); |
| 120 | + if (i < getChildCount() - 1) { |
| 121 | + SpelNode nextChild = getChild(i + 1); |
| 122 | + // Don't append a '.' if the next child is an Indexer. |
| 123 | + // For example, we want 'myVar[0]' instead of 'myVar.[0]'. |
| 124 | + if (!(nextChild instanceof Indexer)) { |
| 125 | + sb.append('.'); |
| 126 | + } |
| 127 | + } |
117 | 128 | }
|
118 |
| - return sj.toString(); |
| 129 | + return sb.toString(); |
119 | 130 | }
|
120 | 131 |
|
121 | 132 | @Override
|
|
0 commit comments