Browse Source

SpelNodeImpl manages start/end position in separate integer values

Fixes gh-22157
pull/22324/head
Juergen Hoeller 6 years ago
parent
commit
7a77e83e10
  1. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Assign.java
  2. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/BeanReference.java
  3. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/BooleanLiteral.java
  4. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/CompoundExpression.java
  5. 10
      spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java
  6. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Elvis.java
  7. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/FloatLiteral.java
  8. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java
  9. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Identifier.java
  10. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java
  11. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java
  12. 16
      spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineMap.java
  13. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/IntLiteral.java
  14. 26
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Literal.java
  15. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/LongLiteral.java
  16. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java
  17. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/NullLiteral.java
  18. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java
  19. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpDec.java
  20. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpDivide.java
  21. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java
  22. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpGE.java
  23. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpGT.java
  24. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpInc.java
  25. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpLE.java
  26. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpLT.java
  27. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpMinus.java
  28. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpModulus.java
  29. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpMultiply.java
  30. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpNE.java
  31. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpOr.java
  32. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java
  33. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java
  34. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorBetween.java
  35. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorInstanceof.java
  36. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java
  37. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorNot.java
  38. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorPower.java
  39. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Projection.java
  40. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java
  41. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/QualifiedIdentifier.java
  42. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/RealLiteral.java
  43. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Selection.java
  44. 15
      spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java
  45. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/StringLiteral.java
  46. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Ternary.java
  47. 10
      spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java
  48. 9
      spring-expression/src/main/java/org/springframework/expression/spel/ast/ValueRef.java
  49. 6
      spring-expression/src/main/java/org/springframework/expression/spel/ast/VariableReference.java
  50. 152
      spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java
  51. 82
      spring-expression/src/test/java/org/springframework/expression/spel/ast/OpPlusTests.java

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/Assign.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,8 +31,8 @@ import org.springframework.expression.spel.ExpressionState; @@ -31,8 +31,8 @@ import org.springframework.expression.spel.ExpressionState;
*/
public class Assign extends SpelNodeImpl {
public Assign(int pos, SpelNodeImpl... operands) {
super(pos, operands);
public Assign(int startPos, int endPos, SpelNodeImpl... operands) {
super(startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/BeanReference.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,8 +37,8 @@ public class BeanReference extends SpelNodeImpl { @@ -37,8 +37,8 @@ public class BeanReference extends SpelNodeImpl {
private final String beanName;
public BeanReference(int pos, String beanName) {
super(pos);
public BeanReference(int startPos, int endPos, String beanName) {
super(startPos, endPos);
this.beanName = beanName;
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/BooleanLiteral.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,8 +31,8 @@ public class BooleanLiteral extends Literal { @@ -31,8 +31,8 @@ public class BooleanLiteral extends Literal {
private final BooleanTypedValue value;
public BooleanLiteral(String payload, int pos, boolean value) {
super(payload, pos);
public BooleanLiteral(String payload, int startPos, int endPos, boolean value) {
super(payload, startPos, endPos);
this.value = BooleanTypedValue.forValue(value);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/CompoundExpression.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,8 +33,8 @@ import org.springframework.lang.Nullable; @@ -33,8 +33,8 @@ import org.springframework.lang.Nullable;
*/
public class CompoundExpression extends SpelNodeImpl {
public CompoundExpression(int pos, SpelNodeImpl... expressionComponents) {
super(pos, expressionComponents);
public CompoundExpression(int startPos, int endPos, SpelNodeImpl... expressionComponents) {
super(startPos, endPos, expressionComponents);
if (expressionComponents.length < 2) {
throw new IllegalStateException("Do not build compound expressions with less than two entries: " +
expressionComponents.length);

10
spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -72,8 +72,8 @@ public class ConstructorReference extends SpelNodeImpl { @@ -72,8 +72,8 @@ public class ConstructorReference extends SpelNodeImpl {
* Create a constructor reference. The first argument is the type, the rest are the parameters to the constructor
* call
*/
public ConstructorReference(int pos, SpelNodeImpl... arguments) {
super(pos, arguments);
public ConstructorReference(int startPos, int endPos, SpelNodeImpl... arguments) {
super(startPos, endPos, arguments);
this.isArrayConstructor = false;
}
@ -81,8 +81,8 @@ public class ConstructorReference extends SpelNodeImpl { @@ -81,8 +81,8 @@ public class ConstructorReference extends SpelNodeImpl {
* Create a constructor reference. The first argument is the type, the rest are the parameters to the constructor
* call
*/
public ConstructorReference(int pos, SpelNodeImpl[] dimensions, SpelNodeImpl... arguments) {
super(pos, arguments);
public ConstructorReference(int startPos, int endPos, SpelNodeImpl[] dimensions, SpelNodeImpl... arguments) {
super(startPos, endPos, arguments);
this.isArrayConstructor = true;
this.dimensions = dimensions;
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/Elvis.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ import org.springframework.util.StringUtils; @@ -36,8 +36,8 @@ import org.springframework.util.StringUtils;
*/
public class Elvis extends SpelNodeImpl {
public Elvis(int pos, SpelNodeImpl... args) {
super(pos, args);
public Elvis(int startPos, int endPos, SpelNodeImpl... args) {
super(startPos, endPos, args);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/FloatLiteral.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,8 +32,8 @@ public class FloatLiteral extends Literal { @@ -32,8 +32,8 @@ public class FloatLiteral extends Literal {
private final TypedValue value;
public FloatLiteral(String payload, int pos, float value) {
super(payload, pos);
public FloatLiteral(String payload, int startPos, int endPos, float value) {
super(payload, startPos, endPos);
this.value = new TypedValue(value);
this.exitTypeDescriptor = "F";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -57,8 +57,8 @@ public class FunctionReference extends SpelNodeImpl { @@ -57,8 +57,8 @@ public class FunctionReference extends SpelNodeImpl {
private volatile Method method;
public FunctionReference(String functionName, int pos, SpelNodeImpl... arguments) {
super(pos, arguments);
public FunctionReference(String functionName, int startPos, int endPos, SpelNodeImpl... arguments) {
super(startPos, endPos, arguments);
this.name = functionName;
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/Identifier.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,8 +31,8 @@ public class Identifier extends SpelNodeImpl { @@ -31,8 +31,8 @@ public class Identifier extends SpelNodeImpl {
private final TypedValue id;
public Identifier(String payload, int pos) {
super(pos);
public Identifier(String payload, int startPos, int endPos) {
super(startPos, endPos);
this.id = new TypedValue(payload);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -90,8 +90,8 @@ public class Indexer extends SpelNodeImpl { @@ -90,8 +90,8 @@ public class Indexer extends SpelNodeImpl {
private IndexedType indexedType;
public Indexer(int pos, SpelNodeImpl expr) {
super(pos, expr);
public Indexer(int startPos, int endPos, SpelNodeImpl expr) {
super(startPos, endPos, expr);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -42,8 +42,8 @@ public class InlineList extends SpelNodeImpl { @@ -42,8 +42,8 @@ public class InlineList extends SpelNodeImpl {
private TypedValue constant; // TODO must be immutable list
public InlineList(int pos, SpelNodeImpl... args) {
super(pos, args);
public InlineList(int startPos, int endPos, SpelNodeImpl... args) {
super(startPos, endPos, args);
checkIfConstant();
}

16
spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineMap.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -40,14 +40,14 @@ public class InlineMap extends SpelNodeImpl { @@ -40,14 +40,14 @@ public class InlineMap extends SpelNodeImpl {
private TypedValue constant;
public InlineMap(int pos, SpelNodeImpl... args) {
super(pos, args);
public InlineMap(int startPos, int endPos, SpelNodeImpl... args) {
super(startPos, endPos, args);
checkIfConstant();
}
/**
* If all the components of the list are constants, or lists/maps that themselves
* If all the components of the map are constants, or lists/maps that themselves
* contain constants, then a constant list can be built to represent this node.
* This will speed up later getValue calls and reduce the amount of garbage created.
*/
@ -70,14 +70,14 @@ public class InlineMap extends SpelNodeImpl { @@ -70,14 +70,14 @@ public class InlineMap extends SpelNodeImpl {
break;
}
}
else if (!((c%2)==0 && (child instanceof PropertyOrFieldReference))) {
else if (!(c % 2 == 0 && child instanceof PropertyOrFieldReference)) {
isConstant = false;
break;
}
}
}
if (isConstant) {
Map<Object,Object> constantMap = new LinkedHashMap<>();
Map<Object, Object> constantMap = new LinkedHashMap<>();
int childCount = getChildCount();
for (int c = 0; c < childCount; c++) {
SpelNode keyChild = getChild(c++);
@ -159,9 +159,9 @@ public class InlineMap extends SpelNodeImpl { @@ -159,9 +159,9 @@ public class InlineMap extends SpelNodeImpl {
@SuppressWarnings("unchecked")
@Nullable
public Map<Object,Object> getConstantValue() {
public Map<Object, Object> getConstantValue() {
Assert.state(this.constant != null, "No constant");
return (Map<Object,Object>) this.constant.getValue();
return (Map<Object, Object>) this.constant.getValue();
}
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/IntLiteral.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,8 +32,8 @@ public class IntLiteral extends Literal { @@ -32,8 +32,8 @@ public class IntLiteral extends Literal {
private final TypedValue value;
public IntLiteral(String payload, int pos, int value) {
super(payload, pos);
public IntLiteral(String payload, int startPos, int endPos, int value) {
super(payload, startPos, endPos);
this.value = new TypedValue(value);
this.exitTypeDescriptor = "I";
}

26
spring-expression/src/main/java/org/springframework/expression/spel/ast/Literal.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ public abstract class Literal extends SpelNodeImpl { @@ -36,8 +36,8 @@ public abstract class Literal extends SpelNodeImpl {
private final String originalValue;
public Literal(@Nullable String originalValue, int pos) {
super(pos);
public Literal(@Nullable String originalValue, int startPos, int endPos) {
super(startPos, endPos);
this.originalValue = originalValue;
}
@ -74,39 +74,39 @@ public abstract class Literal extends SpelNodeImpl { @@ -74,39 +74,39 @@ public abstract class Literal extends SpelNodeImpl {
* @param radix the base of number
* @return a subtype of Literal that can represent it
*/
public static Literal getIntLiteral(String numberToken, int pos, int radix) {
public static Literal getIntLiteral(String numberToken, int startPos, int endPos, int radix) {
try {
int value = Integer.parseInt(numberToken, radix);
return new IntLiteral(numberToken, pos, value);
return new IntLiteral(numberToken, startPos, endPos, value);
}
catch (NumberFormatException ex) {
throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_AN_INTEGER, numberToken));
throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_AN_INTEGER, numberToken));
}
}
public static Literal getLongLiteral(String numberToken, int pos, int radix) {
public static Literal getLongLiteral(String numberToken, int startPos, int endPos, int radix) {
try {
long value = Long.parseLong(numberToken, radix);
return new LongLiteral(numberToken, pos, value);
return new LongLiteral(numberToken, startPos, endPos, value);
}
catch (NumberFormatException ex) {
throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_A_LONG, numberToken));
throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_A_LONG, numberToken));
}
}
public static Literal getRealLiteral(String numberToken, int pos, boolean isFloat) {
public static Literal getRealLiteral(String numberToken, int startPos, int endPos, boolean isFloat) {
try {
if (isFloat) {
float value = Float.parseFloat(numberToken);
return new FloatLiteral(numberToken, pos, value);
return new FloatLiteral(numberToken, startPos, endPos, value);
}
else {
double value = Double.parseDouble(numberToken);
return new RealLiteral(numberToken, pos, value);
return new RealLiteral(numberToken, startPos, endPos, value);
}
}
catch (NumberFormatException ex) {
throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_A_REAL, numberToken));
throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_A_REAL, numberToken));
}
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/LongLiteral.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,8 +31,8 @@ public class LongLiteral extends Literal { @@ -31,8 +31,8 @@ public class LongLiteral extends Literal {
private final TypedValue value;
public LongLiteral(String payload, int pos, long value) {
super(payload, pos);
public LongLiteral(String payload, int startPos, int endPos, long value) {
super(payload, startPos, endPos);
this.value = new TypedValue(value);
this.exitTypeDescriptor = "J";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -64,8 +64,8 @@ public class MethodReference extends SpelNodeImpl { @@ -64,8 +64,8 @@ public class MethodReference extends SpelNodeImpl {
private volatile CachedMethodExecutor cachedExecutor;
public MethodReference(boolean nullSafe, String methodName, int pos, SpelNodeImpl... arguments) {
super(pos, arguments);
public MethodReference(boolean nullSafe, String methodName, int startPos, int endPos, SpelNodeImpl... arguments) {
super(startPos, endPos, arguments);
this.name = methodName;
this.nullSafe = nullSafe;
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/NullLiteral.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,8 +28,8 @@ import org.springframework.expression.spel.CodeFlow; @@ -28,8 +28,8 @@ import org.springframework.expression.spel.CodeFlow;
*/
public class NullLiteral extends Literal {
public NullLiteral(int pos) {
super(null, pos);
public NullLiteral(int startPos, int endPos) {
super(null, startPos, endPos);
this.exitTypeDescriptor = "Ljava/lang/Object";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,8 +37,8 @@ import org.springframework.lang.Nullable; @@ -37,8 +37,8 @@ import org.springframework.lang.Nullable;
*/
public class OpAnd extends Operator {
public OpAnd(int pos, SpelNodeImpl... operands) {
super("and", pos, operands);
public OpAnd(int startPos, int endPos, SpelNodeImpl... operands) {
super("and", startPos, endPos, operands);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpDec.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,8 +41,8 @@ public class OpDec extends Operator { @@ -41,8 +41,8 @@ public class OpDec extends Operator {
private final boolean postfix; // false means prefix
public OpDec(int pos, boolean postfix, SpelNodeImpl... operands) {
super("--", pos, operands);
public OpDec(int startPos, int endPos, boolean postfix, SpelNodeImpl... operands) {
super("--", startPos, endPos, operands);
this.postfix = postfix;
Assert.notEmpty(operands, "Operands must not be empty");
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpDivide.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -39,8 +39,8 @@ import org.springframework.util.NumberUtils; @@ -39,8 +39,8 @@ import org.springframework.util.NumberUtils;
*/
public class OpDivide extends Operator {
public OpDivide(int pos, SpelNodeImpl... operands) {
super("/", pos, operands);
public OpDivide(int startPos, int endPos, SpelNodeImpl... operands) {
super("/", startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpEQ.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,8 +31,8 @@ import org.springframework.expression.spel.support.BooleanTypedValue; @@ -31,8 +31,8 @@ import org.springframework.expression.spel.support.BooleanTypedValue;
*/
public class OpEQ extends Operator {
public OpEQ(int pos, SpelNodeImpl... operands) {
super("==", pos, operands);
public OpEQ(int startPos, int endPos, SpelNodeImpl... operands) {
super("==", startPos, endPos, operands);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpGE.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ import org.springframework.util.NumberUtils; @@ -36,8 +36,8 @@ import org.springframework.util.NumberUtils;
*/
public class OpGE extends Operator {
public OpGE(int pos, SpelNodeImpl... operands) {
super(">=", pos, operands);
public OpGE(int startPos, int endPos, SpelNodeImpl... operands) {
super(">=", startPos, endPos, operands);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpGT.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ import org.springframework.util.NumberUtils; @@ -36,8 +36,8 @@ import org.springframework.util.NumberUtils;
*/
public class OpGT extends Operator {
public OpGT(int pos, SpelNodeImpl... operands) {
super(">", pos, operands);
public OpGT(int startPos, int endPos, SpelNodeImpl... operands) {
super(">", startPos, endPos, operands);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpInc.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,8 +41,8 @@ public class OpInc extends Operator { @@ -41,8 +41,8 @@ public class OpInc extends Operator {
private final boolean postfix; // false means prefix
public OpInc(int pos, boolean postfix, SpelNodeImpl... operands) {
super("++", pos, operands);
public OpInc(int startPos, int endPos, boolean postfix, SpelNodeImpl... operands) {
super("++", startPos, endPos, operands);
this.postfix = postfix;
Assert.notEmpty(operands, "Operands must not be empty");
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpLE.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ import org.springframework.util.NumberUtils; @@ -36,8 +36,8 @@ import org.springframework.util.NumberUtils;
*/
public class OpLE extends Operator {
public OpLE(int pos, SpelNodeImpl... operands) {
super("<=", pos, operands);
public OpLE(int startPos, int endPos, SpelNodeImpl... operands) {
super("<=", startPos, endPos, operands);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpLT.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ import org.springframework.util.NumberUtils; @@ -36,8 +36,8 @@ import org.springframework.util.NumberUtils;
*/
public class OpLT extends Operator {
public OpLT(int pos, SpelNodeImpl... operands) {
super("<", pos, operands);
public OpLT(int startPos, int endPos, SpelNodeImpl... operands) {
super("<", startPos, endPos, operands);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpMinus.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -47,8 +47,8 @@ import org.springframework.util.NumberUtils; @@ -47,8 +47,8 @@ import org.springframework.util.NumberUtils;
*/
public class OpMinus extends Operator {
public OpMinus(int pos, SpelNodeImpl... operands) {
super("-", pos, operands);
public OpMinus(int startPos, int endPos, SpelNodeImpl... operands) {
super("-", startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpModulus.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -38,8 +38,8 @@ import org.springframework.util.NumberUtils; @@ -38,8 +38,8 @@ import org.springframework.util.NumberUtils;
*/
public class OpModulus extends Operator {
public OpModulus(int pos, SpelNodeImpl... operands) {
super("%", pos, operands);
public OpModulus(int startPos, int endPos, SpelNodeImpl... operands) {
super("%", startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpMultiply.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -52,8 +52,8 @@ import org.springframework.util.NumberUtils; @@ -52,8 +52,8 @@ import org.springframework.util.NumberUtils;
*/
public class OpMultiply extends Operator {
public OpMultiply(int pos, SpelNodeImpl... operands) {
super("*", pos, operands);
public OpMultiply(int startPos, int endPos, SpelNodeImpl... operands) {
super("*", startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpNE.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,8 +32,8 @@ import org.springframework.expression.spel.support.BooleanTypedValue; @@ -32,8 +32,8 @@ import org.springframework.expression.spel.support.BooleanTypedValue;
*/
public class OpNE extends Operator {
public OpNE(int pos, SpelNodeImpl... operands) {
super("!=", pos, operands);
public OpNE(int startPos, int endPos, SpelNodeImpl... operands) {
super("!=", startPos, endPos, operands);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpOr.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ import org.springframework.lang.Nullable; @@ -36,8 +36,8 @@ import org.springframework.lang.Nullable;
*/
public class OpOr extends Operator {
public OpOr(int pos, SpelNodeImpl... operands) {
super("or", pos, operands);
public OpOr(int startPos, int endPos, SpelNodeImpl... operands) {
super("or", startPos, endPos, operands);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -50,8 +50,8 @@ import org.springframework.util.NumberUtils; @@ -50,8 +50,8 @@ import org.springframework.util.NumberUtils;
*/
public class OpPlus extends Operator {
public OpPlus(int pos, SpelNodeImpl... operands) {
super("+", pos, operands);
public OpPlus(int startPos, int endPos, SpelNodeImpl... operands) {
super("+", startPos, endPos, operands);
Assert.notEmpty(operands, "Operands must not be empty");
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -54,8 +54,8 @@ public abstract class Operator extends SpelNodeImpl { @@ -54,8 +54,8 @@ public abstract class Operator extends SpelNodeImpl {
protected String rightActualDescriptor;
public Operator(String payload, int pos, SpelNodeImpl... operands) {
super(pos, operands);
public Operator(String payload, int startPos, int endPos, SpelNodeImpl... operands) {
super(startPos, endPos, operands);
this.operatorName = payload;
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorBetween.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ import org.springframework.expression.spel.support.BooleanTypedValue; @@ -36,8 +36,8 @@ import org.springframework.expression.spel.support.BooleanTypedValue;
*/
public class OperatorBetween extends Operator {
public OperatorBetween(int pos, SpelNodeImpl... operands) {
super("between", pos, operands);
public OperatorBetween(int startPos, int endPos, SpelNodeImpl... operands) {
super("between", startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorInstanceof.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,8 +41,8 @@ public class OperatorInstanceof extends Operator { @@ -41,8 +41,8 @@ public class OperatorInstanceof extends Operator {
private Class<?> type;
public OperatorInstanceof(int pos, SpelNodeImpl... operands) {
super("instanceof", pos, operands);
public OperatorInstanceof(int startPos, int endPos, SpelNodeImpl... operands) {
super("instanceof", startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -45,8 +45,8 @@ public class OperatorMatches extends Operator { @@ -45,8 +45,8 @@ public class OperatorMatches extends Operator {
private final ConcurrentMap<String, Pattern> patternCache = new ConcurrentHashMap<>();
public OperatorMatches(int pos, SpelNodeImpl... operands) {
super("matches", pos, operands);
public OperatorMatches(int startPos, int endPos, SpelNodeImpl... operands) {
super("matches", startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorNot.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -35,8 +35,8 @@ import org.springframework.expression.spel.support.BooleanTypedValue; @@ -35,8 +35,8 @@ import org.springframework.expression.spel.support.BooleanTypedValue;
*/
public class OperatorNot extends SpelNodeImpl { // Not is a unary operator so does not extend BinaryOperator
public OperatorNot(int pos, SpelNodeImpl operand) {
super(pos, operand);
public OperatorNot(int startPos, int endPos, SpelNodeImpl operand) {
super(startPos, endPos, operand);
this.exitTypeDescriptor = "Z";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorPower.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,8 +34,8 @@ import org.springframework.util.NumberUtils; @@ -34,8 +34,8 @@ import org.springframework.util.NumberUtils;
*/
public class OperatorPower extends Operator {
public OperatorPower(int pos, SpelNodeImpl... operands) {
super("^", pos, operands);
public OperatorPower(int startPos, int endPos, SpelNodeImpl... operands) {
super("^", startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/Projection.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -46,8 +46,8 @@ public class Projection extends SpelNodeImpl { @@ -46,8 +46,8 @@ public class Projection extends SpelNodeImpl {
private final boolean nullSafe;
public Projection(boolean nullSafe, int pos, SpelNodeImpl expression) {
super(pos, expression);
public Projection(boolean nullSafe, int startPos, int endPos, SpelNodeImpl expression) {
super(startPos, endPos, expression);
this.nullSafe = nullSafe;
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -64,8 +64,8 @@ public class PropertyOrFieldReference extends SpelNodeImpl { @@ -64,8 +64,8 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
private volatile PropertyAccessor cachedWriteAccessor;
public PropertyOrFieldReference(boolean nullSafe, String propertyOrFieldName, int pos) {
super(pos);
public PropertyOrFieldReference(boolean nullSafe, String propertyOrFieldName, int startPos, int endPos) {
super(startPos, endPos);
this.nullSafe = nullSafe;
this.name = propertyOrFieldName;
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/QualifiedIdentifier.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ public class QualifiedIdentifier extends SpelNodeImpl { @@ -36,8 +36,8 @@ public class QualifiedIdentifier extends SpelNodeImpl {
private TypedValue value;
public QualifiedIdentifier(int pos, SpelNodeImpl... operands) {
super(pos, operands);
public QualifiedIdentifier(int startPos, int endPos, SpelNodeImpl... operands) {
super(startPos, endPos, operands);
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/RealLiteral.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,8 +31,8 @@ public class RealLiteral extends Literal { @@ -31,8 +31,8 @@ public class RealLiteral extends Literal {
private final TypedValue value;
public RealLiteral(String payload, int pos, double value) {
super(payload, pos);
public RealLiteral(String payload, int startPos, int endPos, double value) {
super(payload, startPos, endPos);
this.value = new TypedValue(value);
this.exitTypeDescriptor = "D";
}

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/Selection.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -69,8 +69,8 @@ public class Selection extends SpelNodeImpl { @@ -69,8 +69,8 @@ public class Selection extends SpelNodeImpl {
private final boolean nullSafe;
public Selection(boolean nullSafe, int variant, int pos, SpelNodeImpl expression) {
super(pos, expression);
public Selection(boolean nullSafe, int variant, int startPos, int endPos, SpelNodeImpl expression) {
super(startPos, endPos, expression);
this.nullSafe = nullSafe;
this.variant = variant;
}

15
spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -47,7 +47,9 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes { @@ -47,7 +47,9 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes {
private static final SpelNodeImpl[] NO_CHILDREN = new SpelNodeImpl[0];
protected final int pos; // start = top 16bits, end = bottom 16bits
private final int startPos;
private final int endPos;
protected SpelNodeImpl[] children = SpelNodeImpl.NO_CHILDREN;
@ -67,8 +69,9 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes { @@ -67,8 +69,9 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes {
protected volatile String exitTypeDescriptor;
public SpelNodeImpl(int pos, SpelNodeImpl... operands) {
this.pos = pos;
public SpelNodeImpl(int startPos, int endPos, SpelNodeImpl... operands) {
this.startPos = startPos;
this.endPos = endPos;
if (!ObjectUtils.isEmpty(operands)) {
this.children = operands;
for (SpelNodeImpl operand : operands) {
@ -146,12 +149,12 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes { @@ -146,12 +149,12 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes {
@Override
public int getStartPosition() {
return (this.pos >> 16);
return this.startPos;
}
@Override
public int getEndPosition() {
return (this.pos & 0xffff);
return this.endPos;
}
/**

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/StringLiteral.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,8 +33,8 @@ public class StringLiteral extends Literal { @@ -33,8 +33,8 @@ public class StringLiteral extends Literal {
private final TypedValue value;
public StringLiteral(String payload, int pos, String value) {
super(payload, pos);
public StringLiteral(String payload, int startPos, int endPos, String value) {
super(payload, startPos, endPos);
String valueWithinQuotes = value.substring(1, value.length() - 1);
valueWithinQuotes = StringUtils.replace(valueWithinQuotes, "''", "'");

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/Ternary.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,8 +36,8 @@ import org.springframework.util.ObjectUtils; @@ -36,8 +36,8 @@ import org.springframework.util.ObjectUtils;
*/
public class Ternary extends SpelNodeImpl {
public Ternary(int pos, SpelNodeImpl... args) {
super(pos, args);
public Ternary(int startPos, int endPos, SpelNodeImpl... args) {
super(startPos, endPos, args);
}

10
spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,12 +41,12 @@ public class TypeReference extends SpelNodeImpl { @@ -41,12 +41,12 @@ public class TypeReference extends SpelNodeImpl {
private transient Class<?> type;
public TypeReference(int pos, SpelNodeImpl qualifiedId) {
this(pos, qualifiedId, 0);
public TypeReference(int startPos, int endPos, SpelNodeImpl qualifiedId) {
this(startPos, endPos, qualifiedId, 0);
}
public TypeReference(int pos, SpelNodeImpl qualifiedId, int dims) {
super(pos, qualifiedId);
public TypeReference(int startPos, int endPos, SpelNodeImpl qualifiedId, int dims) {
super(startPos, endPos, qualifiedId);
this.dimensions = dims;
}

9
spring-expression/src/main/java/org/springframework/expression/spel/ast/ValueRef.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,8 +24,8 @@ import org.springframework.lang.Nullable; @@ -24,8 +24,8 @@ import org.springframework.lang.Nullable;
/**
* Represents a reference to a value. With a reference it is possible to get or set the
* value. Passing around value references rather than the values themselves can avoid
* incorrect duplication of operand evaluation. For example in 'list[index++]++' without a
* value reference for 'list[index++]' it would be necessary to evaluate list[index++]
* incorrect duplication of operand evaluation. For example in 'list[index++]++' without
* a value reference for 'list[index++]' it would be necessary to evaluate list[index++]
* twice (once to get the value, once to determine where the value goes) and that would
* double increment index.
*
@ -103,7 +103,8 @@ public interface ValueRef { @@ -103,7 +103,8 @@ public interface ValueRef {
@Override
public void setValue(@Nullable Object newValue) {
throw new SpelEvaluationException(this.node.pos, SpelMessage.NOT_ASSIGNABLE, this.node.toStringAST());
throw new SpelEvaluationException(
this.node.getStartPosition(), SpelMessage.NOT_ASSIGNABLE, this.node.toStringAST());
}
@Override

6
spring-expression/src/main/java/org/springframework/expression/spel/ast/VariableReference.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,8 +44,8 @@ public class VariableReference extends SpelNodeImpl { @@ -44,8 +44,8 @@ public class VariableReference extends SpelNodeImpl {
private final String name;
public VariableReference(String variableName, int pos) {
super(pos);
public VariableReference(String variableName, int startPos, int endPos) {
super(startPos, endPos);
this.name = variableName;
}

152
spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -155,32 +155,32 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -155,32 +155,32 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
if (t != null) {
if (t.kind == TokenKind.ASSIGN) { // a=b
if (expr == null) {
expr = new NullLiteral(toPos(t.startPos - 1, t.endPos - 1));
expr = new NullLiteral(t.startPos - 1, t.endPos - 1);
}
nextToken();
SpelNodeImpl assignedValue = eatLogicalOrExpression();
return new Assign(toPos(t), expr, assignedValue);
return new Assign(t.startPos, t.endPos, expr, assignedValue);
}
if (t.kind == TokenKind.ELVIS) { // a?:b (a if it isn't null, otherwise b)
if (expr == null) {
expr = new NullLiteral(toPos(t.startPos - 1, t.endPos - 2));
expr = new NullLiteral(t.startPos - 1, t.endPos - 2);
}
nextToken(); // elvis has left the building
SpelNodeImpl valueIfNull = eatExpression();
if (valueIfNull == null) {
valueIfNull = new NullLiteral(toPos(t.startPos + 1, t.endPos + 1));
valueIfNull = new NullLiteral(t.startPos + 1, t.endPos + 1);
}
return new Elvis(toPos(t), expr, valueIfNull);
return new Elvis(t.startPos, t.endPos, expr, valueIfNull);
}
if (t.kind == TokenKind.QMARK) { // a?b:c
if (expr == null) {
expr = new NullLiteral(toPos(t.startPos - 1, t.endPos - 1));
expr = new NullLiteral(t.startPos - 1, t.endPos - 1);
}
nextToken();
SpelNodeImpl ifTrueExprValue = eatExpression();
eatToken(TokenKind.COLON);
SpelNodeImpl ifFalseExprValue = eatExpression();
return new Ternary(toPos(t), expr, ifTrueExprValue, ifFalseExprValue);
return new Ternary(t.startPos, t.endPos, expr, ifTrueExprValue, ifFalseExprValue);
}
}
return expr;
@ -194,7 +194,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -194,7 +194,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
Token t = takeToken(); //consume OR
SpelNodeImpl rhExpr = eatLogicalAndExpression();
checkOperands(t, expr, rhExpr);
expr = new OpOr(toPos(t), expr, rhExpr);
expr = new OpOr(t.startPos, t.endPos, expr, rhExpr);
}
return expr;
}
@ -207,7 +207,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -207,7 +207,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
Token t = takeToken(); // consume 'AND'
SpelNodeImpl rhExpr = eatRelationalExpression();
checkOperands(t, expr, rhExpr);
expr = new OpAnd(toPos(t), expr, rhExpr);
expr = new OpAnd(t.startPos, t.endPos, expr, rhExpr);
}
return expr;
}
@ -224,36 +224,35 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -224,36 +224,35 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
TokenKind tk = relationalOperatorToken.kind;
if (relationalOperatorToken.isNumericRelationalOperator()) {
int pos = toPos(t);
if (tk == TokenKind.GT) {
return new OpGT(pos, expr, rhExpr);
return new OpGT(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.LT) {
return new OpLT(pos, expr, rhExpr);
return new OpLT(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.LE) {
return new OpLE(pos, expr, rhExpr);
return new OpLE(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.GE) {
return new OpGE(pos, expr, rhExpr);
return new OpGE(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.EQ) {
return new OpEQ(pos, expr, rhExpr);
return new OpEQ(t.startPos, t.endPos, expr, rhExpr);
}
Assert.isTrue(tk == TokenKind.NE, "Not-equals token expected");
return new OpNE(pos, expr, rhExpr);
return new OpNE(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.INSTANCEOF) {
return new OperatorInstanceof(toPos(t), expr, rhExpr);
return new OperatorInstanceof(t.startPos, t.endPos, expr, rhExpr);
}
if (tk == TokenKind.MATCHES) {
return new OperatorMatches(toPos(t), expr, rhExpr);
return new OperatorMatches(t.startPos, t.endPos, expr, rhExpr);
}
Assert.isTrue(tk == TokenKind.BETWEEN, "Between token expected");
return new OperatorBetween(toPos(t), expr, rhExpr);
return new OperatorBetween(t.startPos, t.endPos, expr, rhExpr);
}
return expr;
}
@ -267,10 +266,10 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -267,10 +266,10 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
SpelNodeImpl rhExpr = eatProductExpression();
checkRightOperand(t, rhExpr);
if (t.kind == TokenKind.PLUS) {
expr = new OpPlus(toPos(t), expr, rhExpr);
expr = new OpPlus(t.startPos, t.endPos, expr, rhExpr);
}
else if (t.kind == TokenKind.MINUS) {
expr = new OpMinus(toPos(t), expr, rhExpr);
expr = new OpMinus(t.startPos, t.endPos, expr, rhExpr);
}
}
return expr;
@ -285,14 +284,14 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -285,14 +284,14 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
SpelNodeImpl rhExpr = eatPowerIncDecExpression();
checkOperands(t, expr, rhExpr);
if (t.kind == TokenKind.STAR) {
expr = new OpMultiply(toPos(t), expr, rhExpr);
expr = new OpMultiply(t.startPos, t.endPos, expr, rhExpr);
}
else if (t.kind == TokenKind.DIV) {
expr = new OpDivide(toPos(t), expr, rhExpr);
expr = new OpDivide(t.startPos, t.endPos, expr, rhExpr);
}
else {
Assert.isTrue(t.kind == TokenKind.MOD, "Mod token expected");
expr = new OpModulus(toPos(t), expr, rhExpr);
expr = new OpModulus(t.startPos, t.endPos, expr, rhExpr);
}
}
return expr;
@ -306,14 +305,14 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -306,14 +305,14 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
Token t = takeToken(); //consume POWER
SpelNodeImpl rhExpr = eatUnaryExpression();
checkRightOperand(t, rhExpr);
return new OperatorPower(toPos(t), expr, rhExpr);
return new OperatorPower(t.startPos, t.endPos, expr, rhExpr);
}
if (expr != null && peekToken(TokenKind.INC, TokenKind.DEC)) {
Token t = takeToken(); //consume INC/DEC
if (t.getKind() == TokenKind.INC) {
return new OpInc(toPos(t), true, expr);
return new OpInc(t.startPos, t.endPos, true, expr);
}
return new OpDec(toPos(t), true, expr);
return new OpDec(t.startPos, t.endPos, true, expr);
}
return expr;
}
@ -326,21 +325,21 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -326,21 +325,21 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
SpelNodeImpl expr = eatUnaryExpression();
Assert.state(expr != null, "No node");
if (t.kind == TokenKind.NOT) {
return new OperatorNot(toPos(t), expr);
return new OperatorNot(t.startPos, t.endPos, expr);
}
if (t.kind == TokenKind.PLUS) {
return new OpPlus(toPos(t), expr);
return new OpPlus(t.startPos, t.endPos, expr);
}
Assert.isTrue(t.kind == TokenKind.MINUS, "Minus token expected");
return new OpMinus(toPos(t), expr);
return new OpMinus(t.startPos, t.endPos, expr);
}
if (peekToken(TokenKind.INC, TokenKind.DEC)) {
Token t = takeToken();
SpelNodeImpl expr = eatUnaryExpression();
if (t.getKind() == TokenKind.INC) {
return new OpInc(toPos(t), false, expr);
return new OpInc(t.startPos, t.endPos, false, expr);
}
return new OpDec(toPos(t), false, expr);
return new OpDec(t.startPos, t.endPos, false, expr);
}
return eatPrimaryExpression();
}
@ -362,8 +361,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -362,8 +361,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
if (start == null || nodes == null) {
return start;
}
return new CompoundExpression(toPos(start.getStartPosition(),
nodes.get(nodes.size() - 1).getEndPosition()),
return new CompoundExpression(start.getStartPosition(), nodes.get(nodes.size() - 1).getEndPosition(),
nodes.toArray(new SpelNodeImpl[0]));
}
@ -424,12 +422,12 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -424,12 +422,12 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
SpelNodeImpl[] args = maybeEatMethodArgs();
if (args == null) {
push(new VariableReference(functionOrVariableName.stringValue(),
toPos(t.startPos, functionOrVariableName.endPos)));
t.startPos, functionOrVariableName.endPos));
return true;
}
push(new FunctionReference(functionOrVariableName.stringValue(),
toPos(t.startPos, functionOrVariableName.endPos), args));
t.startPos, functionOrVariableName.endPos, args));
return true;
}
@ -548,11 +546,10 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -548,11 +546,10 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
BeanReference beanReference;
if (beanRefToken.getKind() == TokenKind.FACTORY_BEAN_REF) {
String beanNameString = String.valueOf(TokenKind.FACTORY_BEAN_REF.tokenChars) + beanName;
beanReference = new BeanReference(
toPos(beanRefToken.startPos, beanNameToken.endPos), beanNameString);
beanReference = new BeanReference(beanRefToken.startPos, beanNameToken.endPos, beanNameString);
}
else {
beanReference = new BeanReference(toPos(beanNameToken), beanName);
beanReference = new BeanReference(beanNameToken.startPos, beanNameToken.endPos, beanName);
}
this.constructedNodes.push(beanReference);
return true;
@ -571,7 +568,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -571,7 +568,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
Token t = takeToken();
if (peekToken(TokenKind.RSQUARE)) {
// looks like 'T]' (T is map key)
push(new PropertyOrFieldReference(false, t.stringValue(), toPos(t)));
push(new PropertyOrFieldReference(false, t.stringValue(), t.startPos, t.endPos));
return true;
}
eatToken(TokenKind.LPAREN);
@ -584,7 +581,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -584,7 +581,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
dims++;
}
eatToken(TokenKind.RPAREN);
this.constructedNodes.push(new TypeReference(toPos(typeName), node, dims));
this.constructedNodes.push(new TypeReference(typeName.startPos, typeName.endPos, node, dims));
return true;
}
return false;
@ -598,7 +595,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -598,7 +595,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
return false;
}
nextToken();
this.constructedNodes.push(new NullLiteral(toPos(nullToken)));
this.constructedNodes.push(new NullLiteral(nullToken.startPos, nullToken.endPos));
return true;
}
return false;
@ -614,7 +611,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -614,7 +611,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
SpelNodeImpl expr = eatExpression();
Assert.state(expr != null, "No node");
eatToken(TokenKind.RSQUARE);
this.constructedNodes.push(new Projection(nullSafeNavigation, toPos(t), expr));
this.constructedNodes.push(new Projection(nullSafeNavigation, t.startPos, t.endPos, expr));
return true;
}
@ -631,12 +628,12 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -631,12 +628,12 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
if (peekToken(TokenKind.RCURLY, true)) {
// empty list '{}'
Assert.state(closingCurly != null, "No token");
expr = new InlineList(toPos(t.startPos, closingCurly.endPos));
expr = new InlineList(t.startPos, closingCurly.endPos);
}
else if (peekToken(TokenKind.COLON, true)) {
closingCurly = eatToken(TokenKind.RCURLY);
// empty map '{:}'
expr = new InlineMap(toPos(t.startPos, closingCurly.endPos));
expr = new InlineMap(t.startPos, closingCurly.endPos);
}
else {
SpelNodeImpl firstExpression = eatExpression();
@ -648,7 +645,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -648,7 +645,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
List<SpelNodeImpl> elements = new ArrayList<>();
elements.add(firstExpression);
closingCurly = eatToken(TokenKind.RCURLY);
expr = new InlineList(toPos(t.startPos, closingCurly.endPos), elements.toArray(new SpelNodeImpl[0]));
expr = new InlineList(t.startPos, closingCurly.endPos, elements.toArray(new SpelNodeImpl[0]));
}
else if (peekToken(TokenKind.COMMA, true)) { // multi-item list
List<SpelNodeImpl> elements = new ArrayList<>();
@ -658,7 +655,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -658,7 +655,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
}
while (peekToken(TokenKind.COMMA, true));
closingCurly = eatToken(TokenKind.RCURLY);
expr = new InlineList(toPos(t.startPos, closingCurly.endPos), elements.toArray(new SpelNodeImpl[0]));
expr = new InlineList(t.startPos, closingCurly.endPos, elements.toArray(new SpelNodeImpl[0]));
}
else if (peekToken(TokenKind.COLON, true)) { // map!
@ -671,7 +668,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -671,7 +668,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
elements.add(eatExpression());
}
closingCurly = eatToken(TokenKind.RCURLY);
expr = new InlineMap(toPos(t.startPos, closingCurly.endPos), elements.toArray(new SpelNodeImpl[0]));
expr = new InlineMap(t.startPos, closingCurly.endPos, elements.toArray(new SpelNodeImpl[0]));
}
else {
throw internalException(t.startPos, SpelMessage.OOD);
@ -690,7 +687,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -690,7 +687,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
SpelNodeImpl expr = eatExpression();
Assert.state(expr != null, "No node");
eatToken(TokenKind.RSQUARE);
this.constructedNodes.push(new Indexer(toPos(t), expr));
this.constructedNodes.push(new Indexer(t.startPos, t.endPos, expr));
return true;
}
@ -703,17 +700,17 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -703,17 +700,17 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
nextToken();
SpelNodeImpl expr = eatExpression();
if (expr == null) {
throw internalException(toPos(t), SpelMessage.MISSING_SELECTION_EXPRESSION);
throw internalException(t.startPos, SpelMessage.MISSING_SELECTION_EXPRESSION);
}
eatToken(TokenKind.RSQUARE);
if (t.kind == TokenKind.SELECT_FIRST) {
this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.FIRST, toPos(t), expr));
this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.FIRST, t.startPos, t.endPos, expr));
}
else if (t.kind == TokenKind.SELECT_LAST) {
this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.LAST, toPos(t), expr));
this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.LAST, t.startPos, t.endPos, expr));
}
else {
this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.ALL, toPos(t), expr));
this.constructedNodes.push(new Selection(nullSafeNavigation, Selection.ALL, t.startPos, t.endPos, expr));
}
return true;
}
@ -728,7 +725,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -728,7 +725,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
while (isValidQualifiedId(node)) {
nextToken();
if (node.kind != TokenKind.DOT) {
qualifiedIdPieces.add(new Identifier(node.stringValue(), toPos(node)));
qualifiedIdPieces.add(new Identifier(node.stringValue(), node.startPos, node.endPos));
}
node = peekToken();
}
@ -739,8 +736,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -739,8 +736,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
throw internalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN,
"qualified ID", node.getKind().toString().toLowerCase());
}
int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition());
return new QualifiedIdentifier(pos, qualifiedIdPieces.toArray(new SpelNodeImpl[0]));
return new QualifiedIdentifier(qualifiedIdPieces.getFirst().getStartPosition(),
qualifiedIdPieces.getLast().getEndPosition(), qualifiedIdPieces.toArray(new SpelNodeImpl[0]));
}
private boolean isValidQualifiedId(@Nullable Token node) {
@ -764,12 +761,12 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -764,12 +761,12 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
if (args == null) {
// property
push(new PropertyOrFieldReference(nullSafeNavigation, methodOrPropertyName.stringValue(),
toPos(methodOrPropertyName)));
methodOrPropertyName.startPos, methodOrPropertyName.endPos));
return true;
}
// method reference
push(new MethodReference(nullSafeNavigation, methodOrPropertyName.stringValue(),
toPos(methodOrPropertyName), args));
methodOrPropertyName.startPos, methodOrPropertyName.endPos, args));
// TODO what is the end position for a method reference? the name or the last arg?
return true;
}
@ -784,7 +781,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -784,7 +781,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
// It looks like a constructor reference but is NEW being used as a map key?
if (peekToken(TokenKind.RSQUARE)) {
// looks like 'NEW]' (so NEW used as map key)
push(new PropertyOrFieldReference(false, newToken.stringValue(), toPos(newToken)));
push(new PropertyOrFieldReference(false, newToken.stringValue(), newToken.startPos, newToken.endPos));
return true;
}
SpelNodeImpl possiblyQualifiedConstructorName = eatPossiblyQualifiedId();
@ -805,14 +802,14 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -805,14 +802,14 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
if (maybeEatInlineListOrMap()) {
nodes.add(pop());
}
push(new ConstructorReference(toPos(newToken),
push(new ConstructorReference(newToken.startPos, newToken.endPos,
dimensions.toArray(new SpelNodeImpl[0]), nodes.toArray(new SpelNodeImpl[0])));
}
else {
// regular constructor invocation
eatConstructorArgs(nodes);
// TODO correct end position?
push(new ConstructorReference(toPos(newToken), nodes.toArray(new SpelNodeImpl[0])));
push(new ConstructorReference(newToken.startPos, newToken.endPos, nodes.toArray(new SpelNodeImpl[0])));
}
return true;
}
@ -841,31 +838,31 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -841,31 +838,31 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
return false;
}
if (t.kind == TokenKind.LITERAL_INT) {
push(Literal.getIntLiteral(t.stringValue(), toPos(t), 10));
push(Literal.getIntLiteral(t.stringValue(), t.startPos, t.endPos, 10));
}
else if (t.kind == TokenKind.LITERAL_LONG) {
push(Literal.getLongLiteral(t.stringValue(), toPos(t), 10));
push(Literal.getLongLiteral(t.stringValue(), t.startPos, t.endPos, 10));
}
else if (t.kind == TokenKind.LITERAL_HEXINT) {
push(Literal.getIntLiteral(t.stringValue(), toPos(t), 16));
push(Literal.getIntLiteral(t.stringValue(), t.startPos, t.endPos, 16));
}
else if (t.kind == TokenKind.LITERAL_HEXLONG) {
push(Literal.getLongLiteral(t.stringValue(), toPos(t), 16));
push(Literal.getLongLiteral(t.stringValue(), t.startPos, t.endPos, 16));
}
else if (t.kind == TokenKind.LITERAL_REAL) {
push(Literal.getRealLiteral(t.stringValue(), toPos(t), false));
push(Literal.getRealLiteral(t.stringValue(), t.startPos, t.endPos, false));
}
else if (t.kind == TokenKind.LITERAL_REAL_FLOAT) {
push(Literal.getRealLiteral(t.stringValue(), toPos(t), true));
push(Literal.getRealLiteral(t.stringValue(), t.startPos, t.endPos, true));
}
else if (peekIdentifierToken("true")) {
push(new BooleanLiteral(t.stringValue(), toPos(t), true));
push(new BooleanLiteral(t.stringValue(), t.startPos, t.endPos, true));
}
else if (peekIdentifierToken("false")) {
push(new BooleanLiteral(t.stringValue(), toPos(t), false));
push(new BooleanLiteral(t.stringValue(), t.startPos, t.endPos, false));
}
else if (t.kind == TokenKind.LITERAL_STRING) {
push(new StringLiteral(t.stringValue(), toPos(t), t.stringValue()));
push(new StringLiteral(t.stringValue(), t.startPos, t.endPos, t.stringValue()));
}
else {
return false;
@ -1040,17 +1037,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -1040,17 +1037,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
}
}
private InternalParseException internalException(int pos, SpelMessage message, Object... inserts) {
return new InternalParseException(new SpelParseException(this.expressionString, pos, message, inserts));
}
private int toPos(Token t) {
// Compress the start and end of a token into a single int
return (t.startPos << 16) + t.endPos;
}
private int toPos(int start, int end) {
return (start << 16) + end;
private InternalParseException internalException(int startPos, SpelMessage message, Object... inserts) {
return new InternalParseException(new SpelParseException(this.expressionString, startPos, message, inserts));
}
}

82
spring-expression/src/test/java/org/springframework/expression/spel/ast/OpPlusTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -23,7 +23,6 @@ import java.util.Locale; @@ -23,7 +23,6 @@ import java.util.Locale;
import org.junit.Test;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.ExpressionState;
@ -45,16 +44,16 @@ public class OpPlusTests { @@ -45,16 +44,16 @@ public class OpPlusTests {
@Test(expected = IllegalArgumentException.class)
public void test_emptyOperands() {
new OpPlus(-1);
new OpPlus(-1, -1);
}
@Test(expected = SpelEvaluationException.class)
public void test_unaryPlusWithStringLiteral() {
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
StringLiteral str = new StringLiteral("word", -1, "word");
StringLiteral str = new StringLiteral("word", -1, -1, "word");
OpPlus o = new OpPlus(-1, str);
OpPlus o = new OpPlus(-1, -1, str);
o.getValueInternal(expressionState);
}
@ -63,8 +62,8 @@ public class OpPlusTests { @@ -63,8 +62,8 @@ public class OpPlusTests {
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
{
RealLiteral realLiteral = new RealLiteral("123.00", -1, 123.0);
OpPlus o = new OpPlus(-1, realLiteral);
RealLiteral realLiteral = new RealLiteral("123.00", -1, -1, 123.0);
OpPlus o = new OpPlus(-1, -1, realLiteral);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(Double.class, value.getTypeDescriptor().getObjectType());
@ -73,8 +72,8 @@ public class OpPlusTests { @@ -73,8 +72,8 @@ public class OpPlusTests {
}
{
IntLiteral intLiteral = new IntLiteral("123", -1, 123);
OpPlus o = new OpPlus(-1, intLiteral);
IntLiteral intLiteral = new IntLiteral("123", -1, -1, 123);
OpPlus o = new OpPlus(-1, -1, intLiteral);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(Integer.class, value.getTypeDescriptor().getObjectType());
@ -83,8 +82,8 @@ public class OpPlusTests { @@ -83,8 +82,8 @@ public class OpPlusTests {
}
{
LongLiteral longLiteral = new LongLiteral("123", -1, 123L);
OpPlus o = new OpPlus(-1, longLiteral);
LongLiteral longLiteral = new LongLiteral("123", -1, -1, 123L);
OpPlus o = new OpPlus(-1, -1, longLiteral);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(Long.class, value.getTypeDescriptor().getObjectType());
@ -98,9 +97,9 @@ public class OpPlusTests { @@ -98,9 +97,9 @@ public class OpPlusTests {
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
{
RealLiteral n1 = new RealLiteral("123.00", -1, 123.0);
RealLiteral n2 = new RealLiteral("456.00", -1, 456.0);
OpPlus o = new OpPlus(-1, n1, n2);
RealLiteral n1 = new RealLiteral("123.00", -1, -1, 123.0);
RealLiteral n2 = new RealLiteral("456.00", -1, -1, 456.0);
OpPlus o = new OpPlus(-1, -1, n1, n2);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(Double.class, value.getTypeDescriptor().getObjectType());
@ -109,9 +108,9 @@ public class OpPlusTests { @@ -109,9 +108,9 @@ public class OpPlusTests {
}
{
LongLiteral n1 = new LongLiteral("123", -1, 123L);
LongLiteral n2 = new LongLiteral("456", -1, 456L);
OpPlus o = new OpPlus(-1, n1, n2);
LongLiteral n1 = new LongLiteral("123", -1, -1, 123L);
LongLiteral n2 = new LongLiteral("456", -1, -1, 456L);
OpPlus o = new OpPlus(-1, -1, n1, n2);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(Long.class, value.getTypeDescriptor().getObjectType());
@ -120,9 +119,9 @@ public class OpPlusTests { @@ -120,9 +119,9 @@ public class OpPlusTests {
}
{
IntLiteral n1 = new IntLiteral("123", -1, 123);
IntLiteral n2 = new IntLiteral("456", -1, 456);
OpPlus o = new OpPlus(-1, n1, n2);
IntLiteral n1 = new IntLiteral("123", -1, -1, 123);
IntLiteral n2 = new IntLiteral("456", -1, -1, 456);
OpPlus o = new OpPlus(-1, -1, n1, n2);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(Integer.class, value.getTypeDescriptor().getObjectType());
@ -135,9 +134,9 @@ public class OpPlusTests { @@ -135,9 +134,9 @@ public class OpPlusTests {
public void test_binaryPlusWithStringOperands() {
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
StringLiteral n1 = new StringLiteral("\"foo\"", -1, "\"foo\"");
StringLiteral n2 = new StringLiteral("\"bar\"", -1, "\"bar\"");
OpPlus o = new OpPlus(-1, n1, n2);
StringLiteral n1 = new StringLiteral("\"foo\"", -1, -1, "\"foo\"");
StringLiteral n2 = new StringLiteral("\"bar\"", -1, -1, "\"bar\"");
OpPlus o = new OpPlus(-1, -1, n1, n2);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
@ -149,9 +148,9 @@ public class OpPlusTests { @@ -149,9 +148,9 @@ public class OpPlusTests {
public void test_binaryPlusWithLeftStringOperand() {
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
StringLiteral n1 = new StringLiteral("\"number is \"", -1, "\"number is \"");
LongLiteral n2 = new LongLiteral("123", -1, 123);
OpPlus o = new OpPlus(-1, n1, n2);
StringLiteral n1 = new StringLiteral("\"number is \"", -1, -1, "\"number is \"");
LongLiteral n2 = new LongLiteral("123", -1, -1, 123);
OpPlus o = new OpPlus(-1, -1, n1, n2);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
@ -163,9 +162,9 @@ public class OpPlusTests { @@ -163,9 +162,9 @@ public class OpPlusTests {
public void test_binaryPlusWithRightStringOperand() {
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
LongLiteral n1 = new LongLiteral("123", -1, 123);
StringLiteral n2 = new StringLiteral("\" is a number\"", -1, "\" is a number\"");
OpPlus o = new OpPlus(-1, n1, n2);
LongLiteral n1 = new LongLiteral("123", -1, -1, 123);
StringLiteral n2 = new StringLiteral("\" is a number\"", -1, -1, "\" is a number\"");
OpPlus o = new OpPlus(-1, -1, n1, n2);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
@ -175,16 +174,14 @@ public class OpPlusTests { @@ -175,16 +174,14 @@ public class OpPlusTests {
@Test
public void test_binaryPlusWithTime_ToString() {
ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
Time time = new Time(new Date().getTime());
VariableReference var = new VariableReference("timeVar", -1);
VariableReference var = new VariableReference("timeVar", -1, -1);
var.setValue(expressionState, time);
StringLiteral n2 = new StringLiteral("\" is now\"", -1, "\" is now\"");
OpPlus o = new OpPlus(-1, var, n2);
StringLiteral n2 = new StringLiteral("\" is now\"", -1, -1, "\" is now\"");
OpPlus o = new OpPlus(-1, -1, var, n2);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(String.class, value.getTypeDescriptor().getObjectType());
@ -194,29 +191,22 @@ public class OpPlusTests { @@ -194,29 +191,22 @@ public class OpPlusTests {
@Test
public void test_binaryPlusWithTimeConverted() {
final SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH);
SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH);
GenericConversionService conversionService = new GenericConversionService();
conversionService.addConverter(new Converter<Time, String>() {
@Override
public String convert(Time source) {
return format.format(source);
}
});
conversionService.addConverter(Time.class, String.class, format::format);
StandardEvaluationContext evaluationContextConverter = new StandardEvaluationContext();
evaluationContextConverter.setTypeConverter(new StandardTypeConverter(conversionService));
ExpressionState expressionState = new ExpressionState(evaluationContextConverter);
Time time = new Time(new Date().getTime());
VariableReference var = new VariableReference("timeVar", -1);
VariableReference var = new VariableReference("timeVar", -1, -1);
var.setValue(expressionState, time);
StringLiteral n2 = new StringLiteral("\" is now\"", -1, "\" is now\"");
OpPlus o = new OpPlus(-1, var, n2);
StringLiteral n2 = new StringLiteral("\" is now\"", -1, -1, "\" is now\"");
OpPlus o = new OpPlus(-1, -1, var, n2);
TypedValue value = o.getValueInternal(expressionState);
assertEquals(String.class, value.getTypeDescriptor().getObjectType());

Loading…
Cancel
Save