|
16 | 16 |
|
17 | 17 | package org.springframework.expression.spel;
|
18 | 18 |
|
| 19 | +import org.springframework.asm.MethodVisitor; |
19 | 20 | import org.springframework.expression.EvaluationException;
|
20 | 21 | import org.springframework.expression.TypedValue;
|
21 | 22 | import org.springframework.lang.Nullable;
|
|
25 | 26 | * Expression Language (SpEL) expression.
|
26 | 27 | *
|
27 | 28 | * @author Andy Clement
|
| 29 | + * @author Sam Brannen |
28 | 30 | * @since 3.0
|
29 | 31 | */
|
30 | 32 | public interface SpelNode {
|
@@ -109,4 +111,40 @@ public interface SpelNode {
|
109 | 111 | */
|
110 | 112 | int getEndPosition();
|
111 | 113 |
|
| 114 | + /** |
| 115 | + * Determine if this node can be compiled to bytecode. |
| 116 | + * <p>The reasoning in each node may be different but will typically involve |
| 117 | + * checking whether the exit type descriptor of the node is known and any |
| 118 | + * relevant child nodes are compilable. |
| 119 | + * <p>The default implementation returns {@code false}. |
| 120 | + * <p>If you override this method, you must also override |
| 121 | + * {@link #generateCode(MethodVisitor, CodeFlow)}. |
| 122 | + * @return {@code true} if this node can be compiled to bytecode |
| 123 | + * @since 6.2 |
| 124 | + * @see #generateCode(MethodVisitor, CodeFlow) |
| 125 | + */ |
| 126 | + default boolean isCompilable() { |
| 127 | + return false; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Generate the bytecode for this node into the supplied {@link MethodVisitor}. |
| 132 | + * <p>Context information about the current expression being compiled is |
| 133 | + * available in the supplied {@link CodeFlow} object — for example, |
| 134 | + * information about the type of the object currently on the stack. |
| 135 | + * <p>This method will not be invoked unless {@link #isCompilable()} returns |
| 136 | + * {@code true}. |
| 137 | + * <p>The default implementation throws an {@link IllegalStateException} |
| 138 | + * since {@link #isCompilable()} returns {@code false} by default. |
| 139 | + * <p>If you override this method, you must also override {@link #isCompilable()}. |
| 140 | + * @param methodVisitor the ASM {@code MethodVisitor} into which code should |
| 141 | + * be generated |
| 142 | + * @param codeFlow a context object with information about what is on the stack |
| 143 | + * @since 6.2 |
| 144 | + * @see #isCompilable() |
| 145 | + */ |
| 146 | + default void generateCode(MethodVisitor methodVisitor, CodeFlow codeFlow) { |
| 147 | + throw new IllegalStateException(getClass().getName() + " does not support bytecode generation"); |
| 148 | + } |
| 149 | + |
112 | 150 | }
|
0 commit comments