SPR-6525: avoid need to use #root for method parameter references
This commit is contained in:
@@ -52,7 +52,14 @@ public class MethodReference extends SpelNodeImpl {
|
||||
TypedValue currentContext = state.getActiveContextObject();
|
||||
Object[] arguments = new Object[getChildCount()];
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
arguments[i] = children[i].getValueInternal(state).getValue();
|
||||
// Make the root object the active context again for evaluating the parameter
|
||||
// expressions
|
||||
try {
|
||||
state.pushActiveContextObject(state.getRootContextObject());
|
||||
arguments[i] = children[i].getValueInternal(state).getValue();
|
||||
} finally {
|
||||
state.popActiveContextObject();
|
||||
}
|
||||
}
|
||||
if (currentContext.getValue() == null) {
|
||||
if (nullSafe) {
|
||||
|
||||
@@ -367,7 +367,27 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
public void testTernaryOperatorWithNullValue() {
|
||||
parser.parseExpression("null ? 0 : 1").getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodCallWithRootReferenceThroughParameter() {
|
||||
evaluate("placeOfBirth.doubleIt(inventions.length)", 18, Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ctorCallWithRootReferenceThroughParameter() {
|
||||
evaluate("new org.springframework.expression.spel.testresources.PlaceOfBirth(inventions[0].toString()).city", "Telephone repeater", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fnCallWithRootReferenceThroughParameter() {
|
||||
evaluate("#reverseInt(inventions.length, inventions.length, inventions.length)", "int[3]{9,9,9}", int[].class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodCallWithRootReferenceThroughParameterThatIsAFunctionCall() {
|
||||
evaluate("placeOfBirth.doubleIt(#reverseInt(inventions.length,2,3)[2])", 18, Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexer03() {
|
||||
evaluate("'christian'[8]", "n", String.class);
|
||||
|
||||
Reference in New Issue
Block a user