Polish SpEL internals and tests
This commit is contained in:
parent
e1bbdf0913
commit
3577e3b758
|
|
@ -239,6 +239,7 @@ public class Indexer extends SpelNodeImpl {
|
|||
cf.loadTarget(mv);
|
||||
}
|
||||
|
||||
SpelNodeImpl index = this.children[0];
|
||||
if (this.indexedType == IndexedType.ARRAY) {
|
||||
int insn = switch (this.exitTypeDescriptor) {
|
||||
case "D" -> {
|
||||
|
|
@ -282,7 +283,6 @@ public class Indexer extends SpelNodeImpl {
|
|||
}
|
||||
};
|
||||
|
||||
SpelNodeImpl index = this.children[0];
|
||||
cf.enterCompilationScope();
|
||||
index.generateCode(mv, cf);
|
||||
cf.exitCompilationScope();
|
||||
|
|
@ -292,7 +292,7 @@ public class Indexer extends SpelNodeImpl {
|
|||
else if (this.indexedType == IndexedType.LIST) {
|
||||
mv.visitTypeInsn(CHECKCAST, "java/util/List");
|
||||
cf.enterCompilationScope();
|
||||
this.children[0].generateCode(mv, cf);
|
||||
index.generateCode(mv, cf);
|
||||
cf.exitCompilationScope();
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;", true);
|
||||
}
|
||||
|
|
@ -301,13 +301,13 @@ public class Indexer extends SpelNodeImpl {
|
|||
mv.visitTypeInsn(CHECKCAST, "java/util/Map");
|
||||
// Special case when the key is an unquoted string literal that will be parsed as
|
||||
// a property/field reference
|
||||
if ((this.children[0] instanceof PropertyOrFieldReference reference)) {
|
||||
if ((index instanceof PropertyOrFieldReference reference)) {
|
||||
String mapKeyName = reference.getName();
|
||||
mv.visitLdcInsn(mapKeyName);
|
||||
}
|
||||
else {
|
||||
cf.enterCompilationScope();
|
||||
this.children[0].generateCode(mv, cf);
|
||||
index.generateCode(mv, cf);
|
||||
cf.exitCompilationScope();
|
||||
}
|
||||
mv.visitMethodInsn(
|
||||
|
|
|
|||
|
|
@ -613,6 +613,9 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
|
|||
|
||||
private final TypeDescriptor typeDescriptor;
|
||||
|
||||
/**
|
||||
* The original method, or {@code null} if the member is not a method.
|
||||
*/
|
||||
@Nullable
|
||||
private final Method originalMethod;
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
|
|||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.testdata.PersonInOtherPackage;
|
||||
import org.springframework.expression.spel.testresources.Person;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
|
@ -909,7 +910,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
assertThatExceptionOfType(SpelEvaluationException.class)
|
||||
.isThrownBy(expression::getValue)
|
||||
.withMessageEndingWith("Type cannot be found 'Missing'");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -994,7 +995,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
ctx.setVariable("foo", String.class);
|
||||
expression = parse("3 instanceof #foo");
|
||||
assertThat(expression.getValue(ctx)).isEqualTo(false);
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
// use of primitive as type for instanceof check - compilable
|
||||
// but always false
|
||||
|
|
@ -1279,13 +1280,13 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// Can't compile this as we aren't going down the getfalse() branch in our evaluation
|
||||
expression = parser.parseExpression("gettrue() or getfalse()");
|
||||
resultI = expression.getValue(tc, boolean.class);
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
expression = parser.parseExpression("getA() or getB()");
|
||||
tc.a = true;
|
||||
tc.b = true;
|
||||
resultI = expression.getValue(tc, boolean.class);
|
||||
assertCantCompile(expression); // Haven't yet been into second branch
|
||||
assertCannotCompile(expression); // Haven't yet been into second branch
|
||||
tc.a = false;
|
||||
tc.b = true;
|
||||
resultI = expression.getValue(tc, boolean.class);
|
||||
|
|
@ -1335,13 +1336,13 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// Can't compile this as we aren't going down the gettrue() branch in our evaluation
|
||||
expression = parser.parseExpression("getfalse() and gettrue()");
|
||||
resultI = expression.getValue(tc, boolean.class);
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
expression = parser.parseExpression("getA() and getB()");
|
||||
tc.a = false;
|
||||
tc.b = false;
|
||||
resultI = expression.getValue(tc, boolean.class);
|
||||
assertCantCompile(expression); // Haven't yet been into second branch
|
||||
assertCannotCompile(expression); // Haven't yet been into second branch
|
||||
tc.a = true;
|
||||
tc.b = false;
|
||||
resultI = expression.getValue(tc, boolean.class);
|
||||
|
|
@ -1409,7 +1410,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
boolean root = true;
|
||||
expression = parser.parseExpression("(#root and true)?T(Integer).valueOf(1):T(Long).valueOf(3L)");
|
||||
assertThat(expression.getValue(root)).isEqualTo(1);
|
||||
assertCantCompile(expression); // Have not gone down false branch
|
||||
assertCannotCompile(expression); // Have not gone down false branch
|
||||
root = false;
|
||||
assertThat(expression.getValue(root)).isEqualTo(3L);
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -1636,7 +1637,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
String s = "abc";
|
||||
expression = parser.parseExpression("#root?:'b'");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
resultI = expression.getValue(s, String.class);
|
||||
assertThat(resultI).isEqualTo("abc");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -1792,7 +1793,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// type nor method are public
|
||||
expression = parser.parseExpression("#doCompare([0],#arg)");
|
||||
assertThat(expression.getValue(context, Integer.class).toString()).isEqualTo("-1");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
// type not public but method is
|
||||
context = new StandardEvaluationContext(new Object[] {"1"});
|
||||
|
|
@ -1801,7 +1802,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
context.setVariable("arg", "2");
|
||||
expression = parser.parseExpression("#doCompare([0],#arg)");
|
||||
assertThat(expression.getValue(context, Integer.class).toString()).isEqualTo("-1");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2059,7 +2060,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// Differing types of number, not yet supported
|
||||
expression = parse("1 < 3.0d");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
expression = parse("T(Integer).valueOf(3) < 4");
|
||||
assertThat((Boolean) expression.getValue()).isTrue();
|
||||
|
|
@ -2118,7 +2119,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// Differing types of number, not yet supported
|
||||
expression = parse("1 <= 3.0d");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
expression = parse("T(Integer).valueOf(3) <= 4");
|
||||
assertThat((Boolean) expression.getValue()).isTrue();
|
||||
|
|
@ -2168,7 +2169,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// Differing types of number, not yet supported
|
||||
expression = parse("1 > 3.0d");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
expression = parse("T(Integer).valueOf(3) > 4");
|
||||
assertThat((Boolean) expression.getValue()).isFalse();
|
||||
|
|
@ -2230,7 +2231,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// Differing types of number, not yet supported
|
||||
expression = parse("1 >= 3.0d");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
expression = parse("T(Integer).valueOf(3) >= 4");
|
||||
assertThat((Boolean) expression.getValue()).isFalse();
|
||||
|
|
@ -2310,7 +2311,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// number types are not the same
|
||||
expression = parse("1 == 3.0d");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
Double d = 3.0d;
|
||||
expression = parse("#root==3.0d");
|
||||
|
|
@ -2455,7 +2456,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// not compatible number types
|
||||
expression = parse("1 != 3.0d");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
expression = parse("T(Integer).valueOf(3) != 4");
|
||||
assertThat((Boolean) expression.getValue()).isTrue();
|
||||
|
|
@ -3127,7 +3128,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// Three strings, optimal bytecode would only use one StringBuilder
|
||||
expression = parse("'hello' + 3 + ' spring'");
|
||||
assertThat(expression.getValue(new Greeter())).isEqualTo("hello3 spring");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
expression = parse("object + 'a'");
|
||||
assertThat(expression.getValue(new Greeter())).isEqualTo("objecta");
|
||||
|
|
@ -4262,7 +4263,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
String testclass9 = "org.springframework.expression.spel.SpelCompilationCoverageTests$TestClass9";
|
||||
expression = parser.parseExpression("new " + testclass9 + "(42)");
|
||||
assertThat(expression.getValue().getClass().getName()).isEqualTo(testclass9);
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -4272,7 +4273,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// Should call the non varargs version of concat
|
||||
// (which causes the '::' prefix in test output)
|
||||
expression = parser.parseExpression("concat('test')");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("::test");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4283,7 +4284,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// This will call the varargs concat with an empty array
|
||||
expression = parser.parseExpression("concat()");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEmpty();
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4295,7 +4296,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// Should call the non varargs version of concat
|
||||
// (which causes the '::' prefix in test output)
|
||||
expression = parser.parseExpression("concat2('test')");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("::test");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4306,7 +4307,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// This will call the varargs concat with an empty array
|
||||
expression = parser.parseExpression("concat2()");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEmpty();
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4322,7 +4323,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs string
|
||||
expression = parser.parseExpression("eleven()");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEmpty();
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4333,7 +4334,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs string
|
||||
expression = parser.parseExpression("eleven('aaa')");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("aaa");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4344,7 +4345,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs string
|
||||
expression = parser.parseExpression("eleven(stringArray)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("aaabbbccc");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4355,7 +4356,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs string
|
||||
expression = parser.parseExpression("eleven('aaa','bbb','ccc')");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("aaabbbccc");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4365,7 +4366,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
|
||||
expression = parser.parseExpression("sixteen('aaa','bbb','ccc')");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("aaabbbccc");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4387,7 +4388,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs int
|
||||
expression = parser.parseExpression("twelve(1,2,3)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.i).isEqualTo(6);
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4397,7 +4398,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
|
||||
expression = parser.parseExpression("twelve(1)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.i).isEqualTo(1);
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4408,7 +4409,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// one string then varargs string
|
||||
expression = parser.parseExpression("thirteen('aaa','bbb','ccc')");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("aaa::bbbccc");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4419,7 +4420,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// nothing passed to varargs parameter
|
||||
expression = parser.parseExpression("thirteen('aaa')");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("aaa::");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4430,7 +4431,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// nested arrays
|
||||
expression = parser.parseExpression("fourteen('aaa',stringArray,stringArray)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("aaa::{aaabbbccc}{aaabbbccc}");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4441,7 +4442,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// nested primitive array
|
||||
expression = parser.parseExpression("fifteen('aaa',intArray,intArray)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("aaa::{112233}{112233}");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4452,7 +4453,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs boolean
|
||||
expression = parser.parseExpression("arrayz(true,true,false)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("truetruefalse");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4462,7 +4463,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
|
||||
expression = parser.parseExpression("arrayz(true)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("true");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4473,7 +4474,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs short
|
||||
expression = parser.parseExpression("arrays(s1,s2,s3)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("123");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4483,7 +4484,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
|
||||
expression = parser.parseExpression("arrays(s1)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("1");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4494,7 +4495,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs double
|
||||
expression = parser.parseExpression("arrayd(1.0d,2.0d,3.0d)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("1.02.03.0");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4504,7 +4505,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
|
||||
expression = parser.parseExpression("arrayd(1.0d)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("1.0");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4515,7 +4516,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs long
|
||||
expression = parser.parseExpression("arrayj(l1,l2,l3)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("123");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4525,7 +4526,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
|
||||
expression = parser.parseExpression("arrayj(l1)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("1");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4536,7 +4537,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs char
|
||||
expression = parser.parseExpression("arrayc(c1,c2,c3)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("abc");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4546,7 +4547,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
|
||||
expression = parser.parseExpression("arrayc(c1)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("a");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4557,7 +4558,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs byte
|
||||
expression = parser.parseExpression("arrayb(b1,b2,b3)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("656667");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4567,7 +4568,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
|
||||
expression = parser.parseExpression("arrayb(b1)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("65");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4578,7 +4579,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// varargs float
|
||||
expression = parser.parseExpression("arrayf(f1,f2,f3)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("1.02.03.0");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4588,7 +4589,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
tc.reset();
|
||||
|
||||
expression = parser.parseExpression("arrayf(f1)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("1.0");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4603,7 +4604,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// non-static method, no args, void return
|
||||
expression = parser.parseExpression("new %s()?.one()".formatted(TestClass5.class.getName()));
|
||||
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
TestClass5._i = 0;
|
||||
assertThat(expression.getValue()).isNull();
|
||||
|
|
@ -4620,7 +4621,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// static method, no args, void return
|
||||
expression = parser.parseExpression("T(%s)?.two()".formatted(TestClass5.class.getName()));
|
||||
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
TestClass5._i = 0;
|
||||
assertThat(expression.getValue()).isNull();
|
||||
|
|
@ -4637,7 +4638,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// non-static method, no args, Void return
|
||||
expression = parser.parseExpression("new %s()?.oneVoidWrapper()".formatted(TestClass5.class.getName()));
|
||||
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
TestClass5._i = 0;
|
||||
assertThat(expression.getValue()).isNull();
|
||||
|
|
@ -4654,7 +4655,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// static method, no args, Void return
|
||||
expression = parser.parseExpression("T(%s)?.twoVoidWrapper()".formatted(TestClass5.class.getName()));
|
||||
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
|
||||
TestClass5._i = 0;
|
||||
assertThat(expression.getValue()).isNull();
|
||||
|
|
@ -4672,7 +4673,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// non-static method, no args, void return
|
||||
expression = parser.parseExpression("one()");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4682,7 +4683,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// static method, no args, void return
|
||||
expression = parser.parseExpression("two()");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4692,7 +4693,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// non-static method, reference type return
|
||||
expression = parser.parseExpression("three()");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4701,7 +4702,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// non-static method, primitive type return
|
||||
expression = parser.parseExpression("four()");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4710,7 +4711,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// static method, reference type return
|
||||
expression = parser.parseExpression("five()");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4719,7 +4720,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// static method, primitive type return
|
||||
expression = parser.parseExpression("six()");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4728,7 +4729,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// non-static method, one parameter of reference type
|
||||
expression = parser.parseExpression("seven(\"foo\")");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4738,7 +4739,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// static method, one parameter of reference type
|
||||
expression = parser.parseExpression("eight(\"bar\")");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4748,7 +4749,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// non-static method, one parameter of primitive type
|
||||
expression = parser.parseExpression("nine(231)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4758,7 +4759,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// static method, one parameter of primitive type
|
||||
expression = parser.parseExpression("ten(111)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertCanCompile(expression);
|
||||
tc.reset();
|
||||
|
|
@ -4770,10 +4771,10 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// Converting from an int to a string
|
||||
expression = parser.parseExpression("seven(123)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("123");
|
||||
assertCantCompile(expression); // Uncompilable as argument conversion is occurring
|
||||
assertCannotCompile(expression); // Uncompilable as argument conversion is occurring
|
||||
|
||||
Expression expression = parser.parseExpression("'abcd'.substring(index1,index2)");
|
||||
String resultI = expression.getValue(new TestClass1(), String.class);
|
||||
|
|
@ -4784,7 +4785,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// Converting from an int to a Number
|
||||
expression = parser.parseExpression("takeNumber(123)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("123");
|
||||
tc.reset();
|
||||
|
|
@ -4794,7 +4795,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// Passing a subtype
|
||||
expression = parser.parseExpression("takeNumber(T(Integer).valueOf(42))");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("42");
|
||||
tc.reset();
|
||||
|
|
@ -4804,11 +4805,11 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// Passing a subtype
|
||||
expression = parser.parseExpression("takeString(T(Integer).valueOf(42))");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("42");
|
||||
tc.reset();
|
||||
assertCantCompile(expression); // method takes a string and we are passing an Integer
|
||||
assertCannotCompile(expression); // method takes a string and we are passing an Integer
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -4835,7 +4836,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
tc.field = "foo";
|
||||
expression = parser.parseExpression("seven(field)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("foo");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4846,7 +4847,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
// method with changing parameter types (change reference type)
|
||||
tc.obj = "foo";
|
||||
expression = parser.parseExpression("seven(obj)");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
expression.getValue(tc);
|
||||
assertThat(tc.s).isEqualTo("foo");
|
||||
assertCanCompile(expression);
|
||||
|
|
@ -4982,35 +4983,35 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
|
||||
// non-static field
|
||||
expression = parser.parseExpression("orange");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value1");
|
||||
assertCanCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value1");
|
||||
|
||||
// static field
|
||||
expression = parser.parseExpression("apple");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value2");
|
||||
assertCanCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value2");
|
||||
|
||||
// non static getter
|
||||
expression = parser.parseExpression("banana");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value3");
|
||||
assertCanCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value3");
|
||||
|
||||
// static getter
|
||||
expression = parser.parseExpression("plum");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value4");
|
||||
assertCanCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value4");
|
||||
|
||||
// record-style accessor
|
||||
expression = parser.parseExpression("strawberry");
|
||||
assertCantCompile(expression);
|
||||
assertCannotCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value5");
|
||||
assertCanCompile(expression);
|
||||
assertThat(expression.getValue(tc)).isEqualTo("value5");
|
||||
|
|
@ -5631,7 +5632,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
.isTrue();
|
||||
}
|
||||
|
||||
private void assertCantCompile(Expression expression) {
|
||||
private void assertCannotCompile(Expression expression) {
|
||||
assertThat(SpelCompiler.compile(expression))
|
||||
.as(() -> "Expression <%s> should not be compilable"
|
||||
.formatted(((SpelExpression) expression).toStringAST()))
|
||||
|
|
@ -5860,25 +5861,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
|||
}
|
||||
|
||||
|
||||
public class Person {
|
||||
|
||||
private int age;
|
||||
|
||||
public Person(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Person3 {
|
||||
public static class Person3 {
|
||||
|
||||
private int age;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,15 @@ public class Person {
|
|||
|
||||
private String privateName;
|
||||
|
||||
private int age;
|
||||
|
||||
Company company;
|
||||
|
||||
|
||||
public Person(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Person(String name) {
|
||||
this.privateName = name;
|
||||
}
|
||||
|
|
@ -31,6 +38,7 @@ public class Person {
|
|||
this.company = company;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return privateName;
|
||||
}
|
||||
|
|
@ -39,6 +47,14 @@ public class Person {
|
|||
this.privateName = n;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue