TypeDescriptor.valueOf usage in favor of constants; TypedValue usage simplification
This commit is contained in:
@@ -107,11 +107,11 @@ public class CompositeStringExpression implements Expression {
|
||||
}
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) {
|
||||
return TypeDescriptor.STRING;
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor() {
|
||||
return TypeDescriptor.STRING;
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
public void setValue(EvaluationContext context, Object value) throws EvaluationException {
|
||||
@@ -157,11 +157,11 @@ public class CompositeStringExpression implements Expression {
|
||||
}
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.STRING;
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.STRING;
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
|
||||
@@ -62,11 +62,11 @@ public class LiteralExpression implements Expression {
|
||||
}
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) {
|
||||
return TypeDescriptor.STRING;
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor() {
|
||||
return TypeDescriptor.STRING;
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
public void setValue(EvaluationContext context, Object value) throws EvaluationException {
|
||||
@@ -91,49 +91,40 @@ public class LiteralExpression implements Expression {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
||||
public <T> T getValue(Object rootObject, Class<T> desiredResultType) throws EvaluationException {
|
||||
Object value = getValue(rootObject);
|
||||
return ExpressionUtils.convert(null, value, desiredResultType);
|
||||
}
|
||||
|
||||
|
||||
public String getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return this.literalValue;
|
||||
}
|
||||
|
||||
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> desiredResultType) throws EvaluationException {
|
||||
Object value = getValue(context, rootObject);
|
||||
return ExpressionUtils.convert(null, value, desiredResultType);
|
||||
}
|
||||
|
||||
|
||||
public Class getValueType(Object rootObject) throws EvaluationException {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
||||
public Class getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.STRING;
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.STRING;
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException {
|
||||
throw new EvaluationException(literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Identifier extends SpelNodeImpl {
|
||||
|
||||
public Identifier(String payload,int pos) {
|
||||
super(pos);
|
||||
this.id = new TypedValue(payload, STRING_TYPE_DESCRIPTOR);
|
||||
this.id = new TypedValue(payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Indexer extends SpelNodeImpl {
|
||||
if (targetObject instanceof Map && (children[0] instanceof PropertyOrFieldReference)) {
|
||||
PropertyOrFieldReference reference = (PropertyOrFieldReference)children[0];
|
||||
index = reference.getName();
|
||||
indexValue = new TypedValue(index, TypeDescriptor.STRING);
|
||||
indexValue = new TypedValue(index);
|
||||
}
|
||||
else {
|
||||
// In case the map key is unqualified, we want it evaluated against the root object so
|
||||
@@ -75,23 +75,20 @@ public class Indexer extends SpelNodeImpl {
|
||||
if (targetObject == null) {
|
||||
// Current decision: attempt to index into null map == exception and does not just return null
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);
|
||||
// if (targetObjectTypeDescriptor.isMapEntryTypeKnown()) {
|
||||
// return new TypedValue(null,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getMapValueType()));
|
||||
// } else {
|
||||
// return new TypedValue(null,TypeDescriptor.NULL);
|
||||
// }
|
||||
}
|
||||
Object possiblyConvertedKey = index;
|
||||
if (targetObjectTypeDescriptor.isMapEntryTypeKnown()) {
|
||||
possiblyConvertedKey = state.convertValue(index,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getMapKeyType()));
|
||||
}
|
||||
Object o = ((Map<?, ?>) targetObject).get(possiblyConvertedKey);
|
||||
TypeDescriptor resultDescriptor = (targetObjectTypeDescriptor.isMapEntryTypeKnown() ?
|
||||
TypeDescriptor.valueOf(targetObjectTypeDescriptor.getMapValueType()) : TypeDescriptor.OBJECT);
|
||||
return new TypedValue(o,resultDescriptor);
|
||||
if (targetObjectTypeDescriptor.isMapEntryTypeKnown()) {
|
||||
return new TypedValue(o, targetObjectTypeDescriptor.getMapValueTypeDescriptor());
|
||||
} else {
|
||||
return new TypedValue(o);
|
||||
}
|
||||
}
|
||||
|
||||
int idx = (Integer)state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
|
||||
int idx = (Integer)state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
|
||||
|
||||
if (targetObject == null) {
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);
|
||||
@@ -139,7 +136,7 @@ public class Indexer extends SpelNodeImpl {
|
||||
if (idx >= ctxString.length()) {
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.STRING_INDEX_OUT_OF_BOUNDS, ctxString.length(), idx);
|
||||
}
|
||||
return new TypedValue(String.valueOf(ctxString.charAt(idx)),STRING_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(String.valueOf(ctxString.charAt(idx)));
|
||||
}
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetObjectTypeDescriptor.asString());
|
||||
}
|
||||
@@ -175,11 +172,11 @@ public class Indexer extends SpelNodeImpl {
|
||||
}
|
||||
|
||||
if (targetObjectTypeDescriptor.isArray()) {
|
||||
int idx = (Integer)state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
|
||||
int idx = (Integer)state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
|
||||
setArrayElement(state, contextObject.getValue(), idx, newValue, targetObjectTypeDescriptor.getElementType());
|
||||
}
|
||||
else if (targetObjectTypeDescriptor.isCollection()) {
|
||||
int idx = (Integer)state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
|
||||
int idx = (Integer)state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
|
||||
Collection c = (Collection) targetObject;
|
||||
if (idx >= c.size()) {
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS, c.size(), idx);
|
||||
@@ -215,35 +212,35 @@ public class Indexer extends SpelNodeImpl {
|
||||
if (arrayComponentType == Integer.TYPE) {
|
||||
int[] array = (int[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = (Integer)state.convertValue(newValue, INTEGER_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Integer)state.convertValue(newValue, TypeDescriptor.valueOf(Integer.class));
|
||||
} else if (arrayComponentType == Boolean.TYPE) {
|
||||
boolean[] array = (boolean[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = (Boolean)state.convertValue(newValue, BOOLEAN_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Boolean)state.convertValue(newValue, TypeDescriptor.valueOf(Boolean.class));
|
||||
} else if (arrayComponentType == Character.TYPE) {
|
||||
char[] array = (char[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = (Character)state.convertValue(newValue, CHARACTER_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Character)state.convertValue(newValue, TypeDescriptor.valueOf(Character.class));
|
||||
} else if (arrayComponentType == Long.TYPE) {
|
||||
long[] array = (long[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = (Long)state.convertValue(newValue, LONG_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Long)state.convertValue(newValue, TypeDescriptor.valueOf(Long.class));
|
||||
} else if (arrayComponentType == Short.TYPE) {
|
||||
short[] array = (short[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = (Short)state.convertValue(newValue, SHORT_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Short)state.convertValue(newValue, TypeDescriptor.valueOf(Short.class));
|
||||
} else if (arrayComponentType == Double.TYPE) {
|
||||
double[] array = (double[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = (Double)state.convertValue(newValue, DOUBLE_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Double)state.convertValue(newValue, TypeDescriptor.valueOf(Double.class));
|
||||
} else if (arrayComponentType == Float.TYPE) {
|
||||
float[] array = (float[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = (Float)state.convertValue(newValue, FLOAT_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Float)state.convertValue(newValue, TypeDescriptor.valueOf(Float.class));
|
||||
} else if (arrayComponentType == Byte.TYPE) {
|
||||
byte[] array = (byte[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = (Byte)state.convertValue(newValue, BYTE_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Byte)state.convertValue(newValue, TypeDescriptor.valueOf(Byte.class));
|
||||
} else {
|
||||
Object[] array = (Object[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
|
||||
@@ -14,7 +14,7 @@ public class IntLiteral extends Literal {
|
||||
|
||||
IntLiteral(String payload, int pos, int value) {
|
||||
super(payload, pos);
|
||||
this.value = new TypedValue(value, INTEGER_TYPE_DESCRIPTOR);
|
||||
this.value = new TypedValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,7 @@ public class LongLiteral extends Literal {
|
||||
|
||||
LongLiteral(String payload, int pos, long value) {
|
||||
super(payload, pos);
|
||||
this.value = new TypedValue(value, LONG_TYPE_DESCRIPTOR);
|
||||
this.value = new TypedValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.expression.spel.ast;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.ExpressionState;
|
||||
@@ -44,7 +45,7 @@ public class OpAnd extends Operator {
|
||||
try {
|
||||
TypedValue typedValue = getLeftOperand().getValueInternal(state);
|
||||
this.assertTypedValueNotNull(typedValue);
|
||||
leftValue = (Boolean)state.convertValue(typedValue, BOOLEAN_TYPE_DESCRIPTOR);
|
||||
leftValue = (Boolean)state.convertValue(typedValue, TypeDescriptor.valueOf(Boolean.class));
|
||||
}
|
||||
catch (SpelEvaluationException ee) {
|
||||
ee.setPosition(getLeftOperand().getStartPosition());
|
||||
@@ -58,7 +59,7 @@ public class OpAnd extends Operator {
|
||||
try {
|
||||
TypedValue typedValue = getRightOperand().getValueInternal(state);
|
||||
this.assertTypedValueNotNull(typedValue);
|
||||
rightValue = (Boolean)state.convertValue(typedValue, BOOLEAN_TYPE_DESCRIPTOR);
|
||||
rightValue = (Boolean)state.convertValue(typedValue, TypeDescriptor.valueOf(Boolean.class));
|
||||
}
|
||||
catch (SpelEvaluationException ee) {
|
||||
ee.setPosition(getRightOperand().getStartPosition());
|
||||
|
||||
@@ -42,11 +42,11 @@ public class OpDivide extends Operator {
|
||||
Number op1 = (Number) operandOne;
|
||||
Number op2 = (Number) operandTwo;
|
||||
if (op1 instanceof Double || op2 instanceof Double) {
|
||||
return new TypedValue(op1.doubleValue() / op2.doubleValue(), DOUBLE_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.doubleValue() / op2.doubleValue());
|
||||
} else if (op1 instanceof Long || op2 instanceof Long) {
|
||||
return new TypedValue(op1.longValue() / op2.longValue(), LONG_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.longValue() / op2.longValue());
|
||||
} else { // TODO what about non-int result of the division?
|
||||
return new TypedValue(op1.intValue() / op2.intValue(), INTEGER_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.intValue() / op2.intValue());
|
||||
}
|
||||
}
|
||||
Object result = state.operate(Operation.DIVIDE, operandOne, operandTwo);
|
||||
|
||||
@@ -51,11 +51,11 @@ public class OpMinus extends Operator {
|
||||
if (operand instanceof Number) {
|
||||
Number n = (Number) operand;
|
||||
if (operand instanceof Double) {
|
||||
return new TypedValue(0 - n.doubleValue(),DOUBLE_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(0 - n.doubleValue());
|
||||
} else if (operand instanceof Long) {
|
||||
return new TypedValue(0 - n.longValue(),LONG_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(0 - n.longValue());
|
||||
} else {
|
||||
return new TypedValue(0 - n.intValue(),INTEGER_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(0 - n.intValue());
|
||||
}
|
||||
}
|
||||
return state.operate(Operation.SUBTRACT, operand, null);
|
||||
@@ -66,17 +66,17 @@ public class OpMinus extends Operator {
|
||||
Number op1 = (Number) left;
|
||||
Number op2 = (Number) right;
|
||||
if (op1 instanceof Double || op2 instanceof Double) {
|
||||
return new TypedValue(op1.doubleValue() - op2.doubleValue(),DOUBLE_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.doubleValue() - op2.doubleValue());
|
||||
} else if (op1 instanceof Long || op2 instanceof Long) {
|
||||
return new TypedValue(op1.longValue() - op2.longValue(),LONG_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.longValue() - op2.longValue());
|
||||
} else {
|
||||
return new TypedValue(op1.intValue() - op2.intValue(),INTEGER_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.intValue() - op2.intValue());
|
||||
}
|
||||
} else if (left instanceof String && right instanceof Integer && ((String)left).length()==1) {
|
||||
String theString = (String) left;
|
||||
Integer theInteger = (Integer) right;
|
||||
// implements character - int (ie. b - 1 = a)
|
||||
return new TypedValue(Character.toString((char) (theString.charAt(0) - theInteger)),STRING_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(Character.toString((char) (theString.charAt(0) - theInteger)));
|
||||
}
|
||||
return state.operate(Operation.SUBTRACT, left, right);
|
||||
}
|
||||
|
||||
@@ -41,11 +41,11 @@ public class OpModulus extends Operator {
|
||||
Number op1 = (Number) operandOne;
|
||||
Number op2 = (Number) operandTwo;
|
||||
if (op1 instanceof Double || op2 instanceof Double) {
|
||||
return new TypedValue(op1.doubleValue() % op2.doubleValue(),DOUBLE_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.doubleValue() % op2.doubleValue());
|
||||
} else if (op1 instanceof Long || op2 instanceof Long) {
|
||||
return new TypedValue(op1.longValue() % op2.longValue(),LONG_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.longValue() % op2.longValue());
|
||||
} else {
|
||||
return new TypedValue(op1.intValue() % op2.intValue(),INTEGER_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.intValue() % op2.intValue());
|
||||
}
|
||||
}
|
||||
return state.operate(Operation.MODULUS, operandOne, operandTwo);
|
||||
|
||||
@@ -60,11 +60,11 @@ public class OpMultiply extends Operator {
|
||||
Number leftNumber = (Number) operandOne;
|
||||
Number rightNumber = (Number) operandTwo;
|
||||
if (leftNumber instanceof Double || rightNumber instanceof Double) {
|
||||
return new TypedValue(leftNumber.doubleValue() * rightNumber.doubleValue(), DOUBLE_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(leftNumber.doubleValue() * rightNumber.doubleValue());
|
||||
} else if (leftNumber instanceof Long || rightNumber instanceof Long) {
|
||||
return new TypedValue(leftNumber.longValue() * rightNumber.longValue(), LONG_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(leftNumber.longValue() * rightNumber.longValue());
|
||||
} else {
|
||||
return new TypedValue(leftNumber.intValue() * rightNumber.intValue(), INTEGER_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(leftNumber.intValue() * rightNumber.intValue());
|
||||
}
|
||||
} else if (operandOne instanceof String && operandTwo instanceof Integer) {
|
||||
int repeats = (Integer) operandTwo;
|
||||
@@ -72,7 +72,7 @@ public class OpMultiply extends Operator {
|
||||
for (int i = 0; i < repeats; i++) {
|
||||
result.append(operandOne);
|
||||
}
|
||||
return new TypedValue(result.toString(), STRING_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(result.toString());
|
||||
}
|
||||
return state.operate(Operation.MULTIPLY, operandOne, operandTwo);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.expression.spel.ast;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.ExpressionState;
|
||||
@@ -43,7 +44,7 @@ public class OpOr extends Operator {
|
||||
try {
|
||||
TypedValue typedValue = getLeftOperand().getValueInternal(state);
|
||||
this.assertTypedValueNotNull(typedValue);
|
||||
leftValue = (Boolean)state.convertValue(typedValue, BOOLEAN_TYPE_DESCRIPTOR);
|
||||
leftValue = (Boolean)state.convertValue(typedValue, TypeDescriptor.valueOf(Boolean.class));
|
||||
}
|
||||
catch (SpelEvaluationException see) {
|
||||
see.setPosition(getLeftOperand().getStartPosition());
|
||||
@@ -57,7 +58,7 @@ public class OpOr extends Operator {
|
||||
try {
|
||||
TypedValue typedValue = getRightOperand().getValueInternal(state);
|
||||
this.assertTypedValueNotNull(typedValue);
|
||||
rightValue = (Boolean)state.convertValue(typedValue, BOOLEAN_TYPE_DESCRIPTOR);
|
||||
rightValue = (Boolean)state.convertValue(typedValue, TypeDescriptor.valueOf(Boolean.class));
|
||||
}
|
||||
catch (SpelEvaluationException see) {
|
||||
see.setPosition(getRightOperand().getStartPosition()); // TODO end positions here and in similar situations
|
||||
|
||||
@@ -49,11 +49,11 @@ public class OpPlus extends Operator {
|
||||
Object operandOne = leftOp.getValueInternal(state).getValue();
|
||||
if (operandOne instanceof Number) {
|
||||
if (operandOne instanceof Double) {
|
||||
return new TypedValue(((Double) operandOne).doubleValue(), DOUBLE_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(((Double) operandOne).doubleValue());
|
||||
} else if (operandOne instanceof Long) {
|
||||
return new TypedValue(((Long) operandOne).longValue(), LONG_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(((Long) operandOne).longValue());
|
||||
} else {
|
||||
return new TypedValue(((Integer) operandOne).intValue(), INTEGER_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(((Integer) operandOne).intValue());
|
||||
}
|
||||
}
|
||||
return state.operate(Operation.ADD, operandOne, null);
|
||||
@@ -65,22 +65,22 @@ public class OpPlus extends Operator {
|
||||
Number op1 = (Number) operandOne;
|
||||
Number op2 = (Number) operandTwo;
|
||||
if (op1 instanceof Double || op2 instanceof Double) {
|
||||
return new TypedValue(op1.doubleValue() + op2.doubleValue(),DOUBLE_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.doubleValue() + op2.doubleValue());
|
||||
} else if (op1 instanceof Long || op2 instanceof Long) {
|
||||
return new TypedValue(op1.longValue() + op2.longValue(),LONG_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.longValue() + op2.longValue());
|
||||
} else { // TODO what about overflow?
|
||||
return new TypedValue(op1.intValue() + op2.intValue(),INTEGER_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(op1.intValue() + op2.intValue());
|
||||
}
|
||||
} else if (operandOne instanceof String && operandTwo instanceof String) {
|
||||
return new TypedValue(new StringBuilder((String) operandOne).append((String) operandTwo).toString(),STRING_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(new StringBuilder((String) operandOne).append((String) operandTwo).toString());
|
||||
} else if (operandOne instanceof String) {
|
||||
StringBuilder result = new StringBuilder((String)operandOne);
|
||||
result.append((operandTwo==null?"null":operandTwo.toString()));
|
||||
return new TypedValue(result.toString(),STRING_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(result.toString());
|
||||
} else if (operandTwo instanceof String) {
|
||||
StringBuilder result = new StringBuilder((operandOne==null?"null":operandOne.toString()));
|
||||
result.append((String)operandTwo);
|
||||
return new TypedValue(result.toString(),STRING_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(result.toString());
|
||||
}
|
||||
return state.operate(Operation.ADD, operandOne, operandTwo);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.expression.spel.ast;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.ExpressionState;
|
||||
@@ -43,7 +44,7 @@ public class OperatorNot extends SpelNodeImpl { // Not is a unary operator so do
|
||||
if (TypedValue.NULL_TYPED_VALUE.equals(typedValue)) {
|
||||
throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean");
|
||||
}
|
||||
boolean value = (Boolean) state.convertValue(typedValue, BOOLEAN_TYPE_DESCRIPTOR);
|
||||
boolean value = (Boolean) state.convertValue(typedValue, TypeDescriptor.valueOf(Boolean.class));
|
||||
return BooleanTypedValue.forValue(!value);
|
||||
}
|
||||
catch (SpelEvaluationException see) {
|
||||
|
||||
@@ -44,16 +44,16 @@ public class OperatorPower extends Operator {
|
||||
Number op1 = (Number) operandOne;
|
||||
Number op2 = (Number) operandTwo;
|
||||
if (op1 instanceof Double || op2 instanceof Double) {
|
||||
return new TypedValue(Math.pow(op1.doubleValue(),op2.doubleValue()),DOUBLE_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(Math.pow(op1.doubleValue(),op2.doubleValue()));
|
||||
} else if (op1 instanceof Long || op2 instanceof Long) {
|
||||
double d= Math.pow(op1.longValue(), op2.longValue());
|
||||
return new TypedValue((long)d, LONG_TYPE_DESCRIPTOR);
|
||||
return new TypedValue((long)d);
|
||||
} else {
|
||||
double d= Math.pow(op1.longValue(), op2.longValue());
|
||||
if (d > Integer.MAX_VALUE) {
|
||||
return new TypedValue((long)d,LONG_TYPE_DESCRIPTOR);
|
||||
return new TypedValue((long)d);
|
||||
} else {
|
||||
return new TypedValue((int)d,INTEGER_TYPE_DESCRIPTOR);
|
||||
return new TypedValue((int)d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class QualifiedIdentifier extends SpelNodeImpl {
|
||||
}
|
||||
sb.append(value);
|
||||
}
|
||||
this.value = new TypedValue(sb.toString(),STRING_TYPE_DESCRIPTOR);
|
||||
this.value = new TypedValue(sb.toString());
|
||||
}
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class RealLiteral extends Literal {
|
||||
|
||||
public RealLiteral(String payload, int pos, double value) {
|
||||
super(payload, pos);
|
||||
this.value = new TypedValue(value,DOUBLE_TYPE_DESCRIPTOR);
|
||||
this.value = new TypedValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.expression.spel.ast;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.common.ExpressionUtils;
|
||||
@@ -35,18 +34,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class SpelNodeImpl implements SpelNode {
|
||||
|
||||
static TypeDescriptor OBJECT_TYPE_DESCRIPTOR = TypeDescriptor.OBJECT;
|
||||
static TypeDescriptor STRING_TYPE_DESCRIPTOR = TypeDescriptor.STRING;
|
||||
static TypeDescriptor CLASS_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Class.class);
|
||||
static TypeDescriptor BOOLEAN_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Boolean.class);
|
||||
static TypeDescriptor CHARACTER_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Character.class);
|
||||
static TypeDescriptor BYTE_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Byte.class);
|
||||
static TypeDescriptor SHORT_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Short.class);
|
||||
static TypeDescriptor INTEGER_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Integer.class);
|
||||
static TypeDescriptor LONG_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Long.class);
|
||||
static TypeDescriptor FLOAT_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Float.class);
|
||||
static TypeDescriptor DOUBLE_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(Double.class);
|
||||
|
||||
private static SpelNodeImpl[] NO_CHILDREN = new SpelNodeImpl[0];
|
||||
|
||||
protected int pos; // start = top 16bits, end = bottom 16bits
|
||||
|
||||
@@ -31,7 +31,7 @@ public class StringLiteral extends Literal {
|
||||
super(payload,pos);
|
||||
// TODO should these have been skipped being created by the parser rules? or not?
|
||||
value = value.substring(1, value.length() - 1);
|
||||
this.value = new TypedValue(value.replaceAll("''", "'"),STRING_TYPE_DESCRIPTOR);
|
||||
this.value = new TypedValue(value.replaceAll("''", "'"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,10 +39,10 @@ public class TypeReference extends SpelNodeImpl {
|
||||
TypeCode tc = TypeCode.valueOf(typename.toUpperCase());
|
||||
if (tc != TypeCode.OBJECT) {
|
||||
// it is a primitive type
|
||||
return new TypedValue(tc.getType(),CLASS_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(tc.getType());
|
||||
}
|
||||
}
|
||||
return new TypedValue(state.findType(typename),CLASS_TYPE_DESCRIPTOR);
|
||||
return new TypedValue(state.findType(typename));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -257,10 +257,10 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testTypeConversion() throws EvaluationException {
|
||||
ExpressionState state = getState();
|
||||
String s = (String)state.convertValue(34,TypeDescriptor.STRING);
|
||||
String s = (String)state.convertValue(34, TypeDescriptor.valueOf(String.class));
|
||||
Assert.assertEquals("34",s);
|
||||
|
||||
s = (String)state.convertValue(new TypedValue(34),TypeDescriptor.STRING);
|
||||
s = (String)state.convertValue(new TypedValue(34), TypeDescriptor.valueOf(String.class));
|
||||
Assert.assertEquals("34",s);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.expression.PropertyAccessor;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
|
||||
/**
|
||||
* Testing variations on map access.
|
||||
@@ -78,7 +77,7 @@ public class MapAccessTests extends ExpressionTestCase {
|
||||
}
|
||||
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
return new TypedValue(((Map) target).get(name), TypeDescriptor.OBJECT);
|
||||
return new TypedValue(((Map) target).get(name));
|
||||
}
|
||||
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
@@ -26,8 +26,8 @@ import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.PropertyAccessor;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
///CLOVER:OFF
|
||||
@@ -155,7 +155,7 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
if (!name.equals("flibbles"))
|
||||
throw new RuntimeException("Assertion Failed! name should be flibbles");
|
||||
return new TypedValue(flibbles, TypeDescriptor.STRING);
|
||||
return new TypedValue(flibbles, TypeDescriptor.valueOf(String.class));
|
||||
}
|
||||
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue)
|
||||
|
||||
@@ -21,9 +21,8 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
@@ -219,7 +218,7 @@ public class SpringEL300Tests extends ExpressionTestCase {
|
||||
}
|
||||
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
return new TypedValue(((Map) target).get(name), TypeDescriptor.OBJECT);
|
||||
return new TypedValue(((Map) target).get(name));
|
||||
}
|
||||
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
|
||||
Reference in New Issue
Block a user