Remove trailing whitespace in source files
find . -type f -name "*.java" -or -name "*.aj" | \
xargs perl -p -i -e "s/[ \t]*$//g" {} \;
Issue: SPR-10127
This commit is contained in:
committed by
Chris Beams
parent
44a474a014
commit
1762157ad1
@@ -18,7 +18,7 @@ package org.springframework.expression;
|
||||
|
||||
/**
|
||||
* An AccessException is thrown by an accessor if it has an unexpected problem.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -35,4 +35,3 @@ public interface BeanResolver {
|
||||
Object resolve(EvaluationContext context, String beanName) throws AccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ package org.springframework.expression;
|
||||
* back to the resolvers. For example, the particular constructor to run on a class may be discovered by the reflection
|
||||
* constructor resolver - it will then build a ConstructorExecutor that executes that constructor and the
|
||||
* ConstructorExecutor can be reused without needing to go back to the resolver to discover the constructor again.
|
||||
*
|
||||
*
|
||||
* They can become stale, and in that case should throw an AccessException - this will cause the infrastructure to go
|
||||
* back to the resolvers to ask for a new one.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.expression;
|
||||
|
||||
/**
|
||||
* Represent an exception that occurs during expression evaluation.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -28,7 +28,7 @@ public class EvaluationException extends ExpressionException {
|
||||
* Creates a new expression evaluation exception.
|
||||
* @param position the position in the expression where the problem occurred
|
||||
* @param message description of the problem that occurred
|
||||
*/
|
||||
*/
|
||||
public EvaluationException(int position, String message) {
|
||||
super(position, message);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class EvaluationException extends ExpressionException {
|
||||
* Creates a new expression evaluation exception.
|
||||
* @param expressionString the expression that could not be evaluated
|
||||
* @param message description of the problem that occurred
|
||||
*/
|
||||
*/
|
||||
public EvaluationException(String expressionString, String message) {
|
||||
super(expressionString, message);
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class EvaluationException extends ExpressionException {
|
||||
* @param position the position in the expression where the problem occurred
|
||||
* @param message description of the problem that occurred
|
||||
* @param cause the underlying cause of this exception
|
||||
*/
|
||||
*/
|
||||
public EvaluationException(int position, String message, Throwable cause) {
|
||||
super(position, message, cause);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class EvaluationException extends ExpressionException {
|
||||
/**
|
||||
* Creates a new expression evaluation exception.
|
||||
* @param message description of the problem that occurred
|
||||
*/
|
||||
*/
|
||||
public EvaluationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@@ -37,14 +37,14 @@ public interface Expression {
|
||||
*/
|
||||
Object getValue() throws EvaluationException;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Evaluate this expression against the specified root object
|
||||
* @param rootObject the root object against which properties/etc will be resolved
|
||||
* @return the evaluation result
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
Object getValue(Object rootObject) throws EvaluationException;
|
||||
|
||||
|
||||
/**
|
||||
* Evaluate the expression in the default context. If the result of the evaluation does not match (and
|
||||
* cannot be converted to) the expected result type then an exception will be returned.
|
||||
@@ -53,10 +53,10 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
<T> T getValue(Class<T> desiredResultType) throws EvaluationException;
|
||||
|
||||
|
||||
/**
|
||||
* Evaluate the expression in the default context against the specified root object. If the
|
||||
* result of the evaluation does not match (and cannot be converted to) the expected result type
|
||||
* Evaluate the expression in the default context against the specified root object. If the
|
||||
* result of the evaluation does not match (and cannot be converted to) the expected result type
|
||||
* then an exception will be returned.
|
||||
* @param rootObject the root object against which properties/etc will be resolved
|
||||
* @param desiredResultType the class the caller would like the result to be
|
||||
@@ -82,7 +82,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
Object getValue(EvaluationContext context, Object rootObject) throws EvaluationException;
|
||||
|
||||
|
||||
/**
|
||||
* Evaluate the expression in a specified context which can resolve references to properties, methods, types, etc -
|
||||
* the type of the evaluation result is expected to be of a particular class and an exception will be thrown if it
|
||||
@@ -132,7 +132,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem determining the type
|
||||
*/
|
||||
Class getValueType(EvaluationContext context) throws EvaluationException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the most general type that can be passed to the {@link #setValue(EvaluationContext, Object)}
|
||||
* method for the given context. The supplied root object overrides any specified in the context.
|
||||
@@ -150,7 +150,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem determining the type
|
||||
*/
|
||||
TypeDescriptor getValueTypeDescriptor() throws EvaluationException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the most general type that can be passed to the {@link #setValue(EvaluationContext, Object)}
|
||||
* method using the default context.
|
||||
@@ -207,13 +207,13 @@ public interface Expression {
|
||||
|
||||
/**
|
||||
* Set this expression in the provided context to the value provided.
|
||||
*
|
||||
*
|
||||
* @param context the context in which to set the value of the expression
|
||||
* @param value the new value
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
void setValue(EvaluationContext context, Object value) throws EvaluationException;
|
||||
|
||||
|
||||
/**
|
||||
* Set this expression in the provided context to the value provided.
|
||||
* @param rootObject the root object against which to evaluate the expression
|
||||
@@ -231,7 +231,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the original string used to create this expression, unmodified.
|
||||
* @return the original expression string
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ExpressionException extends RuntimeException {
|
||||
this.position = -1;
|
||||
this.expressionString = expressionString;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new expression exception.
|
||||
* @param expressionString the expression string
|
||||
@@ -66,7 +66,7 @@ public class ExpressionException extends RuntimeException {
|
||||
* @param position the position in the expression string where the problem occurred
|
||||
* @param message a descriptive message
|
||||
* @param cause the underlying cause of this exception
|
||||
*/
|
||||
*/
|
||||
public ExpressionException(int position, String message, Throwable cause) {
|
||||
super(message,cause);
|
||||
this.position = position;
|
||||
@@ -75,7 +75,7 @@ public class ExpressionException extends RuntimeException {
|
||||
/**
|
||||
* Creates a new expression exception.
|
||||
* @param message a descriptive message
|
||||
*/
|
||||
*/
|
||||
public ExpressionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
@@ -99,11 +99,11 @@ public class ExpressionException extends RuntimeException {
|
||||
output.append(getMessage());
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
|
||||
public final String getExpressionString() {
|
||||
return this.expressionString;
|
||||
}
|
||||
|
||||
|
||||
public final int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.springframework.expression;
|
||||
* It differs from a SpelEvaluationException because this indicates the occurrence of a checked exception
|
||||
* that the invoked method was defined to throw. SpelEvaluationExceptions are for handling (and wrapping)
|
||||
* unexpected exceptions.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0.3
|
||||
*/
|
||||
|
||||
@@ -21,26 +21,26 @@ import java.util.List;
|
||||
/**
|
||||
* MethodFilter instances allow SpEL users to fine tune the behaviour of the method resolution
|
||||
* process. Method resolution (which translates from a method name in an expression to a real
|
||||
* method to invoke) will normally retrieve candidate methods for invocation via a simple call
|
||||
* to 'Class.getMethods()' and will choose the first one that is suitable for the
|
||||
* input parameters. By registering a MethodFilter the user can receive a callback
|
||||
* method to invoke) will normally retrieve candidate methods for invocation via a simple call
|
||||
* to 'Class.getMethods()' and will choose the first one that is suitable for the
|
||||
* input parameters. By registering a MethodFilter the user can receive a callback
|
||||
* and change the methods that will be considered suitable.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public interface MethodFilter {
|
||||
|
||||
/**
|
||||
* Called by the method resolver to allow the SpEL user to organize the list of candidate
|
||||
* methods that may be invoked. The filter can remove methods that should not be
|
||||
* considered candidates and it may sort the results. The resolver will then search
|
||||
* through the methods as returned from the filter when looking for a suitable
|
||||
* Called by the method resolver to allow the SpEL user to organize the list of candidate
|
||||
* methods that may be invoked. The filter can remove methods that should not be
|
||||
* considered candidates and it may sort the results. The resolver will then search
|
||||
* through the methods as returned from the filter when looking for a suitable
|
||||
* candidate to invoke.
|
||||
*
|
||||
*
|
||||
* @param methods the full list of methods the resolver was going to choose from
|
||||
* @return a possible subset of input methods that may be sorted by order of relevance
|
||||
*/
|
||||
List<Method> filter(List<Method> methods);
|
||||
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.springframework.expression;
|
||||
|
||||
/**
|
||||
* Supported operations that an {@link OperatorOverloader} can implement for any pair of operands.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.expression;
|
||||
/**
|
||||
* By default the mathematical operators {@link Operation} support simple types like numbers. By providing an
|
||||
* implementation of OperatorOverloader, a user of the expression language can support these operations on other types.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ParseException extends ExpressionException {
|
||||
* @param expressionString the expression string that could not be parsed
|
||||
* @param position the position in the expression string where the problem occurred
|
||||
* @param message description of the problem that occurred
|
||||
*/
|
||||
*/
|
||||
public ParseException(String expressionString, int position, String message) {
|
||||
super(expressionString, position, message);
|
||||
}
|
||||
@@ -39,16 +39,16 @@ public class ParseException extends ExpressionException {
|
||||
* @param position the position in the expression string where the problem occurred
|
||||
* @param message description of the problem that occurred
|
||||
* @param cause the underlying cause of this exception
|
||||
*/
|
||||
*/
|
||||
public ParseException(int position, String message, Throwable cause) {
|
||||
super(position, message, cause);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new expression parsing exception.
|
||||
* @param position the position in the expression string where the problem occurred
|
||||
* @param message description of the problem that occurred
|
||||
*/
|
||||
*/
|
||||
public ParseException(int position, String message) {
|
||||
super(position, message);
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ public interface ParserContext {
|
||||
/**
|
||||
* Whether or not the expression being parsed is a template. A template expression consists of literal text that can
|
||||
* be mixed with evaluatable blocks. Some examples:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* Some literal text
|
||||
* Hello #{name.firstName}!
|
||||
* #{3 + 4}
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @return true if the expression is a template, false otherwise
|
||||
*/
|
||||
boolean isTemplate();
|
||||
@@ -54,7 +54,7 @@ public interface ParserContext {
|
||||
* @return the suffix that identifies the end of an expression
|
||||
*/
|
||||
String getExpressionSuffix();
|
||||
|
||||
|
||||
/**
|
||||
* The default ParserContext implementation that enables template expression parsing mode.
|
||||
* The expression prefix is #{ and the expression suffix is }.
|
||||
@@ -73,7 +73,7 @@ public interface ParserContext {
|
||||
public boolean isTemplate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ package org.springframework.expression;
|
||||
* to determine if it can read or write them. Property resolvers are considered to be ordered and each will be called in
|
||||
* turn. The only rule that affects the call order is that any naming the target class directly in
|
||||
* getSpecifiedTargetClasses() will be called first, before the general resolvers.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.expression;
|
||||
/**
|
||||
* Instances of a type comparator should be able to compare pairs of objects for equality, the specification of the
|
||||
* return value is the same as for {@link Comparable}.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -56,12 +56,12 @@ public class TypedValue {
|
||||
this.value = value;
|
||||
this.typeDescriptor = typeDescriptor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
|
||||
public TypeDescriptor getTypeDescriptor() {
|
||||
if (this.typeDescriptor == null) {
|
||||
this.typeDescriptor = TypeDescriptor.forObject(this.value);
|
||||
@@ -76,5 +76,5 @@ public class TypedValue {
|
||||
str.append("TypedValue: '").append(this.value).append("' of [").append(getTypeDescriptor() + "]");
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.expression.Expression;
|
||||
* which will be represented as a CompositeStringExpression of two parts. The first part being a
|
||||
* LiteralExpression representing 'Hello ' and the second part being a real expression that will
|
||||
* call <code>getName()</code> when invoked.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
@@ -60,7 +60,7 @@ public class CompositeStringExpression implements Expression {
|
||||
String value = expression.getValue(String.class);
|
||||
if (value != null) {
|
||||
sb.append(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class CompositeStringExpression implements Expression {
|
||||
String value = expression.getValue(rootObject, String.class);
|
||||
if (value != null) {
|
||||
sb.append(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class CompositeStringExpression implements Expression {
|
||||
String value = expression.getValue(context, rootObject, String.class);
|
||||
if (value != null) {
|
||||
sb.append(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public class CompositeStringExpression implements Expression {
|
||||
public boolean isWritable(EvaluationContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public Expression[] getExpressions() {
|
||||
return expressions;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class LiteralExpression implements Expression {
|
||||
public String getValue(EvaluationContext context) {
|
||||
return this.literalValue;
|
||||
}
|
||||
|
||||
|
||||
public String getValue(Object rootObject) {
|
||||
return this.literalValue;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TemplateParserContext implements ParserContext {
|
||||
public TemplateParserContext() {
|
||||
this("#{", "}");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new TemplateParserContext for the given prefix and suffix.
|
||||
* @param expressionPrefix the expression prefix to use
|
||||
|
||||
@@ -36,22 +36,22 @@ import org.springframework.expression.TypedValue;
|
||||
* expressions but it gives a place to hold local variables and for component expressions in a compound expression to
|
||||
* communicate state. This is in contrast to the EvaluationContext, which is shared amongst expression evaluations, and
|
||||
* any changes to it will be seen by other expressions or any code that chooses to ask questions of the context.
|
||||
*
|
||||
*
|
||||
* <p>It also acts as a place for to define common utility routines that the various Ast nodes might need.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ExpressionState {
|
||||
|
||||
private final EvaluationContext relatedContext;
|
||||
|
||||
private Stack<VariableScope> variableScopes;
|
||||
|
||||
private Stack<VariableScope> variableScopes;
|
||||
|
||||
private Stack<TypedValue> contextObjects;
|
||||
|
||||
|
||||
private final TypedValue rootObject;
|
||||
|
||||
|
||||
private SpelParserConfiguration configuration;
|
||||
|
||||
|
||||
@@ -59,30 +59,30 @@ public class ExpressionState {
|
||||
this.relatedContext = context;
|
||||
this.rootObject = context.getRootObject();
|
||||
}
|
||||
|
||||
|
||||
public ExpressionState(EvaluationContext context, SpelParserConfiguration configuration) {
|
||||
this.relatedContext = context;
|
||||
this.configuration = configuration;
|
||||
this.rootObject = context.getRootObject();
|
||||
}
|
||||
|
||||
|
||||
public ExpressionState(EvaluationContext context, TypedValue rootObject) {
|
||||
this.relatedContext = context;
|
||||
this.rootObject = rootObject;
|
||||
}
|
||||
|
||||
|
||||
public ExpressionState(EvaluationContext context, TypedValue rootObject, SpelParserConfiguration configuration) {
|
||||
this.relatedContext = context;
|
||||
this.configuration = configuration;
|
||||
this.rootObject = rootObject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void ensureVariableScopesInitialized() {
|
||||
if (this.variableScopes == null) {
|
||||
this.variableScopes = new Stack<VariableScope>();
|
||||
// top level empty variable scope
|
||||
this.variableScopes.add(new VariableScope());
|
||||
this.variableScopes.add(new VariableScope());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ExpressionState {
|
||||
if (this.contextObjects==null || this.contextObjects.isEmpty()) {
|
||||
return this.rootObject;
|
||||
}
|
||||
|
||||
|
||||
return this.contextObjects.peek();
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public class ExpressionState {
|
||||
public Object convertValue(Object value, TypeDescriptor targetTypeDescriptor) throws EvaluationException {
|
||||
return this.relatedContext.getTypeConverter().convertValue(value, TypeDescriptor.forObject(value), targetTypeDescriptor);
|
||||
}
|
||||
|
||||
|
||||
public TypeConverter getTypeConverter() {
|
||||
return this.relatedContext.getTypeConverter();
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class ExpressionState {
|
||||
/*
|
||||
* A new scope is entered when a function is invoked
|
||||
*/
|
||||
|
||||
|
||||
public void enterScope(Map<String, Object> argMap) {
|
||||
ensureVariableScopesInitialized();
|
||||
this.variableScopes.push(new VariableScope(argMap));
|
||||
@@ -226,7 +226,7 @@ public class ExpressionState {
|
||||
this.vars.putAll(arguments);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public VariableScope(String name, Object value) {
|
||||
this.vars.put(name,value);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.expression.spel.SpelParseException;
|
||||
/**
|
||||
* Wraps a real parse exception. This exception flows to the top parse method and then
|
||||
* the wrapped exception is thrown as the real problem.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -30,9 +30,9 @@ public class InternalParseException extends RuntimeException {
|
||||
public InternalParseException(SpelParseException cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
|
||||
public SpelParseException getCause() {
|
||||
return (SpelParseException) super.getCause();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.expression.EvaluationException;
|
||||
* Root exception for Spring EL related exceptions. Rather than holding a hard coded string indicating the problem, it
|
||||
* records a message key and the inserts for the message. See {@link SpelMessage} for the list of all possible messages
|
||||
* that can occur.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -37,7 +37,7 @@ public class SpelEvaluationException extends EvaluationException {
|
||||
}
|
||||
|
||||
public SpelEvaluationException(int position, SpelMessage message, Object... inserts) {
|
||||
super(position, message.formatMessage(position, inserts));
|
||||
super(position, message.formatMessage(position, inserts));
|
||||
this.message = message;
|
||||
this.inserts = inserts;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class SpelEvaluationException extends EvaluationException {
|
||||
|
||||
/**
|
||||
* Set the position in the related expression which gave rise to this exception.
|
||||
*
|
||||
*
|
||||
* @param position the position in the expression that gave rise to the exception
|
||||
*/
|
||||
public void setPosition(int position) {
|
||||
|
||||
@@ -24,13 +24,13 @@ import java.text.MessageFormat;
|
||||
* enabling the message text to more easily be modified and the tests to run successfully in different locales.
|
||||
* <p>
|
||||
* When a message is formatted, it will have this kind of form
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* EL1004E: (pos 34): Type cannot be found 'String'
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* </code> The prefix captures the code and the error kind, whilst the position is included if it is known.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ public enum SpelMessage {
|
||||
TYPE_CONVERSION_ERROR(Kind.ERROR, 1001, "Type conversion problem, cannot convert from {0} to {1}"), //
|
||||
CONSTRUCTOR_NOT_FOUND(Kind.ERROR, 1002, "Constructor call: No suitable constructor found on type {0} for arguments {1}"), //
|
||||
CONSTRUCTOR_INVOCATION_PROBLEM(Kind.ERROR, 1003, "A problem occurred whilst attempting to construct an object of type ''{0}'' using arguments ''{1}''"), //
|
||||
METHOD_NOT_FOUND(Kind.ERROR, 1004, "Method call: Method {0} cannot be found on {1} type"), //
|
||||
METHOD_NOT_FOUND(Kind.ERROR, 1004, "Method call: Method {0} cannot be found on {1} type"), //
|
||||
TYPE_NOT_FOUND(Kind.ERROR, 1005, "Type cannot be found ''{0}''"), //
|
||||
FUNCTION_NOT_DEFINED(Kind.ERROR, 1006, "The function ''{0}'' could not be found"), //
|
||||
PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL(Kind.ERROR, 1007, "Field or property ''{0}'' cannot be found on null"), //
|
||||
@@ -47,7 +47,7 @@ public enum SpelMessage {
|
||||
PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL(Kind.ERROR, 1009, "Field or property ''{0}'' cannot be set on null"), //
|
||||
PROPERTY_OR_FIELD_NOT_WRITABLE(Kind.ERROR, 1010, "Field or property ''{0}'' cannot be set on object of type ''{1}''"), //
|
||||
METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED(Kind.ERROR, 1011, "Method call: Attempted to call method {0} on null context object"), //
|
||||
CANNOT_INDEX_INTO_NULL_VALUE(Kind.ERROR, 1012, "Cannot index into a null value"),
|
||||
CANNOT_INDEX_INTO_NULL_VALUE(Kind.ERROR, 1012, "Cannot index into a null value"),
|
||||
NOT_COMPARABLE(Kind.ERROR, 1013, "Cannot compare instances of {0} and {1}"), //
|
||||
INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION(Kind.ERROR, 1014, "Incorrect number of arguments for function, {0} supplied but function takes {1}"), //
|
||||
INVALID_TYPE_FOR_SELECTION(Kind.ERROR, 1015, "Cannot perform selection on input data of type ''{0}''"), //
|
||||
@@ -60,22 +60,22 @@ public enum SpelMessage {
|
||||
FUNCTION_REFERENCE_CANNOT_BE_INVOKED(Kind.ERROR, 1022, "The function ''{0}'' mapped to an object of type ''{1}'' which cannot be invoked"), //
|
||||
EXCEPTION_DURING_FUNCTION_CALL(Kind.ERROR, 1023, "A problem occurred whilst attempting to invoke the function ''{0}'': ''{1}''"), //
|
||||
ARRAY_INDEX_OUT_OF_BOUNDS(Kind.ERROR, 1024, "The array has ''{0}'' elements, index ''{1}'' is invalid"), //
|
||||
COLLECTION_INDEX_OUT_OF_BOUNDS(Kind.ERROR, 1025, "The collection has ''{0}'' elements, index ''{1}'' is invalid"), //
|
||||
COLLECTION_INDEX_OUT_OF_BOUNDS(Kind.ERROR, 1025, "The collection has ''{0}'' elements, index ''{1}'' is invalid"), //
|
||||
STRING_INDEX_OUT_OF_BOUNDS(Kind.ERROR, 1026, "The string has ''{0}'' characters, index ''{1}'' is invalid"), //
|
||||
INDEXING_NOT_SUPPORTED_FOR_TYPE(Kind.ERROR, 1027, "Indexing into type ''{0}'' is not supported"), //
|
||||
INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND(Kind.ERROR, 1028, "The operator 'instanceof' needs the right operand to be a class, not a ''{0}''"), //
|
||||
EXCEPTION_DURING_METHOD_INVOCATION(Kind.ERROR, 1029, "A problem occurred when trying to execute method ''{0}'' on object of type ''{1}'': ''{2}''"), //
|
||||
EXCEPTION_DURING_METHOD_INVOCATION(Kind.ERROR, 1029, "A problem occurred when trying to execute method ''{0}'' on object of type ''{1}'': ''{2}''"), //
|
||||
OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES(Kind.ERROR, 1030, "The operator ''{0}'' is not supported between objects of type ''{1}'' and ''{2}''"), //
|
||||
PROBLEM_LOCATING_METHOD(Kind.ERROR, 1031, "Problem locating method {0} cannot on type {1}"),
|
||||
PROBLEM_LOCATING_METHOD(Kind.ERROR, 1031, "Problem locating method {0} cannot on type {1}"),
|
||||
SETVALUE_NOT_SUPPORTED( Kind.ERROR, 1032, "setValue(ExpressionState, Object) not supported for ''{0}''"), //
|
||||
MULTIPLE_POSSIBLE_METHODS(Kind.ERROR, 1033, "Method call of ''{0}'' is ambiguous, supported type conversions allow multiple variants to match"), //
|
||||
EXCEPTION_DURING_PROPERTY_WRITE(Kind.ERROR, 1034, "A problem occurred whilst attempting to set the property ''{0}'': {1}"), //
|
||||
NOT_AN_INTEGER(Kind.ERROR, 1035, "The value ''{0}'' cannot be parsed as an int"), //
|
||||
NOT_A_LONG(Kind.ERROR, 1036, "The value ''{0}'' cannot be parsed as a long"), //
|
||||
NOT_A_LONG(Kind.ERROR, 1036, "The value ''{0}'' cannot be parsed as a long"), //
|
||||
INVALID_FIRST_OPERAND_FOR_MATCHES_OPERATOR(Kind.ERROR, 1037, "First operand to matches operator must be a string. ''{0}'' is not"), //
|
||||
INVALID_SECOND_OPERAND_FOR_MATCHES_OPERATOR(Kind.ERROR, 1038, "Second operand to matches operator must be a string. ''{0}'' is not"), //
|
||||
FUNCTION_MUST_BE_STATIC(Kind.ERROR, 1039, "Only static methods can be called via function references. The method ''{0}'' referred to by name ''{1}'' is not static."),//
|
||||
NOT_A_REAL(Kind.ERROR, 1040, "The value ''{0}'' cannot be parsed as a double"), //
|
||||
NOT_A_REAL(Kind.ERROR, 1040, "The value ''{0}'' cannot be parsed as a double"), //
|
||||
MORE_INPUT(Kind.ERROR,1041, "After parsing a valid expression, there is still more data in the expression: ''{0}''"),
|
||||
RIGHT_OPERAND_PROBLEM(Kind.ERROR,1042, "Problem parsing right operand"),
|
||||
NOT_EXPECTED_TOKEN(Kind.ERROR,1043,"Unexpected token. Expected ''{0}'' but was ''{1}''"),
|
||||
@@ -93,7 +93,7 @@ public enum SpelMessage {
|
||||
UNABLE_TO_CREATE_MAP_FOR_INDEXING(Kind.ERROR,1055,"Unable to dynamically create a Map to replace a null value"),//
|
||||
UNABLE_TO_DYNAMICALLY_CREATE_OBJECT(Kind.ERROR,1056,"Unable to dynamically create instance of ''{0}'' to replace a null value"),//
|
||||
NO_BEAN_RESOLVER_REGISTERED(Kind.ERROR,1057,"No bean resolver registered in the context to resolve access to bean ''{0}''"),//
|
||||
EXCEPTION_DURING_BEAN_RESOLUTION(Kind.ERROR, 1058, "A problem occurred when trying to resolve bean ''{0}'':''{1}''"), //
|
||||
EXCEPTION_DURING_BEAN_RESOLUTION(Kind.ERROR, 1058, "A problem occurred when trying to resolve bean ''{0}'':''{1}''"), //
|
||||
INVALID_BEAN_REFERENCE(Kind.ERROR,1059,"@ can only be followed by an identifier or a quoted name"),//
|
||||
TYPE_NAME_EXPECTED_FOR_ARRAY_CONSTRUCTION(Kind.ERROR, 1060,
|
||||
"Expected the type of the new array to be specified as a String but found ''{0}''"), //
|
||||
@@ -125,7 +125,7 @@ public enum SpelMessage {
|
||||
/**
|
||||
* Produce a complete message including the prefix, the position (if known) and with the inserts applied to the
|
||||
* message.
|
||||
*
|
||||
*
|
||||
* @param pos the position, if less than zero it is ignored and not included in the message
|
||||
* @param inserts the inserts to put into the formatted message
|
||||
* @return a formatted message
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.expression.ParseException;
|
||||
* Root exception for Spring EL related exceptions. Rather than holding a hard coded string indicating the problem, it
|
||||
* records a message key and the inserts for the message. See {@link SpelMessage} for the list of all possible messages
|
||||
* that can occur.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -41,7 +41,7 @@ public class SpelParseException extends ParseException {
|
||||
super(expressionString, position, message.formatMessage(position,inserts));
|
||||
this.position = position;
|
||||
this.message = message;
|
||||
this.inserts = inserts;
|
||||
this.inserts = inserts;
|
||||
}
|
||||
|
||||
public SpelParseException(int position, SpelMessage message, Object... inserts) {
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.expression.spel.ExpressionState;
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public class AstUtils {
|
||||
|
||||
|
||||
/**
|
||||
* Determines the set of property resolvers that should be used to try and access a property on the specified target
|
||||
* type. The resolvers are considered to be in an ordered list, however in the returned list any that are exact
|
||||
@@ -37,7 +37,7 @@ public class AstUtils {
|
||||
* the start of the list. In addition, there are specific resolvers that exactly name the class in question and
|
||||
* resolvers that name a specific class but it is a supertype of the class we have. These are put at the end of the
|
||||
* specific resolvers set and will be tried after exactly matching accessors but before generic accessors.
|
||||
*
|
||||
*
|
||||
* @param targetType the type upon which property access is being attempted
|
||||
* @return a list of resolvers that should be tried in order to access the property
|
||||
*/
|
||||
|
||||
@@ -26,13 +26,13 @@ import org.springframework.expression.spel.SpelMessage;
|
||||
|
||||
/**
|
||||
* Represents a bean reference to a type, for example "@foo" or "@'foo.bar'"
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class BeanReference extends SpelNodeImpl {
|
||||
|
||||
private String beanname;
|
||||
|
||||
|
||||
public BeanReference(int pos,String beanname) {
|
||||
super(pos);
|
||||
this.beanname = beanname;
|
||||
@@ -64,5 +64,5 @@ public class BeanReference extends SpelNodeImpl {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.expression.spel.SpelEvaluationException;
|
||||
|
||||
/**
|
||||
* Represents a DOT separated expression sequence, such as 'property1.property2.methodOne()'
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.springframework.expression.spel.SpelNode;
|
||||
* new String('hello world')<br>
|
||||
* new int[]{1,2,3,4}<br>
|
||||
* new int[3] new int[3]{1,2,3}
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
@@ -137,7 +137,7 @@ public class ConstructorReference extends SpelNodeImpl {
|
||||
throw new SpelEvaluationException(getStartPosition(), rootCause,
|
||||
SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typename, FormatHelper
|
||||
.formatMethodForMessage("", argumentTypes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// at this point we know it wasn't a user problem so worth a retry if a better candidate can be found
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.core.convert.TypeDescriptor;
|
||||
|
||||
/**
|
||||
* Utility methods (formatters, etc) used during parsing and evaluation.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class FormatHelper {
|
||||
@@ -46,7 +46,7 @@ public class FormatHelper {
|
||||
sb.append(formatClassNameForMessage(typeDescriptor.getType()));
|
||||
}
|
||||
else {
|
||||
sb.append(formatClassNameForMessage(null));
|
||||
sb.append(formatClassNameForMessage(null));
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
@@ -60,7 +60,7 @@ public class FormatHelper {
|
||||
* @return a formatted string suitable for message inclusion
|
||||
*/
|
||||
public static String formatClassNameForMessage(Class<?> clazz) {
|
||||
if (clazz == null) {
|
||||
if (clazz == null) {
|
||||
return "null";
|
||||
}
|
||||
StringBuilder fmtd = new StringBuilder();
|
||||
|
||||
@@ -74,7 +74,7 @@ public class FunctionReference extends SpelNodeImpl {
|
||||
|
||||
/**
|
||||
* Execute a function represented as a java.lang.reflect.Method.
|
||||
*
|
||||
*
|
||||
* @param state the expression evaluation state
|
||||
* @param the java method to invoke
|
||||
* @return the return value of the invoked Java method
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.expression.spel.SpelNode;
|
||||
|
||||
/**
|
||||
* Represent a list in an expression, e.g. '{1,2,3}'
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0.4
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@ public class IntLiteral extends Literal {
|
||||
private final TypedValue value;
|
||||
|
||||
IntLiteral(String payload, int pos, int value) {
|
||||
super(payload, pos);
|
||||
super(payload, pos);
|
||||
this.value = new TypedValue(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.springframework.expression.spel.*;
|
||||
|
||||
/**
|
||||
* Common superclass for nodes representing literals (boolean, string, number, etc).
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public abstract class Literal extends SpelNodeImpl {
|
||||
|
||||
protected String literalValue;
|
||||
|
||||
|
||||
public Literal(String payload, int pos) {
|
||||
super(pos);
|
||||
this.literalValue = payload;
|
||||
@@ -53,7 +53,7 @@ public abstract class Literal extends SpelNodeImpl {
|
||||
/**
|
||||
* Process the string form of a number, using the specified base if supplied and return an appropriate literal to
|
||||
* hold it. Any suffix to indicate a long will be taken into account (either 'l' or 'L' is supported).
|
||||
*
|
||||
*
|
||||
* @param numberToken the token holding the number as its payload (eg. 1234 or 0xCAFE)
|
||||
* @param radix the base of number
|
||||
* @return a subtype of Literal that can represent it
|
||||
@@ -84,7 +84,7 @@ public abstract class Literal extends SpelNodeImpl {
|
||||
return new FloatLiteral(numberToken, pos, value);
|
||||
} else {
|
||||
double value = Double.parseDouble(numberToken);
|
||||
return new RealLiteral(numberToken, pos, value);
|
||||
return new RealLiteral(numberToken, pos, value);
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new InternalParseException(new SpelParseException(pos>>16, nfe, SpelMessage.NOT_A_REAL, numberToken));
|
||||
|
||||
@@ -29,7 +29,7 @@ public class LongLiteral extends Literal {
|
||||
private final TypedValue value;
|
||||
|
||||
LongLiteral(String payload, int pos, long value) {
|
||||
super(payload, pos);
|
||||
super(payload, pos);
|
||||
this.value = new TypedValue(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class OpLT extends Operator {
|
||||
public OpLT(int pos, SpelNodeImpl... operands) {
|
||||
super("<", pos, operands);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
|
||||
Object left = getLeftOperand().getValueInternal(state).getValue();
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.expression.spel.ExpressionState;
|
||||
/**
|
||||
* Implements the {@code multiply} operator.
|
||||
*
|
||||
* <p>Conversions and promotions are handled as defined in
|
||||
* <p>Conversions and promotions are handled as defined in
|
||||
* <a href="http://java.sun.com/docs/books/jls/third_edition/html/conversions.html">Section 5.6.2
|
||||
* of the Java Language Specification</a>:
|
||||
*
|
||||
|
||||
@@ -27,12 +27,12 @@ package org.springframework.expression.spel.ast;
|
||||
public abstract class Operator extends SpelNodeImpl {
|
||||
|
||||
String operatorName;
|
||||
|
||||
|
||||
public Operator(String payload,int pos,SpelNodeImpl... operands) {
|
||||
super(pos, operands);
|
||||
this.operatorName = payload;
|
||||
}
|
||||
|
||||
|
||||
public SpelNodeImpl getLeftOperand() {
|
||||
return children[0];
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.expression.spel.support.BooleanTypedValue;
|
||||
* Represents the between operator. The left operand to between must be a single value and the right operand must be a
|
||||
* list - this operator returns true if the left operand is between (using the registered comparator) the two elements
|
||||
* in the list. The definition of between being inclusive follows the SQL BETWEEN definition.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.expression.spel.ExpressionState;
|
||||
|
||||
/**
|
||||
* The power operator.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -37,7 +37,7 @@ public class OperatorPower extends Operator {
|
||||
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
|
||||
SpelNodeImpl leftOp = getLeftOperand();
|
||||
SpelNodeImpl rightOp = getRightOperand();
|
||||
|
||||
|
||||
Object operandOne = leftOp.getValueInternal(state).getValue();
|
||||
Object operandTwo = rightOp.getValueInternal(state).getValue();
|
||||
if (operandOne instanceof Number && operandTwo instanceof Number) {
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Represents projection, where a given operation is performed on all elements in some input sequence, returning
|
||||
* Represents projection, where a given operation is performed on all elements in some input sequence, returning
|
||||
* a new sequence of the same size. For example:
|
||||
* "{1,2,3,4,5,6,7,8,9,10}.!{#isEven(#this)}" returns "[n, y, n, y, n, y, n, y, n, y]"
|
||||
*
|
||||
@@ -43,7 +43,7 @@ import org.springframework.util.ObjectUtils;
|
||||
public class Projection extends SpelNodeImpl {
|
||||
|
||||
private final boolean nullSafe;
|
||||
|
||||
|
||||
public Projection(boolean nullSafe, int pos, SpelNodeImpl expression) {
|
||||
super(pos, expression);
|
||||
this.nullSafe = nullSafe;
|
||||
@@ -61,7 +61,7 @@ public class Projection extends SpelNodeImpl {
|
||||
Object operand = op.getValue();
|
||||
boolean operandIsArray = ObjectUtils.isArray(operand);
|
||||
// TypeDescriptor operandTypeDescriptor = op.getTypeDescriptor();
|
||||
|
||||
|
||||
// When the input is a map, we push a special context object on the stack
|
||||
// before calling the specified operation. This special context object
|
||||
// has two fields 'key' and 'value' that refer to the map entries key
|
||||
|
||||
@@ -34,10 +34,10 @@ import org.springframework.expression.spel.support.ReflectivePropertyAccessor;
|
||||
|
||||
/**
|
||||
* Represents a simple property or field reference.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
* @author Clark Duplichien
|
||||
* @author Clark Duplichien
|
||||
* @since 3.0
|
||||
*/
|
||||
public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
@@ -119,7 +119,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
if ((resultDescriptor.getType().equals(List.class) || resultDescriptor.getType().equals(Map.class))) {
|
||||
// Create a new collection or map ready for the indexer
|
||||
if (resultDescriptor.getType().equals(List.class)) {
|
||||
try {
|
||||
try {
|
||||
if (isWritableProperty(this.name,contextObject,eContext)) {
|
||||
List<?> newList = ArrayList.class.newInstance();
|
||||
writeProperty(contextObject, eContext, this.name, newList);
|
||||
@@ -136,7 +136,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
try {
|
||||
if (isWritableProperty(this.name,contextObject,eContext)) {
|
||||
Map<?,?> newMap = HashMap.class.newInstance();
|
||||
writeProperty(contextObject, eContext, name, newMap);
|
||||
@@ -155,7 +155,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
}
|
||||
else {
|
||||
// 'simple' object
|
||||
try {
|
||||
try {
|
||||
if (isWritableProperty(this.name,contextObject,eContext)) {
|
||||
Object newObject = result.getTypeDescriptor().getType().newInstance();
|
||||
writeProperty(contextObject, eContext, name, newObject);
|
||||
@@ -169,7 +169,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
catch (IllegalAccessException ex) {
|
||||
throw new SpelEvaluationException(getStartPosition(), ex,
|
||||
SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -249,7 +249,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
}
|
||||
|
||||
private void writeProperty(TypedValue contextObject, EvaluationContext eContext, String name, Object newValue) throws SpelEvaluationException {
|
||||
|
||||
|
||||
if (contextObject.getValue() == null && nullSafe) {
|
||||
return;
|
||||
}
|
||||
@@ -339,7 +339,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
specificAccessors.add( resolver);
|
||||
break;
|
||||
}
|
||||
else if (clazz.isAssignableFrom(targetType)) {
|
||||
else if (clazz.isAssignableFrom(targetType)) {
|
||||
generalAccessors.add(resolver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class RealLiteral extends Literal {
|
||||
private final TypedValue value;
|
||||
|
||||
public RealLiteral(String payload, int pos, double value) {
|
||||
super(payload, pos);
|
||||
super(payload, pos);
|
||||
this.value = new TypedValue(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class Selection extends SpelNodeImpl {
|
||||
private final boolean nullSafe;
|
||||
|
||||
public Selection(boolean nullSafe, int variant,int pos,SpelNodeImpl expression) {
|
||||
super(pos,expression);
|
||||
super(pos,expression);
|
||||
this.nullSafe = nullSafe;
|
||||
this.variant = variant;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class Selection extends SpelNodeImpl {
|
||||
}
|
||||
} else {
|
||||
if (operand==null) {
|
||||
if (nullSafe) {
|
||||
if (nullSafe) {
|
||||
return ValueRef.NullValueRef.instance;
|
||||
} else {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INVALID_TYPE_FOR_SELECTION,
|
||||
@@ -162,7 +162,7 @@ public class Selection extends SpelNodeImpl {
|
||||
} else {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INVALID_TYPE_FOR_SELECTION,
|
||||
operand.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.expression.spel.ast;
|
||||
/**
|
||||
* Captures primitive types and their corresponding class objects, plus one special entry that represents all reference
|
||||
* (non-primitive) types.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public enum TypeCode {
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.expression.spel.SpelEvaluationException;
|
||||
|
||||
/**
|
||||
* Represents a variable reference, eg. #someVar. Note this is different to a *local* variable like $someVar
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
@@ -102,7 +102,7 @@ public class VariableReference extends SpelNodeImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toStringAST() {
|
||||
public String toStringAST() {
|
||||
return "#" + this.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,12 +34,12 @@ import org.springframework.util.Assert;
|
||||
* to be evaluated in a specified context. An expression can be evaluated
|
||||
* standalone or in a specified context. During expression evaluation the context
|
||||
* may be asked to resolve references to types, beans, properties, and methods.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
public class SpelExpression implements Expression {
|
||||
|
||||
|
||||
private final String expression;
|
||||
|
||||
private final SpelNodeImpl ast;
|
||||
@@ -61,7 +61,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
|
||||
// implementing Expression
|
||||
|
||||
|
||||
public Object getValue() throws EvaluationException {
|
||||
ExpressionState expressionState = new ExpressionState(getEvaluationContext(), configuration);
|
||||
return ast.getValue(expressionState);
|
||||
@@ -88,7 +88,7 @@ public class SpelExpression implements Expression {
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
return ast.getValue(new ExpressionState(context, configuration));
|
||||
}
|
||||
|
||||
|
||||
public Object getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
return ast.getValue(new ExpressionState(context, toTypedValue(rootObject), configuration));
|
||||
@@ -98,7 +98,7 @@ public class SpelExpression implements Expression {
|
||||
TypedValue typedResultValue = ast.getTypedValue(new ExpressionState(context, configuration));
|
||||
return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
|
||||
}
|
||||
|
||||
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> expectedResultType) throws EvaluationException {
|
||||
TypedValue typedResultValue = ast.getTypedValue(new ExpressionState(context, toTypedValue(rootObject), configuration));
|
||||
return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
|
||||
@@ -128,56 +128,56 @@ public class SpelExpression implements Expression {
|
||||
public TypeDescriptor getValueTypeDescriptor() throws EvaluationException {
|
||||
return getValueTypeDescriptor(getEvaluationContext());
|
||||
}
|
||||
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException {
|
||||
ExpressionState eState = new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), configuration);
|
||||
return ast.getValueInternal(eState).getTypeDescriptor();
|
||||
}
|
||||
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException {
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
ExpressionState eState = new ExpressionState(context, configuration);
|
||||
return ast.getValueInternal(eState).getTypeDescriptor();
|
||||
}
|
||||
|
||||
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
ExpressionState eState = new ExpressionState(context, toTypedValue(rootObject), configuration);
|
||||
return ast.getValueInternal(eState).getTypeDescriptor();
|
||||
}
|
||||
|
||||
|
||||
public String getExpressionString() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
public boolean isWritable(EvaluationContext context) throws EvaluationException {
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
return ast.isWritable(new ExpressionState(context, configuration));
|
||||
}
|
||||
|
||||
public boolean isWritable(Object rootObject) throws EvaluationException {
|
||||
return ast.isWritable(new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), configuration));
|
||||
}
|
||||
|
||||
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
return ast.isWritable(new ExpressionState(context, toTypedValue(rootObject), configuration));
|
||||
}
|
||||
|
||||
public void setValue(EvaluationContext context, Object value) throws EvaluationException {
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
ast.setValue(new ExpressionState(context, configuration), value);
|
||||
}
|
||||
|
||||
public void setValue(Object rootObject, Object value) throws EvaluationException {
|
||||
ast.setValue(new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), configuration), value);
|
||||
}
|
||||
|
||||
|
||||
public void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException {
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
Assert.notNull(context, "The EvaluationContext is required");
|
||||
ast.setValue(new ExpressionState(context, toTypedValue(rootObject), configuration), value);
|
||||
}
|
||||
|
||||
|
||||
// impl only
|
||||
|
||||
/**
|
||||
@@ -196,7 +196,7 @@ public class SpelExpression implements Expression {
|
||||
public String toStringAST() {
|
||||
return ast.toStringAST();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the default evaluation context that will be used if none is supplied on an evaluation call
|
||||
* @return the default evaluation context
|
||||
@@ -207,7 +207,7 @@ public class SpelExpression implements Expression {
|
||||
}
|
||||
return defaultContext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the evaluation context that will be used if none is specified on an evaluation call.
|
||||
* @param context an evaluation context
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* SpEL parser. Instances are reusable and thread-safe.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
|
||||
@@ -18,17 +18,17 @@ package org.springframework.expression.spel.standard;
|
||||
|
||||
/**
|
||||
* Holder for a kind of token, the associated data and its position in the input data stream (start/end).
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
class Token {
|
||||
|
||||
|
||||
TokenKind kind;
|
||||
String data;
|
||||
int startpos; // index of first character
|
||||
int endpos; // index of char after the last character
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for use when there is no particular data for the token (eg. TRUE or '+')
|
||||
* @param startpos the exact start
|
||||
@@ -39,17 +39,17 @@ class Token {
|
||||
this.startpos = startpos;
|
||||
this.endpos = endpos;
|
||||
}
|
||||
|
||||
|
||||
Token(TokenKind tokenKind, char[] tokenData, int pos, int endpos) {
|
||||
this(tokenKind,pos,endpos);
|
||||
this.data = new String(tokenData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public TokenKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append("[").append(kind.toString());
|
||||
|
||||
@@ -22,9 +22,9 @@ package org.springframework.expression.spel.standard;
|
||||
*/
|
||||
enum TokenKind {
|
||||
// ordered by priority - operands first
|
||||
LITERAL_INT, LITERAL_LONG, LITERAL_HEXINT, LITERAL_HEXLONG, LITERAL_STRING, LITERAL_REAL, LITERAL_REAL_FLOAT,
|
||||
LITERAL_INT, LITERAL_LONG, LITERAL_HEXINT, LITERAL_HEXLONG, LITERAL_STRING, LITERAL_REAL, LITERAL_REAL_FLOAT,
|
||||
LPAREN("("), RPAREN(")"), COMMA(","), IDENTIFIER,
|
||||
COLON(":"),HASH("#"),RSQUARE("]"), LSQUARE("["),
|
||||
COLON(":"),HASH("#"),RSQUARE("]"), LSQUARE("["),
|
||||
LCURLY("{"),RCURLY("}"),
|
||||
DOT("."), PLUS("+"), STAR("*"), MINUS("-"), SELECT_FIRST("^["), SELECT_LAST("$["), QMARK("?"), PROJECT("!["),
|
||||
DIV("/"), GE(">="), GT(">"), LE("<="), LT("<"), EQ("=="), NE("!="),
|
||||
|
||||
@@ -27,12 +27,12 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Lex some input data into a stream of tokens that can then be parsed.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
*/
|
||||
class Tokenizer {
|
||||
|
||||
|
||||
String expressionString;
|
||||
char[] toProcess;
|
||||
int pos;
|
||||
@@ -117,7 +117,7 @@ class Tokenizer {
|
||||
if (isTwoCharToken(TokenKind.SELECT_FIRST)) {
|
||||
pushPairToken(TokenKind.SELECT_FIRST);
|
||||
} else {
|
||||
pushCharToken(TokenKind.POWER);
|
||||
pushCharToken(TokenKind.POWER);
|
||||
}
|
||||
break;
|
||||
case '!':
|
||||
@@ -145,7 +145,7 @@ class Tokenizer {
|
||||
if (isTwoCharToken(TokenKind.SYMBOLIC_OR)) {
|
||||
pushPairToken(TokenKind.SYMBOLIC_OR);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case '?':
|
||||
if (isTwoCharToken(TokenKind.SELECT)) {
|
||||
pushPairToken(TokenKind.SELECT);
|
||||
@@ -154,7 +154,7 @@ class Tokenizer {
|
||||
} else if (isTwoCharToken(TokenKind.SAFE_NAVI)) {
|
||||
pushPairToken(TokenKind.SAFE_NAVI);
|
||||
} else {
|
||||
pushCharToken(TokenKind.QMARK);
|
||||
pushCharToken(TokenKind.QMARK);
|
||||
}
|
||||
break;
|
||||
case '$':
|
||||
@@ -216,7 +216,7 @@ class Tokenizer {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Token> getTokens() {
|
||||
public List<Token> getTokens() {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
@@ -266,26 +266,26 @@ class Tokenizer {
|
||||
tokens.add(new Token(TokenKind.LITERAL_STRING, subarray(start,pos), start, pos));
|
||||
}
|
||||
|
||||
// REAL_LITERAL :
|
||||
// REAL_LITERAL :
|
||||
// ('.' (DECIMAL_DIGIT)+ (EXPONENT_PART)? (REAL_TYPE_SUFFIX)?) |
|
||||
// ((DECIMAL_DIGIT)+ '.' (DECIMAL_DIGIT)+ (EXPONENT_PART)? (REAL_TYPE_SUFFIX)?) |
|
||||
// ((DECIMAL_DIGIT)+ (EXPONENT_PART) (REAL_TYPE_SUFFIX)?) |
|
||||
// ((DECIMAL_DIGIT)+ (REAL_TYPE_SUFFIX));
|
||||
// fragment INTEGER_TYPE_SUFFIX : ( 'L' | 'l' );
|
||||
// fragment HEX_DIGIT : '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'A'|'B'|'C'|'D'|'E'|'F'|'a'|'b'|'c'|'d'|'e'|'f';
|
||||
//
|
||||
// fragment EXPONENT_PART : 'e' (SIGN)* (DECIMAL_DIGIT)+ | 'E' (SIGN)* (DECIMAL_DIGIT)+ ;
|
||||
// fragment HEX_DIGIT : '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'A'|'B'|'C'|'D'|'E'|'F'|'a'|'b'|'c'|'d'|'e'|'f';
|
||||
//
|
||||
// fragment EXPONENT_PART : 'e' (SIGN)* (DECIMAL_DIGIT)+ | 'E' (SIGN)* (DECIMAL_DIGIT)+ ;
|
||||
// fragment SIGN : '+' | '-' ;
|
||||
// fragment REAL_TYPE_SUFFIX : 'F' | 'f' | 'D' | 'd';
|
||||
// INTEGER_LITERAL
|
||||
// : (DECIMAL_DIGIT)+ (INTEGER_TYPE_SUFFIX)?;
|
||||
// : (DECIMAL_DIGIT)+ (INTEGER_TYPE_SUFFIX)?;
|
||||
|
||||
private void lexNumericLiteral(boolean firstCharIsZero) {
|
||||
boolean isReal = false;
|
||||
int start = pos;
|
||||
char ch = toProcess[pos+1];
|
||||
boolean isHex = ch=='x' || ch=='X';
|
||||
|
||||
|
||||
// deal with hexadecimal
|
||||
if (firstCharIsZero && isHex) {
|
||||
pos=pos+1;
|
||||
@@ -293,16 +293,16 @@ class Tokenizer {
|
||||
pos++;
|
||||
} while (isHexadecimalDigit(toProcess[pos]));
|
||||
if (isChar('L','l')) {
|
||||
pushHexIntToken(subarray(start+2,pos),true, start, pos);
|
||||
pushHexIntToken(subarray(start+2,pos),true, start, pos);
|
||||
pos++;
|
||||
} else {
|
||||
pushHexIntToken(subarray(start+2,pos),false, start, pos);
|
||||
pushHexIntToken(subarray(start+2,pos),false, start, pos);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// real numbers must have leading digits
|
||||
|
||||
|
||||
// Consume first part of number
|
||||
do {
|
||||
pos++;
|
||||
@@ -311,7 +311,7 @@ class Tokenizer {
|
||||
// a '.' indicates this number is a real
|
||||
ch = toProcess[pos];
|
||||
if (ch=='.') {
|
||||
isReal = true;
|
||||
isReal = true;
|
||||
int dotpos = pos;
|
||||
// carry on consuming digits
|
||||
do {
|
||||
@@ -328,9 +328,9 @@ class Tokenizer {
|
||||
}
|
||||
|
||||
int endOfNumber = pos;
|
||||
|
||||
|
||||
// Now there may or may not be an exponent
|
||||
|
||||
|
||||
// is it a long ?
|
||||
if (isChar('L','l')) {
|
||||
if (isReal) { // 3.4L - not allowed
|
||||
@@ -345,7 +345,7 @@ class Tokenizer {
|
||||
if (isSign(possibleSign)) {
|
||||
pos++;
|
||||
}
|
||||
|
||||
|
||||
// exponent digits
|
||||
do {
|
||||
pos++;
|
||||
@@ -354,7 +354,7 @@ class Tokenizer {
|
||||
if (isFloatSuffix(toProcess[pos])) {
|
||||
isFloat = true;
|
||||
endOfNumber = ++pos;
|
||||
} else if (isDoubleSuffix(toProcess[pos])) {
|
||||
} else if (isDoubleSuffix(toProcess[pos])) {
|
||||
endOfNumber = ++pos;
|
||||
}
|
||||
pushRealToken(subarray(start,pos), isFloat, start, pos);
|
||||
@@ -367,7 +367,7 @@ class Tokenizer {
|
||||
endOfNumber = ++pos;
|
||||
} else if (isDoubleSuffix(ch)) {
|
||||
isReal = true;
|
||||
endOfNumber = ++pos;
|
||||
endOfNumber = ++pos;
|
||||
}
|
||||
if (isReal) {
|
||||
pushRealToken(subarray(start,endOfNumber), isFloat, start, endOfNumber);
|
||||
@@ -386,7 +386,7 @@ class Tokenizer {
|
||||
pos++;
|
||||
} while (isIdentifier(toProcess[pos]));
|
||||
char[] subarray = subarray(start,pos);
|
||||
|
||||
|
||||
// Check if this is the alternative (textual) representation of an operator (see alternativeOperatorNames)
|
||||
if ((pos-start)==2 || (pos-start)==3) {
|
||||
String asString = new String(subarray).toUpperCase();
|
||||
@@ -409,7 +409,7 @@ class Tokenizer {
|
||||
|
||||
private void pushHexIntToken(char[] data,boolean isLong, int start, int end) {
|
||||
if (data.length==0) {
|
||||
if (isLong) {
|
||||
if (isLong) {
|
||||
throw new InternalParseException(new SpelParseException(expressionString,start,SpelMessage.NOT_A_LONG,expressionString.substring(start,end+1)));
|
||||
} else {
|
||||
throw new InternalParseException(new SpelParseException(expressionString,start,SpelMessage.NOT_AN_INTEGER,expressionString.substring(start,end)));
|
||||
@@ -426,7 +426,7 @@ class Tokenizer {
|
||||
if (isFloat) {
|
||||
tokens.add(new Token(TokenKind.LITERAL_REAL_FLOAT, data, start, end));
|
||||
} else {
|
||||
tokens.add(new Token(TokenKind.LITERAL_REAL, data, start, end));
|
||||
tokens.add(new Token(TokenKind.LITERAL_REAL, data, start, end));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ class Tokenizer {
|
||||
return (flags[ch] & IS_HEXDIGIT)!=0;
|
||||
}
|
||||
|
||||
private static final byte flags[] = new byte[256];
|
||||
private static final byte flags[] = new byte[256];
|
||||
private static final byte IS_DIGIT=0x01;
|
||||
private static final byte IS_HEXDIGIT=0x02;
|
||||
private static final byte IS_ALPHA=0x04;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class BooleanTypedValue extends TypedValue {
|
||||
private BooleanTypedValue(boolean b) {
|
||||
super(b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static BooleanTypedValue forValue(boolean b) {
|
||||
if (b) {
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ReflectionHelper {
|
||||
if (suppliedArg.isAssignableTo(expectedArg)) {
|
||||
if (match != ArgsMatchKind.REQUIRES_CONVERSION) {
|
||||
match = ArgsMatchKind.CLOSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeConverter.canConvert(suppliedArg, expectedArg)) {
|
||||
if (argsRequiringConversion == null) {
|
||||
@@ -103,7 +103,7 @@ public class ReflectionHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Based on {@link MethodInvoker#getTypeDifferenceWeight(Class[], Object[])} but operates on TypeDescriptors.
|
||||
*/
|
||||
@@ -153,17 +153,17 @@ public class ReflectionHelper {
|
||||
* type by the converter. This variant of compareArguments also allows for a varargs match.
|
||||
* @param expectedArgTypes the array of types the method/constructor is expecting
|
||||
* @param suppliedArgTypes the array of types that are being supplied at the point of invocation
|
||||
* @param typeConverter a registered type converter
|
||||
* @param typeConverter a registered type converter
|
||||
* @return a MatchInfo object indicating what kind of match it was or null if it was not a match
|
||||
*/
|
||||
static ArgumentsMatchInfo compareArgumentsVarargs(
|
||||
List<TypeDescriptor> expectedArgTypes, List<TypeDescriptor> suppliedArgTypes, TypeConverter typeConverter) {
|
||||
|
||||
|
||||
Assert.isTrue(expectedArgTypes != null && expectedArgTypes.size() > 0,
|
||||
"Expected arguments must at least include one array (the vargargs parameter)");
|
||||
Assert.isTrue(expectedArgTypes.get(expectedArgTypes.size() - 1).isArray(),
|
||||
"Final expected argument should be array type (the varargs parameter)");
|
||||
|
||||
|
||||
ArgsMatchKind match = ArgsMatchKind.EXACT;
|
||||
List<Integer> argsRequiringConversion = null;
|
||||
|
||||
@@ -221,7 +221,7 @@ public class ReflectionHelper {
|
||||
if (suppliedArg == null) {
|
||||
if (varargsParameterType.isPrimitive()) {
|
||||
match = null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (varargsParameterType != suppliedArg.getType()) {
|
||||
if (ClassUtils.isAssignable(varargsParameterType, suppliedArg.getType())) {
|
||||
@@ -284,18 +284,18 @@ public class ReflectionHelper {
|
||||
for (int i = 0; i < varargsPosition; i++) {
|
||||
TypeDescriptor targetType = new TypeDescriptor(MethodParameter.forMethodOrConstructor(methodOrCtor, i));
|
||||
Object argument = arguments[i];
|
||||
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
|
||||
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
|
||||
}
|
||||
MethodParameter methodParam = MethodParameter.forMethodOrConstructor(methodOrCtor, varargsPosition);
|
||||
if (varargsPosition == arguments.length - 1) {
|
||||
TypeDescriptor targetType = new TypeDescriptor(methodParam);
|
||||
TypeDescriptor targetType = new TypeDescriptor(methodParam);
|
||||
Object argument = arguments[varargsPosition];
|
||||
arguments[varargsPosition] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
|
||||
arguments[varargsPosition] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
|
||||
} else {
|
||||
TypeDescriptor targetType = TypeDescriptor.nested(methodParam, 1);
|
||||
for (int i = varargsPosition; i < arguments.length; i++) {
|
||||
Object argument = arguments[i];
|
||||
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
|
||||
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -371,7 +371,7 @@ public class ReflectionHelper {
|
||||
if (argumentCount >= parameterCount) {
|
||||
arraySize = argumentCount - (parameterCount - 1);
|
||||
}
|
||||
|
||||
|
||||
// Create an array for the varargs arguments
|
||||
Object[] newArgs = new Object[parameterCount];
|
||||
for (int i = 0; i < newArgs.length - 1; i++) {
|
||||
@@ -446,9 +446,9 @@ public class ReflectionHelper {
|
||||
|
||||
public static enum ArgsMatchKind {
|
||||
// An exact match is where the parameter types exactly match what the method/constructor being invoked is expecting
|
||||
EXACT,
|
||||
EXACT,
|
||||
// A close match is where the parameter types either exactly match or are assignment compatible with the method/constructor being invoked
|
||||
CLOSE,
|
||||
CLOSE,
|
||||
// A conversion match is where the type converter must be used to transform some of the parameter types
|
||||
REQUIRES_CONVERSION
|
||||
}
|
||||
@@ -474,11 +474,11 @@ public class ReflectionHelper {
|
||||
ArgumentsMatchInfo(ArgsMatchKind kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
|
||||
public boolean isExactMatch() {
|
||||
return (this.kind == ArgsMatchKind.EXACT);
|
||||
}
|
||||
|
||||
|
||||
public boolean isCloseMatch() {
|
||||
return (this.kind == ArgsMatchKind.CLOSE);
|
||||
}
|
||||
@@ -486,7 +486,7 @@ public class ReflectionHelper {
|
||||
public boolean isMatchRequiringConversion() {
|
||||
return (this.kind == ArgsMatchKind.REQUIRES_CONVERSION);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("ArgumentMatch: ").append(this.kind);
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.expression.TypeConverter;
|
||||
|
||||
/**
|
||||
* A constructor resolver that uses reflection to locate the constructor that should be invoked
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
|
||||
@@ -47,13 +47,13 @@ import org.springframework.util.Assert;
|
||||
* @since 3.0
|
||||
*/
|
||||
public class StandardEvaluationContext implements EvaluationContext {
|
||||
|
||||
|
||||
private TypedValue rootObject;
|
||||
|
||||
private List<ConstructorResolver> constructorResolvers;
|
||||
|
||||
private List<MethodResolver> methodResolvers;
|
||||
|
||||
|
||||
private ReflectiveMethodResolver reflectiveMethodResolver;
|
||||
|
||||
private List<PropertyAccessor> propertyAccessors;
|
||||
@@ -67,14 +67,14 @@ public class StandardEvaluationContext implements EvaluationContext {
|
||||
private OperatorOverloader operatorOverloader = new StandardOperatorOverloader();
|
||||
|
||||
private final Map<String, Object> variables = new HashMap<String, Object>();
|
||||
|
||||
|
||||
private BeanResolver beanResolver;
|
||||
|
||||
|
||||
public StandardEvaluationContext() {
|
||||
setRootObject(null);
|
||||
}
|
||||
|
||||
|
||||
public StandardEvaluationContext(Object rootObject) {
|
||||
this();
|
||||
setRootObject(rootObject);
|
||||
@@ -102,12 +102,12 @@ public class StandardEvaluationContext implements EvaluationContext {
|
||||
ensureConstructorResolversInitialized();
|
||||
return this.constructorResolvers.remove(resolver);
|
||||
}
|
||||
|
||||
|
||||
public List<ConstructorResolver> getConstructorResolvers() {
|
||||
ensureConstructorResolversInitialized();
|
||||
return this.constructorResolvers;
|
||||
}
|
||||
|
||||
|
||||
public void setConstructorResolvers(List<ConstructorResolver> constructorResolvers) {
|
||||
this.constructorResolvers = constructorResolvers;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class StandardEvaluationContext implements EvaluationContext {
|
||||
ensureMethodResolversInitialized();
|
||||
this.methodResolvers.add(this.methodResolvers.size() - 1, resolver);
|
||||
}
|
||||
|
||||
|
||||
public boolean removeMethodResolver(MethodResolver methodResolver) {
|
||||
ensureMethodResolversInitialized();
|
||||
return this.methodResolvers.remove(methodResolver);
|
||||
@@ -131,21 +131,21 @@ public class StandardEvaluationContext implements EvaluationContext {
|
||||
public void setBeanResolver(BeanResolver beanResolver) {
|
||||
this.beanResolver = beanResolver;
|
||||
}
|
||||
|
||||
|
||||
public BeanResolver getBeanResolver() {
|
||||
return this.beanResolver;
|
||||
}
|
||||
|
||||
|
||||
public void setMethodResolvers(List<MethodResolver> methodResolvers) {
|
||||
this.methodResolvers = methodResolvers;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addPropertyAccessor(PropertyAccessor accessor) {
|
||||
ensurePropertyAccessorsInitialized();
|
||||
this.propertyAccessors.add(this.propertyAccessors.size() - 1, accessor);
|
||||
}
|
||||
|
||||
|
||||
public boolean removePropertyAccessor(PropertyAccessor accessor) {
|
||||
return this.propertyAccessors.remove(accessor);
|
||||
}
|
||||
@@ -154,7 +154,7 @@ public class StandardEvaluationContext implements EvaluationContext {
|
||||
ensurePropertyAccessorsInitialized();
|
||||
return this.propertyAccessors;
|
||||
}
|
||||
|
||||
|
||||
public void setPropertyAccessors(List<PropertyAccessor> propertyAccessors) {
|
||||
this.propertyAccessors = propertyAccessors;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.expression.spel.SpelMessage;
|
||||
|
||||
/**
|
||||
* A simple basic TypeComparator implementation. It supports comparison of numbers and types implementing Comparable.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
@@ -68,7 +68,7 @@ public class StandardTypeComparator implements TypeComparator {
|
||||
} catch (ClassCastException cce) {
|
||||
throw new SpelEvaluationException(cce, SpelMessage.NOT_COMPARABLE, left.getClass(), right.getClass());
|
||||
}
|
||||
|
||||
|
||||
throw new SpelEvaluationException(SpelMessage.NOT_COMPARABLE, left.getClass(), right.getClass());
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* Default implementation of the {@link TypeConverter} interface,
|
||||
* delegating to a core Spring {@link ConversionService}.
|
||||
*
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
@@ -38,7 +38,7 @@ import org.springframework.util.Assert;
|
||||
public class StandardTypeConverter implements TypeConverter {
|
||||
|
||||
private static ConversionService defaultConversionService;
|
||||
|
||||
|
||||
private final ConversionService conversionService;
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.util.ClassUtils;
|
||||
/**
|
||||
* A default implementation of a TypeLocator that uses the context classloader (or any classloader set upon it). It
|
||||
* supports 'well known' packages so if a type cannot be found it will try the registered imports to locate it.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
@@ -95,9 +95,9 @@ public class StandardTypeLocator implements TypeLocator {
|
||||
public List<String> getImportPrefixes() {
|
||||
return Collections.unmodifiableList(this.knownPackagePrefixes);
|
||||
}
|
||||
|
||||
|
||||
public void removeImport(String prefix) {
|
||||
this.knownPackagePrefixes.remove(prefix);
|
||||
this.knownPackagePrefixes.remove(prefix);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
/**
|
||||
* Test construction of arrays.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ArrayConstructorTests extends ExpressionTestCase {
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||
|
||||
/**
|
||||
* Tests invocation of constructors.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||
@@ -43,22 +43,22 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||
public void testTypeConstructors() {
|
||||
evaluate("new String('hello world')", "hello world", String.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNonExistentType() {
|
||||
evaluateAndCheckError("new FooBar()",SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM);
|
||||
}
|
||||
|
||||
|
||||
static class TestException extends Exception {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class Tester {
|
||||
public static int counter;
|
||||
public int i;
|
||||
|
||||
|
||||
public Tester() {}
|
||||
|
||||
|
||||
public Tester(int i) throws Exception {
|
||||
counter++;
|
||||
if (i==1) {
|
||||
@@ -72,11 +72,11 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||
}
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
|
||||
public Tester(PlaceOfBirth pob) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testConstructorThrowingException_SPR6760() {
|
||||
@@ -85,7 +85,7 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||
// On 2 it will throw a RuntimeException
|
||||
// On 3 it will exit normally
|
||||
// In each case it increments the Tester field 'counter' when invoked
|
||||
|
||||
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("new org.springframework.expression.spel.ConstructorInvocationTests$Tester(#bar).i");
|
||||
|
||||
@@ -104,11 +104,11 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||
o = expr.getValue(eContext);
|
||||
Assert.assertEquals(0, o);
|
||||
// That confirms the logic to mark the cached reference stale and retry is working
|
||||
|
||||
|
||||
|
||||
|
||||
// Now let's cause the method to exit via exception and ensure it doesn't cause
|
||||
// a retry.
|
||||
|
||||
|
||||
// First, switch back to throwException(int)
|
||||
eContext.setVariable("bar",3);
|
||||
o = expr.getValue(eContext);
|
||||
@@ -130,8 +130,8 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||
}
|
||||
// If counter is 4 then the method got called twice!
|
||||
Assert.assertEquals(3,parser.parseExpression("counter").getValue(eContext));
|
||||
|
||||
|
||||
|
||||
|
||||
// 1 will make it throw a RuntimeException - SpEL will let this through
|
||||
eContext.setVariable("bar",1);
|
||||
try {
|
||||
@@ -147,38 +147,38 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||
// If counter is 5 then the method got called twice!
|
||||
Assert.assertEquals(4,parser.parseExpression("counter").getValue(eContext));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddingConstructorResolvers() {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
|
||||
// reflective constructor accessor is the only one by default
|
||||
List<ConstructorResolver> constructorResolvers = ctx.getConstructorResolvers();
|
||||
Assert.assertEquals(1,constructorResolvers.size());
|
||||
|
||||
|
||||
ConstructorResolver dummy = new DummyConstructorResolver();
|
||||
ctx.addConstructorResolver(dummy);
|
||||
Assert.assertEquals(2,ctx.getConstructorResolvers().size());
|
||||
|
||||
|
||||
List<ConstructorResolver> copy = new ArrayList<ConstructorResolver>();
|
||||
copy.addAll(ctx.getConstructorResolvers());
|
||||
Assert.assertTrue(ctx.removeConstructorResolver(dummy));
|
||||
Assert.assertFalse(ctx.removeConstructorResolver(dummy));
|
||||
Assert.assertEquals(1,ctx.getConstructorResolvers().size());
|
||||
|
||||
|
||||
ctx.setConstructorResolvers(copy);
|
||||
Assert.assertEquals(2,ctx.getConstructorResolvers().size());
|
||||
}
|
||||
|
||||
|
||||
static class DummyConstructorResolver implements ConstructorResolver {
|
||||
|
||||
public ConstructorExecutor resolve(EvaluationContext context, String typeName, List<TypeDescriptor> argumentTypes)
|
||||
throws AccessException {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testVarargsInvocation01() {
|
||||
// Calling 'Fruit(String... strings)'
|
||||
@@ -201,7 +201,7 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(2,'a',3.0d).stringscount()", 4, Integer.class);
|
||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(8,stringArrayOfThreeItems).stringscount()", 11, Integer.class);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* These tests are attempting to call constructors where we need to widen or convert the argument in order to
|
||||
* satisfy a suitable constructor.
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.expression.spel.support.StandardTypeComparator;
|
||||
|
||||
/**
|
||||
* Unit tests for type comparison
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class DefaultComparatorUnitTests {
|
||||
@@ -52,12 +52,12 @@ public class DefaultComparatorUnitTests {
|
||||
Assert.assertTrue(comparator.compare(1, 2L) < 0);
|
||||
Assert.assertTrue(comparator.compare(1, 1L) == 0);
|
||||
Assert.assertTrue(comparator.compare(2, 1L) > 0);
|
||||
|
||||
|
||||
Assert.assertTrue(comparator.compare(1L, 2L) < 0);
|
||||
Assert.assertTrue(comparator.compare(1L, 1L) == 0);
|
||||
Assert.assertTrue(comparator.compare(2L, 1L) > 0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNulls() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
@@ -73,7 +73,7 @@ public class DefaultComparatorUnitTests {
|
||||
Assert.assertTrue(comparator.compare("a","b")<0);
|
||||
Assert.assertTrue(comparator.compare("b","a")>0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCanCompare() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
@@ -85,5 +85,5 @@ public class DefaultComparatorUnitTests {
|
||||
Assert.assertTrue(comparator.canCompare("abc",3));
|
||||
Assert.assertFalse(comparator.canCompare(String.class,3));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
* <li>Adding an advanced (better performing) property resolver
|
||||
* <li>Adding your own type converter to support conversion between any types you like
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
@@ -75,7 +75,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
Object value = expr.getValue();
|
||||
// They are reusable
|
||||
value = expr.getValue();
|
||||
|
||||
|
||||
Assert.assertEquals("hello world", value);
|
||||
Assert.assertEquals(String.class, value.getClass());
|
||||
} catch (EvaluationException ee) {
|
||||
@@ -100,7 +100,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
List<Integer> primes = new ArrayList<Integer>();
|
||||
primes.addAll(Arrays.asList(2,3,5,7,11,13,17));
|
||||
ctx.setVariable("primes",primes);
|
||||
|
||||
|
||||
Expression expr = parser.parseRaw("#favouriteColour");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals("blue", value);
|
||||
@@ -112,17 +112,17 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
// all prime numbers > 10 from the list (using selection ?{...})
|
||||
expr = parser.parseRaw("#primes.?[#this>10]");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals("[11, 13, 17]", value.toString());
|
||||
Assert.assertEquals("[11, 13, 17]", value.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
static class TestClass {
|
||||
public String str;
|
||||
private int property;
|
||||
public int getProperty() { return property; }
|
||||
public void setProperty(int i) { property = i; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scenario: using your own root context object
|
||||
*/
|
||||
@@ -137,11 +137,11 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
tc.setProperty(42);
|
||||
tc.str = "wibble";
|
||||
ctx.setRootObject(tc);
|
||||
|
||||
|
||||
// read it, set it, read it again
|
||||
Expression expr = parser.parseRaw("str");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals("wibble", value);
|
||||
Assert.assertEquals("wibble", value);
|
||||
expr = parser.parseRaw("str");
|
||||
expr.setValue(ctx, "wobble");
|
||||
expr = parser.parseRaw("str");
|
||||
@@ -153,7 +153,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
expr = parser.parseRaw("str");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals("wabble", value);
|
||||
|
||||
|
||||
// private property will be accessed through getter()
|
||||
expr = parser.parseRaw("property");
|
||||
value = expr.getValue(ctx);
|
||||
@@ -166,7 +166,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals(4,value);
|
||||
}
|
||||
|
||||
|
||||
public static String repeat(String s) { return s+s; }
|
||||
|
||||
/**
|
||||
@@ -180,7 +180,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
// Use the standard evaluation context
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
ctx.registerFunction("repeat",ExpressionLanguageScenarioTests.class.getDeclaredMethod("repeat",String.class));
|
||||
|
||||
|
||||
Expression expr = parser.parseRaw("#repeat('hello')");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals("hellohello", value);
|
||||
@@ -193,7 +193,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
Assert.fail("Unexpected Exception: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scenario: add a property resolver that will get called in the resolver chain, this one only supports reading.
|
||||
*/
|
||||
@@ -313,6 +313,6 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ import org.springframework.expression.spel.testresources.Inventor;
|
||||
|
||||
/**
|
||||
* Tests for the expression state object - some features are not yet exploited in the language (eg nested scopes)
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ExpressionStateTests extends ExpressionTestCase {
|
||||
|
||||
@Test
|
||||
public void testConstruction() {
|
||||
public void testConstruction() {
|
||||
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
ExpressionState state = new ExpressionState(context);
|
||||
Assert.assertEquals(context,state.getEvaluationContext());
|
||||
@@ -47,14 +47,14 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
|
||||
// Local variables are in variable scopes which come and go during evaluation. Normal variables are
|
||||
// accessible through the evaluation context
|
||||
|
||||
|
||||
@Test
|
||||
public void testLocalVariables() {
|
||||
ExpressionState state = getState();
|
||||
|
||||
|
||||
Object value = state.lookupLocalVariable("foo");
|
||||
Assert.assertNull(value);
|
||||
|
||||
|
||||
state.setLocalVariable("foo",34);
|
||||
value = state.lookupLocalVariable("foo");
|
||||
Assert.assertEquals(34,value);
|
||||
@@ -80,13 +80,13 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
Assert.assertEquals("abc",typedValue.getValue());
|
||||
Assert.assertEquals(String.class,typedValue.getTypeDescriptor().getType());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNoVariableInteference() {
|
||||
ExpressionState state = getState();
|
||||
TypedValue typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals(TypedValue.NULL,typedValue);
|
||||
|
||||
|
||||
state.setLocalVariable("foo",34);
|
||||
typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals(TypedValue.NULL,typedValue);
|
||||
@@ -94,25 +94,25 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
state.setVariable("goo","hello");
|
||||
Assert.assertNull(state.lookupLocalVariable("goo"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLocalVariableNestedScopes() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertEquals(null,state.lookupLocalVariable("foo"));
|
||||
|
||||
|
||||
state.setLocalVariable("foo",12);
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo"));
|
||||
|
||||
|
||||
state.enterScope(null);
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo")); // found in upper scope
|
||||
|
||||
state.setLocalVariable("foo","abc");
|
||||
Assert.assertEquals("abc",state.lookupLocalVariable("foo")); // found in nested scope
|
||||
|
||||
|
||||
state.exitScope();
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo")); // found in nested scope
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRootContextObject() {
|
||||
ExpressionState state = getState();
|
||||
@@ -122,62 +122,62 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
|
||||
Assert.assertEquals(Inventor.class,state.getRootContextObject().getValue().getClass());
|
||||
// Assert.assertEquals(null, state.getRootContextObject().getValue());
|
||||
|
||||
|
||||
state = new ExpressionState(new StandardEvaluationContext());
|
||||
Assert.assertEquals(TypedValue.NULL,state.getRootContextObject());
|
||||
|
||||
|
||||
|
||||
((StandardEvaluationContext)state.getEvaluationContext()).setRootObject(null);
|
||||
Assert.assertEquals(null,state.getRootContextObject().getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testActiveContextObject() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertEquals(state.getRootContextObject().getValue(),state.getActiveContextObject().getValue());
|
||||
|
||||
|
||||
try {
|
||||
state.popActiveContextObject();
|
||||
Assert.fail("stack should be empty...");
|
||||
} catch (EmptyStackException ese) {
|
||||
// success
|
||||
}
|
||||
|
||||
|
||||
state.pushActiveContextObject(new TypedValue(34));
|
||||
Assert.assertEquals(34,state.getActiveContextObject().getValue());
|
||||
|
||||
|
||||
state.pushActiveContextObject(new TypedValue("hello"));
|
||||
Assert.assertEquals("hello",state.getActiveContextObject().getValue());
|
||||
|
||||
|
||||
state.popActiveContextObject();
|
||||
Assert.assertEquals(34,state.getActiveContextObject().getValue());
|
||||
|
||||
|
||||
state.popActiveContextObject();
|
||||
Assert.assertEquals(state.getRootContextObject().getValue(),state.getActiveContextObject().getValue());
|
||||
|
||||
|
||||
state = new ExpressionState(new StandardEvaluationContext());
|
||||
Assert.assertEquals(TypedValue.NULL,state.getActiveContextObject());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPopulatedNestedScopes() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertNull(state.lookupLocalVariable("foo"));
|
||||
|
||||
|
||||
state.enterScope("foo",34);
|
||||
Assert.assertEquals(34,state.lookupLocalVariable("foo"));
|
||||
|
||||
|
||||
state.enterScope(null);
|
||||
state.setLocalVariable("foo",12);
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo"));
|
||||
|
||||
state.exitScope();
|
||||
Assert.assertEquals(34,state.lookupLocalVariable("foo"));
|
||||
|
||||
|
||||
state.exitScope();
|
||||
Assert.assertNull(state.lookupLocalVariable("goo"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRootObjectConstructor() {
|
||||
EvaluationContext ctx = getContext();
|
||||
@@ -188,21 +188,21 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
Assert.assertEquals(String.class,stateRoot.getTypeDescriptor().getType());
|
||||
Assert.assertEquals("i am a string",stateRoot.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPopulatedNestedScopesMap() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertNull(state.lookupLocalVariable("foo"));
|
||||
Assert.assertNull(state.lookupLocalVariable("goo"));
|
||||
|
||||
|
||||
Map<String,Object> m = new HashMap<String,Object>();
|
||||
m.put("foo",34);
|
||||
m.put("goo","abc");
|
||||
|
||||
|
||||
state.enterScope(m);
|
||||
Assert.assertEquals(34,state.lookupLocalVariable("foo"));
|
||||
Assert.assertEquals("abc",state.lookupLocalVariable("goo"));
|
||||
|
||||
|
||||
state.enterScope(null);
|
||||
state.setLocalVariable("foo",12);
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo"));
|
||||
@@ -213,7 +213,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
Assert.assertNull(state.lookupLocalVariable("foo"));
|
||||
Assert.assertNull(state.lookupLocalVariable("goo"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOperators() throws Exception {
|
||||
ExpressionState state = getState();
|
||||
@@ -233,13 +233,13 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
Assert.assertEquals(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES,sEx.getMessageCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testComparator() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertEquals(state.getEvaluationContext().getTypeComparator(),state.getTypeComparator());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTypeLocator() throws EvaluationException {
|
||||
ExpressionState state = getState();
|
||||
@@ -253,7 +253,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
Assert.assertEquals(SpelMessage.TYPE_NOT_FOUND,sEx.getMessageCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTypeConversion() throws EvaluationException {
|
||||
ExpressionState state = getState();
|
||||
@@ -269,7 +269,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertEquals(state.getEvaluationContext().getPropertyAccessors(),state.getPropertyAccessors());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a new ExpressionState
|
||||
*/
|
||||
@@ -278,7 +278,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
ExpressionState state = new ExpressionState(context);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
private EvaluationContext getContext() {
|
||||
return TestScenarioCreator.getTestEvaluationContext();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
|
||||
private static TypeDescriptor typeDescriptorForListOfString = null;
|
||||
private static List<Integer> listOfInteger = new ArrayList<Integer>();
|
||||
private static TypeDescriptor typeDescriptorForListOfInteger = null;
|
||||
|
||||
|
||||
static {
|
||||
listOfString.add("1");
|
||||
listOfString.add("2");
|
||||
@@ -58,21 +58,21 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
|
||||
listOfInteger.add(5);
|
||||
listOfInteger.add(6);
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ExpressionTestsUsingCoreConversionService.typeDescriptorForListOfString = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfString"));
|
||||
ExpressionTestsUsingCoreConversionService.typeDescriptorForListOfInteger = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfInteger"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test the service can convert what we are about to use in the expression evaluation tests.
|
||||
*/
|
||||
@Test
|
||||
public void testConversionsAvailable() throws Exception {
|
||||
TypeConvertorUsingConversionService tcs = new TypeConvertorUsingConversionService();
|
||||
|
||||
|
||||
// ArrayList containing List<Integer> to List<String>
|
||||
Class<?> clazz = typeDescriptorForListOfString.getElementTypeDescriptor().getType();
|
||||
assertEquals(String.class,clazz);
|
||||
@@ -82,11 +82,11 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
|
||||
// ArrayList containing List<String> to List<Integer>
|
||||
clazz = typeDescriptorForListOfInteger.getElementTypeDescriptor().getType();
|
||||
assertEquals(Integer.class,clazz);
|
||||
|
||||
|
||||
l = (List) tcs.convertValue(listOfString, TypeDescriptor.forObject(listOfString), typeDescriptorForListOfString);
|
||||
assertNotNull(l);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetParameterizedList() throws Exception {
|
||||
StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
|
||||
@@ -38,7 +38,7 @@ public class IndexingTests {
|
||||
expression = parser.parseExpression("property['foo']");
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
}
|
||||
|
||||
|
||||
@FieldAnnotation
|
||||
public Object property;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class IndexingTests {
|
||||
expression = parser.parseExpression("property['foo']");
|
||||
assertEquals("bar", expression.getValue(context));
|
||||
}
|
||||
|
||||
|
||||
public static class MapAccessor implements PropertyAccessor {
|
||||
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
@@ -83,9 +83,9 @@ public class IndexingTests {
|
||||
public Class<?>[] getSpecificTargetClasses() {
|
||||
return new Class[] { Map.class };
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setGenericPropertyContainingMap() {
|
||||
Map<String, String> property = new HashMap<String, String>();
|
||||
@@ -97,7 +97,7 @@ public class IndexingTests {
|
||||
assertEquals(property, expression.getValue(this));
|
||||
expression = parser.parseExpression("property['foo']");
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
expression.setValue(this, "baz");
|
||||
expression.setValue(this, "baz");
|
||||
assertEquals("baz", expression.getValue(this));
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class IndexingTests {
|
||||
assertEquals(property, expression.getValue(this));
|
||||
expression = parser.parseExpression("parameterizedMap['9']");
|
||||
assertEquals(3, expression.getValue(this));
|
||||
expression.setValue(this, "37");
|
||||
expression.setValue(this, "37");
|
||||
assertEquals(37, expression.getValue(this));
|
||||
}
|
||||
|
||||
@@ -126,10 +126,10 @@ public class IndexingTests {
|
||||
assertEquals(property, expression.getValue(this));
|
||||
expression = parser.parseExpression("parameterizedMap['9']");
|
||||
assertEquals(null, expression.getValue(this));
|
||||
expression.setValue(this, "37");
|
||||
expression.setValue(this, "37");
|
||||
assertEquals(37, expression.getValue(this));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void indexIntoGenericPropertyContainingList() {
|
||||
List<String> property = new ArrayList<String>();
|
||||
@@ -142,7 +142,7 @@ public class IndexingTests {
|
||||
expression = parser.parseExpression("property[0]");
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setGenericPropertyContainingList() {
|
||||
List<Integer> property = new ArrayList<Integer>();
|
||||
@@ -170,10 +170,10 @@ public class IndexingTests {
|
||||
try {
|
||||
expression.setValue(this, "4");
|
||||
} catch (EvaluationException e) {
|
||||
assertTrue(e.getMessage().startsWith("EL1053E"));
|
||||
assertTrue(e.getMessage().startsWith("EL1053E"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void indexIntoPropertyContainingList() {
|
||||
List<Integer> property = new ArrayList<Integer>();
|
||||
@@ -186,7 +186,7 @@ public class IndexingTests {
|
||||
expression = parser.parseExpression("parameterizedList[0]");
|
||||
assertEquals(3, expression.getValue(this));
|
||||
}
|
||||
|
||||
|
||||
public List<Integer> parameterizedList;
|
||||
|
||||
@Test
|
||||
@@ -201,9 +201,9 @@ public class IndexingTests {
|
||||
expression = parser.parseExpression("parameterizedListOfList[0][0]");
|
||||
assertEquals(3, expression.getValue(this));
|
||||
}
|
||||
|
||||
|
||||
public List<List<Integer>> parameterizedListOfList;
|
||||
|
||||
|
||||
@Test
|
||||
public void setPropertyContainingList() {
|
||||
List<Integer> property = new ArrayList<Integer>();
|
||||
@@ -218,7 +218,7 @@ public class IndexingTests {
|
||||
expression.setValue(this, "4");
|
||||
assertEquals(4, expression.getValue(this));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void indexIntoGenericPropertyContainingNullList() {
|
||||
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
|
||||
@@ -230,7 +230,7 @@ public class IndexingTests {
|
||||
try {
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
} catch (EvaluationException e) {
|
||||
assertTrue(e.getMessage().startsWith("EL1027E"));
|
||||
assertTrue(e.getMessage().startsWith("EL1027E"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ public class IndexingTests {
|
||||
assertTrue(e.getMessage().startsWith("EL1053E"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List property2;
|
||||
|
||||
@Test
|
||||
@@ -281,7 +281,7 @@ public class IndexingTests {
|
||||
expression = parser.parseExpression("property[0]");
|
||||
assertEquals("bar", expression.getValue(this));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void emptyList() {
|
||||
listOfScalarNotGeneric = new ArrayList();
|
||||
@@ -315,7 +315,7 @@ public class IndexingTests {
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface FieldAnnotation {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -327,7 +327,7 @@ public class IndexingTests {
|
||||
Expression expression = parser.parseExpression("mapNotGeneric");
|
||||
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(this).toString());
|
||||
}
|
||||
|
||||
|
||||
@FieldAnnotation
|
||||
public Map mapNotGeneric;
|
||||
|
||||
@@ -339,10 +339,10 @@ public class IndexingTests {
|
||||
Expression expression = parser.parseExpression("listOfScalarNotGeneric[0]");
|
||||
assertEquals(new Integer(5), expression.getValue(this, Integer.class));
|
||||
}
|
||||
|
||||
|
||||
public List listOfScalarNotGeneric;
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testListsOfMap() {
|
||||
listOfMapsNotGeneric = new ArrayList();
|
||||
@@ -353,7 +353,7 @@ public class IndexingTests {
|
||||
Expression expression = parser.parseExpression("listOfMapsNotGeneric[0]['fruit']");
|
||||
assertEquals("apple", expression.getValue(this, String.class));
|
||||
}
|
||||
|
||||
|
||||
public List listOfMapsNotGeneric;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
/**
|
||||
* Test usage of inline lists.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0.4
|
||||
*/
|
||||
|
||||
@@ -46,7 +46,7 @@ public class LiteralExpressionTests {
|
||||
Assert.assertFalse(lEx.isWritable(new Rooty()));
|
||||
Assert.assertFalse(lEx.isWritable(new StandardEvaluationContext(), new Rooty()));
|
||||
}
|
||||
|
||||
|
||||
static class Rooty {}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
/**
|
||||
* Tests the evaluation of basic literals: boolean, integer, hex integer, long, real, null, date
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class LiteralTests extends ExpressionTestCase {
|
||||
@@ -159,7 +159,7 @@ public class LiteralTests extends ExpressionTestCase {
|
||||
evaluate("new Integer(37).byteValue()", (byte) 37, Byte.class); // calling byteValue() on Integer.class
|
||||
evaluateAndAskForReturnType("new Integer(37)", (byte) 37, Byte.class); // relying on registered type converters
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNotWritable() throws Exception {
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("37");
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
/**
|
||||
* Testing variations on map access.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class MapAccessTests extends ExpressionTestCase {
|
||||
@@ -170,7 +170,7 @@ public class MapAccessTests extends ExpressionTestCase {
|
||||
public Class<?>[] getSpecificTargetClasses() {
|
||||
return new Class[] { Map.class };
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* Test providing operator support
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class OperatorOverloaderTests extends ExpressionTestCase {
|
||||
@@ -48,11 +48,11 @@ public class OperatorOverloaderTests extends ExpressionTestCase {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleOperations() throws Exception {
|
||||
// no built in support for this:
|
||||
@@ -66,7 +66,7 @@ public class OperatorOverloaderTests extends ExpressionTestCase {
|
||||
|
||||
expr = (SpelExpression)parser.parseExpression("'abc'-true");
|
||||
Assert.assertEquals("abc",expr.getValue(eContext));
|
||||
|
||||
|
||||
expr = (SpelExpression)parser.parseExpression("'abc'+null");
|
||||
Assert.assertEquals("abcnull",expr.getValue(eContext));
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* Tests the evaluation of expressions using relational operators.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class OperatorTests extends ExpressionTestCase {
|
||||
@@ -124,7 +124,7 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
public void testGreaterThanOrEqual() {
|
||||
evaluate("3 >= 5", false, Boolean.class);
|
||||
evaluate("5 >= 3", true, Boolean.class);
|
||||
evaluate("6 >= 6", true, Boolean.class);
|
||||
evaluate("6 >= 6", true, Boolean.class);
|
||||
evaluate("3L >= 5L", false, Boolean.class);
|
||||
evaluate("5L >= 3L", true, Boolean.class);
|
||||
evaluate("5L >= 5L", true, Boolean.class);
|
||||
@@ -137,14 +137,14 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
|
||||
evaluate("3 GE 5", false, Boolean.class);
|
||||
evaluate("5 gE 3", true, Boolean.class);
|
||||
evaluate("6 Ge 6", true, Boolean.class);
|
||||
evaluate("6 Ge 6", true, Boolean.class);
|
||||
evaluate("3L ge 5L", false, Boolean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGreaterThan() {
|
||||
evaluate("3 > 5", false, Boolean.class);
|
||||
evaluate("5 > 3", true, Boolean.class);
|
||||
evaluate("5 > 3", true, Boolean.class);
|
||||
evaluate("3L > 5L", false, Boolean.class);
|
||||
evaluate("5L > 3L", true, Boolean.class);
|
||||
evaluate("3.0d > 5.0d", false, Boolean.class);
|
||||
@@ -172,7 +172,7 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
public void testMathOperatorAdd02() {
|
||||
evaluate("'hello' + ' ' + 'world'", "hello world", String.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMathOperatorsInChains() {
|
||||
evaluate("1+2+3",6,Integer.class);
|
||||
@@ -194,7 +194,7 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
evaluate("3 Mod 2", 1, Integer.class);
|
||||
evaluate("3 MOD 2", 1, Integer.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPlus() throws Exception {
|
||||
evaluate("7 + 2", "9", Integer.class);
|
||||
@@ -205,26 +205,26 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
evaluate("2 + 'a'", "2a", String.class);
|
||||
evaluate("'ab' + null", "abnull", String.class);
|
||||
evaluate("null + 'ab'", "nullab", String.class);
|
||||
|
||||
|
||||
// AST:
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("+3");
|
||||
Assert.assertEquals("+3",expr.toStringAST());
|
||||
expr = (SpelExpression)parser.parseExpression("2+3");
|
||||
Assert.assertEquals("(2 + 3)",expr.toStringAST());
|
||||
|
||||
|
||||
// use as a unary operator
|
||||
evaluate("+5d",5d,Double.class);
|
||||
evaluate("+5L",5L,Long.class);
|
||||
evaluate("+5",5,Integer.class);
|
||||
evaluateAndCheckError("+'abc'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
|
||||
|
||||
// string concatenation
|
||||
evaluate("'abc'+'def'","abcdef",String.class);
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
evaluate("5 + new Integer('37')",42,Integer.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMinus() throws Exception {
|
||||
evaluate("'c' - 2", "a", String.class);
|
||||
@@ -235,13 +235,13 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
Assert.assertEquals("-3",expr.toStringAST());
|
||||
expr = (SpelExpression)parser.parseExpression("2-3");
|
||||
Assert.assertEquals("(2 - 3)",expr.toStringAST());
|
||||
|
||||
|
||||
evaluate("-5d",-5d,Double.class);
|
||||
evaluate("-5L",-5L,Long.class);
|
||||
evaluate("-5",-5,Integer.class);
|
||||
evaluateAndCheckError("-'abc'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testModulus() {
|
||||
evaluate("3%2",1,Integer.class);
|
||||
@@ -259,7 +259,7 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
evaluate("4L DIV 2L",2L,Long.class);
|
||||
evaluateAndCheckError("'abc'/'def'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMathOperatorDivide_ConvertToDouble() {
|
||||
evaluateAndAskForReturnType("8/4", new Double(2.0), Double.class);
|
||||
@@ -282,7 +282,7 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
evaluate("3.0d / 5.0d", 0.6d, Double.class);
|
||||
evaluate("6.0d % 3.5d", 2.5d, Double.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOperatorNames() throws Exception {
|
||||
Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
|
||||
@@ -290,13 +290,13 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("1!=3"));
|
||||
Assert.assertEquals("!=",node.getOperatorName());
|
||||
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3/3"));
|
||||
Assert.assertEquals("/",node.getOperatorName());
|
||||
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3+3"));
|
||||
Assert.assertEquals("+",node.getOperatorName());
|
||||
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3-3"));
|
||||
Assert.assertEquals("-",node.getOperatorName());
|
||||
|
||||
@@ -305,29 +305,29 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3<=4"));
|
||||
Assert.assertEquals("<=",node.getOperatorName());
|
||||
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3*4"));
|
||||
Assert.assertEquals("*",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3%4"));
|
||||
Assert.assertEquals("%",node.getOperatorName());
|
||||
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3>=4"));
|
||||
Assert.assertEquals(">=",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3 between 4"));
|
||||
Assert.assertEquals("between",node.getOperatorName());
|
||||
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3 ^ 4"));
|
||||
Assert.assertEquals("^",node.getOperatorName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOperatorOverloading() {
|
||||
evaluateAndCheckError("'a' * '2'", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
evaluateAndCheckError("'a' ^ '2'", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPower() {
|
||||
evaluate("3^2",9,Integer.class);
|
||||
@@ -335,16 +335,16 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
evaluate("3L^2L",9L,Long.class);
|
||||
evaluate("(2^32)^2",9223372036854775807L,Long.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMixedOperands_FloatsAndDoubles() {
|
||||
evaluate("3.0d + 5.0f", 8.0d, Double.class);
|
||||
evaluate("3.0D - 5.0f", -2.0d, Double.class);
|
||||
evaluate("3.0f * 5.0d", 15.0d, Double.class);
|
||||
evaluate("3.0f / 5.0D", 0.6d, Double.class);
|
||||
evaluate("5.0D % 3f", 2.0d, Double.class);
|
||||
evaluate("5.0D % 3f", 2.0d, Double.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMixedOperands_DoublesAndInts() {
|
||||
evaluate("3.0d + 5", 8.0d, Double.class);
|
||||
@@ -352,10 +352,10 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
evaluate("3.0f * 5", 15.0f, Float.class);
|
||||
evaluate("6.0f / 2", 3.0f, Float.class);
|
||||
evaluate("6.0f / 4", 1.5f, Float.class);
|
||||
evaluate("5.0D % 3", 2.0d, Double.class);
|
||||
evaluate("5.5D % 3", 2.5, Double.class);
|
||||
evaluate("5.0D % 3", 2.0d, Double.class);
|
||||
evaluate("5.5D % 3", 2.5, Double.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStrings() {
|
||||
evaluate("'abc' == 'abc'",true,Boolean.class);
|
||||
@@ -363,7 +363,7 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
evaluate("'abc' != 'abc'",false,Boolean.class);
|
||||
evaluate("'abc' != 'def'",true,Boolean.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLongs() {
|
||||
evaluate("3L == 4L", false, Boolean.class);
|
||||
@@ -374,14 +374,14 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
evaluate("3L + 50L", 53L, Long.class);
|
||||
evaluate("3L - 50L", -47L, Long.class);
|
||||
}
|
||||
|
||||
|
||||
// ---
|
||||
|
||||
|
||||
private Operator getOperatorNode(SpelExpression e) {
|
||||
SpelNode node = e.getAST();
|
||||
return (Operator)findNode(node,Operator.class);
|
||||
}
|
||||
|
||||
|
||||
private SpelNode findNode(SpelNode node, Class<Operator> clazz) {
|
||||
if (clazz.isAssignableFrom(node.getClass())) {
|
||||
return node;
|
||||
@@ -395,5 +395,5 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
/**
|
||||
* Parse some expressions and check we get the AST we expect. Rather than inspecting each node in the AST, we ask it to
|
||||
* write itself to a string form and check that is as expected.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ParsingTests {
|
||||
@@ -160,7 +160,7 @@ public class ParsingTests {
|
||||
public void testElvis() {
|
||||
parseCheck("3?:1", "3 ?: 1");
|
||||
}
|
||||
|
||||
|
||||
// public void testRelOperatorsIn01() {
|
||||
// parseCheck("3 in {1,2,3,4,5}", "(3 in {1,2,3,4,5})");
|
||||
// }
|
||||
@@ -399,14 +399,14 @@ public class ParsingTests {
|
||||
parseCheck("#var1='value1'");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ternary operator
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernaryOperator01() {
|
||||
parseCheck("1>2?3:4","(1 > 2) ? 3 : 4");
|
||||
}
|
||||
|
||||
|
||||
// public void testTernaryOperator01() {
|
||||
// parseCheck("{1}.#isEven(#this) == 'y'?'it is even':'it is odd'",
|
||||
// "({1}.#isEven(#this) == 'y') ? 'it is even' : 'it is odd'");
|
||||
@@ -432,16 +432,16 @@ public class ParsingTests {
|
||||
public void testTypeReferences02() {
|
||||
parseCheck("T(String)");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInlineList1() {
|
||||
parseCheck("{1,2,3,4}");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the same
|
||||
* as the original expression.
|
||||
*
|
||||
*
|
||||
* @param expression the expression to parse *and* the expected value of the string form of the resultant AST
|
||||
*/
|
||||
public void parseCheck(String expression) {
|
||||
@@ -451,7 +451,7 @@ public class ParsingTests {
|
||||
/**
|
||||
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the
|
||||
* expected value.
|
||||
*
|
||||
*
|
||||
* @param expression the expression to parse
|
||||
* @param expectedStringFormOfAST the expected string form of the AST
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
/**
|
||||
* Tests the evaluation of real expressions in a real context.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class PerformanceTests {
|
||||
@@ -40,7 +40,7 @@ public class PerformanceTests {
|
||||
private static EvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
|
||||
@Test
|
||||
public void testPerformanceOfPropertyAccess() throws Exception {
|
||||
long starttime = 0;
|
||||
@@ -54,7 +54,7 @@ public class PerformanceTests {
|
||||
}
|
||||
expr.getValue(eContext);
|
||||
}
|
||||
|
||||
|
||||
starttime = System.currentTimeMillis();
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
Expression expr = parser.parseExpression("placeOfBirth.city");
|
||||
@@ -92,7 +92,7 @@ public class PerformanceTests {
|
||||
public void testPerformanceOfMethodAccess() throws Exception {
|
||||
long starttime = 0;
|
||||
long endtime = 0;
|
||||
|
||||
|
||||
// warmup
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
Expression expr = parser.parseExpression("getPlaceOfBirth().getCity()");
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
///CLOVER:OFF
|
||||
/**
|
||||
* Spring Security scenarios from https://wiki.springsource.com/display/SECURITY/Spring+Security+Expression-based+Authorization
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
@@ -55,7 +55,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
ctx.setRootObject(new Person("Ben"));
|
||||
Boolean value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertFalse(value);
|
||||
|
||||
|
||||
ctx.setRootObject(new Manager("Luke"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
@@ -72,7 +72,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
ctx.addPropertyAccessor(new SecurityPrincipalAccessor());
|
||||
|
||||
|
||||
// Multiple options for supporting this expression: "p.name == principal.name"
|
||||
// (1) If the right person is the root context object then "name==principal.name" is good enough
|
||||
Expression expr = parser.parseRaw("name == principal.name");
|
||||
@@ -80,22 +80,22 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
ctx.setRootObject(new Person("Andy"));
|
||||
Boolean value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
|
||||
|
||||
ctx.setRootObject(new Person("Christian"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertFalse(value);
|
||||
|
||||
// (2) Or register an accessor that can understand 'p' and return the right person
|
||||
expr = parser.parseRaw("p.name == principal.name");
|
||||
|
||||
|
||||
PersonAccessor pAccessor = new PersonAccessor();
|
||||
ctx.addPropertyAccessor(pAccessor);
|
||||
ctx.setRootObject(null);
|
||||
|
||||
|
||||
pAccessor.setPerson(new Person("Andy"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
|
||||
|
||||
pAccessor.setPerson(new Person("Christian"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertFalse(value);
|
||||
@@ -105,18 +105,18 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
public void testScenario03_Arithmetic() throws Exception {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
|
||||
// Might be better with a as a variable although it would work as a property too...
|
||||
// Variable references using a '#'
|
||||
Expression expr = parser.parseRaw("(hasRole('SUPERVISOR') or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
|
||||
|
||||
Boolean value = null;
|
||||
|
||||
|
||||
ctx.setVariable("a",1.0d); // referenced as #a in the expression
|
||||
ctx.setRootObject(new Supervisor("Ben")); // so non-qualified references 'hasRole()' 'hasIpAddress()' are invoked against it
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
|
||||
|
||||
ctx.setRootObject(new Manager("Luke"));
|
||||
ctx.setVariable("a",1.043d);
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
@@ -128,7 +128,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
public void testScenario04_ControllingWhichMethodsRun() throws Exception {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
|
||||
ctx.setRootObject(new Supervisor("Ben")); // so non-qualified references 'hasRole()' 'hasIpAddress()' are invoked against it);
|
||||
|
||||
ctx.addMethodResolver(new MyMethodResolver()); // NEEDS TO OVERRIDE THE REFLECTION ONE - SHOW REORDERING MECHANISM
|
||||
@@ -138,17 +138,17 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
Expression expr = parser.parseRaw("(hasRole(3) or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
|
||||
|
||||
Boolean value = null;
|
||||
|
||||
|
||||
ctx.setVariable("a",1.0d); // referenced as #a in the expression
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
|
||||
|
||||
// ctx.setRootObject(new Manager("Luke"));
|
||||
// ctx.setVariable("a",1.043d);
|
||||
// value = (Boolean)expr.getValue(ctx,Boolean.class);
|
||||
// assertFalse(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static class Person {
|
||||
|
||||
@@ -236,7 +236,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
public Class<?>[] getSpecificTargetClasses() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||
|
||||
/**
|
||||
* Tests set value expressions.
|
||||
*
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Andy Clement
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
public void testSetProperty() {
|
||||
setValue("wonNobelPrize", true);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetNestedProperty() {
|
||||
setValue("placeOfBirth.city", "Wien");
|
||||
@@ -89,17 +89,17 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
setValueExpectError("arrayContainer.bytes[1]", "NaB");
|
||||
setValueExpectError("arrayContainer.chars[1]", "NaC");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetArrayElementNestedValue() {
|
||||
setValue("placesLived[0].city", "Wien");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetListElementValue() {
|
||||
setValue("placesLivedList[0]", new PlaceOfBirth("Wien"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetGenericListElementValueTypeCoersion() {
|
||||
// TODO currently failing since setValue does a getValue and "Wien" string != PlaceOfBirth - check with andy
|
||||
@@ -110,7 +110,7 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
public void testSetGenericListElementValueTypeCoersionOK() {
|
||||
setValue("booleanList[0]", "true", Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetListElementNestedValue() {
|
||||
setValue("placesLived[0].city", "Wien");
|
||||
@@ -121,17 +121,17 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
setValueExpectError("placesLived[23]", "Wien");
|
||||
setValueExpectError("placesLivedList[23]", "Wien");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetMapElements() {
|
||||
setValue("testMap['montag']","lundi");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIndexingIntoUnsupportedType() {
|
||||
setValueExpectError("'hello'[3]", 'p');
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetPropertyTypeCoersion() {
|
||||
setValue("publicBoolean", "true", Boolean.TRUE);
|
||||
@@ -141,9 +141,9 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
public void testSetPropertyTypeCoersionThroughSetter() {
|
||||
setValue("SomeProperty", "true", Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAssign() throws Exception {
|
||||
public void testAssign() throws Exception {
|
||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parse("publicName='Andy'");
|
||||
Assert.assertFalse(e.isWritable(eContext));
|
||||
@@ -158,32 +158,32 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parse("mapOfStringToBoolean[42]");
|
||||
Assert.assertNull(e.getValue(eContext));
|
||||
|
||||
|
||||
// Key should be coerced to string representation of 42
|
||||
e.setValue(eContext, "true");
|
||||
|
||||
|
||||
// All keys should be strings
|
||||
Set ks = parse("mapOfStringToBoolean.keySet()").getValue(eContext,Set.class);
|
||||
for (Object o: ks) {
|
||||
Assert.assertEquals(String.class,o.getClass());
|
||||
}
|
||||
|
||||
|
||||
// All values should be booleans
|
||||
Collection vs = parse("mapOfStringToBoolean.values()").getValue(eContext,Collection.class);
|
||||
for (Object o: vs) {
|
||||
Assert.assertEquals(Boolean.class,o.getClass());
|
||||
}
|
||||
|
||||
|
||||
// One final test check coercion on the key for a map lookup
|
||||
Object o = e.getValue(eContext);
|
||||
Assert.assertEquals(Boolean.TRUE,o);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Expression parse(String expressionString) throws Exception {
|
||||
return parser.parseExpression(expressionString);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call setValue() but expect it to fail.
|
||||
*/
|
||||
|
||||
@@ -38,17 +38,17 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||
|
||||
/**
|
||||
* Test the examples specified in the documentation.
|
||||
*
|
||||
*
|
||||
* NOTE: any outgoing changes from this file upon synchronizing with the repo may indicate that
|
||||
* you need to update the documentation too !
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
static Inventor tesla ;
|
||||
static Inventor pupin ;
|
||||
|
||||
|
||||
static {
|
||||
GregorianCalendar c = new GregorianCalendar();
|
||||
c.set(1856, 7, 9);
|
||||
@@ -60,18 +60,18 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
pupin = new Inventor("Pupin", c.getTime(), "Idvor");
|
||||
pupin.setPlaceOfBirth(new PlaceOfBirth("Idvor"));
|
||||
|
||||
|
||||
}
|
||||
static class IEEE {
|
||||
private String name;
|
||||
|
||||
|
||||
|
||||
|
||||
public Inventor[] Members = new Inventor[1];
|
||||
public List Members2 = new ArrayList();
|
||||
public Map<String,Object> officers = new HashMap<String,Object>();
|
||||
|
||||
|
||||
public List<Map<String, Object>> reverse = new ArrayList<Map<String, Object>>();
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
IEEE() {
|
||||
officers.put("president",pupin);
|
||||
@@ -80,28 +80,28 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
officers.put("advisors",linv);
|
||||
Members2.add(tesla);
|
||||
Members2.add(pupin);
|
||||
|
||||
|
||||
reverse.add(officers);
|
||||
}
|
||||
|
||||
|
||||
public boolean isMember(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String n) { this.name = n; }
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMethodInvocation() {
|
||||
evaluate("'Hello World'.concat('!')","Hello World!",String.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBeanPropertyAccess() {
|
||||
evaluate("new String('Hello World'.bytes)","Hello World",String.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testArrayLengthAccess() {
|
||||
evaluate("'Hello World'.bytes.length",11,Integer.class);
|
||||
@@ -123,12 +123,12 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
String name = (String) exp.getValue(context);
|
||||
Assert.assertEquals("Nikola Tesla",name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityCheck() throws Exception {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setRootObject(tesla);
|
||||
|
||||
@@ -136,14 +136,14 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
boolean isEqual = exp.getValue(context, Boolean.class); // evaluates to true
|
||||
Assert.assertTrue(isEqual);
|
||||
}
|
||||
|
||||
|
||||
// Section 7.4.1
|
||||
|
||||
|
||||
@Test
|
||||
public void testXMLBasedConfig() {
|
||||
evaluate("(T(java.lang.Math).random() * 100.0 )>0",true,Boolean.class);
|
||||
}
|
||||
|
||||
|
||||
// Section 7.5
|
||||
@Test
|
||||
public void testLiterals() throws Exception {
|
||||
@@ -151,16 +151,16 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
String helloWorld = (String) parser.parseExpression("'Hello World'").getValue(); // evals to "Hello World"
|
||||
Assert.assertEquals("Hello World",helloWorld);
|
||||
|
||||
double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();
|
||||
|
||||
double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();
|
||||
Assert.assertEquals(6.0221415E+23,avogadrosNumber);
|
||||
|
||||
|
||||
int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue(); // evals to 2147483647
|
||||
Assert.assertEquals(Integer.MAX_VALUE,maxValue);
|
||||
|
||||
|
||||
boolean trueValue = (Boolean) parser.parseExpression("true").getValue();
|
||||
Assert.assertTrue(trueValue);
|
||||
|
||||
|
||||
Object nullValue = parser.parseExpression("null").getValue();
|
||||
Assert.assertNull(nullValue);
|
||||
}
|
||||
@@ -170,11 +170,11 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
int year = (Integer) parser.parseExpression("Birthdate.Year + 1900").getValue(context); // 1856
|
||||
Assert.assertEquals(1856,year);
|
||||
|
||||
|
||||
String city = (String) parser.parseExpression("placeOfBirth.City").getValue(context);
|
||||
Assert.assertEquals("SmilJan",city);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPropertyNavigation() throws Exception {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
@@ -184,7 +184,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
// teslaContext.setRootObject(tesla);
|
||||
|
||||
// evaluates to "Induction motor"
|
||||
String invention = parser.parseExpression("inventions[3]").getValue(teslaContext, String.class);
|
||||
String invention = parser.parseExpression("inventions[3]").getValue(teslaContext, String.class);
|
||||
Assert.assertEquals("Induction motor",invention);
|
||||
|
||||
// Members List
|
||||
@@ -196,14 +196,14 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
// evaluates to "Nikola Tesla"
|
||||
String name = parser.parseExpression("Members[0].Name").getValue(societyContext, String.class);
|
||||
Assert.assertEquals("Nikola Tesla",name);
|
||||
|
||||
|
||||
// List and Array navigation
|
||||
// evaluates to "Wireless communication"
|
||||
invention = parser.parseExpression("Members[0].Inventions[6]").getValue(societyContext, String.class);
|
||||
Assert.assertEquals("Wireless communication",invention);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testDictionaryAccess() throws Exception {
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
@@ -217,14 +217,14 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
// setting values
|
||||
Inventor i = parser.parseExpression("officers['advisors'][0]").getValue(societyContext,Inventor.class);
|
||||
Assert.assertEquals("Nikola Tesla",i.getName());
|
||||
|
||||
|
||||
parser.parseExpression("officers['advisors'][0].PlaceOfBirth.Country").setValue(societyContext, "Croatia");
|
||||
|
||||
Inventor i2 = parser.parseExpression("reverse[0]['advisors'][0]").getValue(societyContext,Inventor.class);
|
||||
Assert.assertEquals("Nikola Tesla",i2.getName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 7.5.3
|
||||
|
||||
@Test
|
||||
@@ -232,16 +232,16 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
// string literal, evaluates to "bc"
|
||||
String c = parser.parseExpression("'abc'.substring(1, 3)").getValue(String.class);
|
||||
Assert.assertEquals("bc",c);
|
||||
|
||||
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
// evaluates to true
|
||||
boolean isMember = parser.parseExpression("isMember('Mihajlo Pupin')").getValue(societyContext, Boolean.class);
|
||||
Assert.assertTrue(isMember);
|
||||
}
|
||||
|
||||
|
||||
// 7.5.4.1
|
||||
|
||||
|
||||
@Test
|
||||
public void testRelationalOperators() throws Exception {
|
||||
boolean result = parser.parseExpression("2 == 2").getValue(Boolean.class);
|
||||
@@ -249,18 +249,18 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
// evaluates to false
|
||||
result = parser.parseExpression("2 < -5.0").getValue(Boolean.class);
|
||||
Assert.assertFalse(result);
|
||||
|
||||
|
||||
// evaluates to true
|
||||
result = parser.parseExpression("'black' < 'block'").getValue(Boolean.class);
|
||||
Assert.assertTrue(result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOtherOperators() throws Exception {
|
||||
// evaluates to false
|
||||
boolean falseValue = parser.parseExpression("'xyz' instanceof T(int)").getValue(Boolean.class);
|
||||
Assert.assertFalse(falseValue);
|
||||
|
||||
|
||||
// evaluates to true
|
||||
boolean trueValue = parser.parseExpression("'5.00' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
|
||||
Assert.assertTrue(trueValue);
|
||||
@@ -269,15 +269,15 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
falseValue = parser.parseExpression("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
|
||||
Assert.assertFalse(falseValue);
|
||||
}
|
||||
|
||||
|
||||
// 7.5.4.2
|
||||
|
||||
|
||||
@Test
|
||||
public void testLogicalOperators() throws Exception {
|
||||
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
|
||||
|
||||
// -- AND --
|
||||
|
||||
// evaluates to false
|
||||
@@ -292,12 +292,12 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
// evaluates to true
|
||||
trueValue = parser.parseExpression("true or false").getValue(Boolean.class);
|
||||
Assert.assertTrue(trueValue);
|
||||
|
||||
|
||||
// evaluates to true
|
||||
expression = "isMember('Nikola Tesla') or isMember('Albert Einstien')";
|
||||
trueValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
|
||||
Assert.assertTrue(trueValue);
|
||||
|
||||
|
||||
// -- NOT --
|
||||
|
||||
// evaluates to false
|
||||
@@ -310,56 +310,56 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
falseValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
|
||||
Assert.assertFalse(falseValue);
|
||||
}
|
||||
|
||||
|
||||
// 7.5.4.3
|
||||
|
||||
|
||||
@Test
|
||||
public void testNumericalOperators() throws Exception {
|
||||
// Addition
|
||||
int two = parser.parseExpression("1 + 1").getValue(Integer.class); // 2
|
||||
Assert.assertEquals(2,two);
|
||||
|
||||
|
||||
String testString = parser.parseExpression("'test' + ' ' + 'string'").getValue(String.class); // 'test string'
|
||||
Assert.assertEquals("test string",testString);
|
||||
|
||||
|
||||
// Subtraction
|
||||
int four = parser.parseExpression("1 - -3").getValue(Integer.class); // 4
|
||||
Assert.assertEquals(4,four);
|
||||
|
||||
|
||||
double d = parser.parseExpression("1000.00 - 1e4").getValue(Double.class); // -9000
|
||||
Assert.assertEquals(-9000.0d,d);
|
||||
|
||||
|
||||
// Multiplication
|
||||
int six = parser.parseExpression("-2 * -3").getValue(Integer.class); // 6
|
||||
Assert.assertEquals(6,six);
|
||||
|
||||
|
||||
double twentyFour = parser.parseExpression("2.0 * 3e0 * 4").getValue(Double.class); // 24.0
|
||||
Assert.assertEquals(24.0d,twentyFour);
|
||||
|
||||
|
||||
// Division
|
||||
int minusTwo = parser.parseExpression("6 / -3").getValue(Integer.class); // -2
|
||||
Assert.assertEquals(-2,minusTwo);
|
||||
|
||||
|
||||
double one = parser.parseExpression("8.0 / 4e0 / 2").getValue(Double.class); // 1.0
|
||||
Assert.assertEquals(1.0d,one);
|
||||
|
||||
// Modulus
|
||||
int three = parser.parseExpression("7 % 4").getValue(Integer.class); // 3
|
||||
Assert.assertEquals(3,three);
|
||||
|
||||
|
||||
int oneInt = parser.parseExpression("8 / 5 % 2").getValue(Integer.class); // 1
|
||||
Assert.assertEquals(1,oneInt);
|
||||
|
||||
|
||||
// Operator precedence
|
||||
int minusTwentyOne = parser.parseExpression("1+2-3*8").getValue(Integer.class); // -21
|
||||
Assert.assertEquals(-21,minusTwentyOne);
|
||||
}
|
||||
|
||||
// 7.5.5
|
||||
|
||||
|
||||
@Test
|
||||
public void testAssignment() throws Exception {
|
||||
Inventor inventor = new Inventor();
|
||||
Inventor inventor = new Inventor();
|
||||
StandardEvaluationContext inventorContext = new StandardEvaluationContext();
|
||||
inventorContext.setRootObject(inventor);
|
||||
|
||||
@@ -372,9 +372,9 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
Assert.assertEquals("Alexandar Seovic",parser.parseExpression("foo").getValue(inventorContext,String.class));
|
||||
Assert.assertEquals("Alexandar Seovic",aleks);
|
||||
}
|
||||
|
||||
|
||||
// 7.5.6
|
||||
|
||||
|
||||
@Test
|
||||
public void testTypes() throws Exception {
|
||||
Class dateClass = parser.parseExpression("T(java.util.Date)").getValue(Class.class);
|
||||
@@ -382,22 +382,22 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
boolean trueValue = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class);
|
||||
Assert.assertTrue(trueValue);
|
||||
}
|
||||
|
||||
|
||||
// 7.5.7
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructors() throws Exception {
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
Inventor einstein =
|
||||
Inventor einstein =
|
||||
parser.parseExpression("new org.springframework.expression.spel.testresources.Inventor('Albert Einstein',new java.util.Date(), 'German')").getValue(Inventor.class);
|
||||
Assert.assertEquals("Albert Einstein", einstein.getName());
|
||||
//create new inventor instance within add method of List
|
||||
parser.parseExpression("Members2.add(new org.springframework.expression.spel.testresources.Inventor('Albert Einstein', 'German'))").getValue(societyContext);
|
||||
}
|
||||
|
||||
|
||||
// 7.5.8
|
||||
|
||||
|
||||
@Test
|
||||
public void testVariables() throws Exception {
|
||||
Inventor tesla = new Inventor("Nikola Tesla", "Serbian");
|
||||
@@ -410,7 +410,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
Assert.assertEquals("Mike Tesla",tesla.getFoo());
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSpecialVariables() throws Exception {
|
||||
@@ -427,45 +427,45 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
List<Integer> primesGreaterThanTen = (List<Integer>) parser.parseExpression("#primes.?[#this>10]").getValue(context);
|
||||
Assert.assertEquals("[11, 13, 17]",primesGreaterThanTen.toString());
|
||||
}
|
||||
|
||||
|
||||
// 7.5.9
|
||||
|
||||
|
||||
@Test
|
||||
public void testFunctions() throws Exception {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
|
||||
context.registerFunction("reverseString",
|
||||
context.registerFunction("reverseString",
|
||||
StringUtils.class.getDeclaredMethod("reverseString", new Class[] { String.class }));
|
||||
|
||||
String helloWorldReversed = parser.parseExpression("#reverseString('hello world')").getValue(context, String.class);
|
||||
Assert.assertEquals("dlrow olleh",helloWorldReversed);
|
||||
}
|
||||
|
||||
|
||||
// 7.5.10
|
||||
|
||||
|
||||
@Test
|
||||
public void testTernary() throws Exception {
|
||||
String falseString = parser.parseExpression("false ? 'trueExp' : 'falseExp'").getValue(String.class);
|
||||
Assert.assertEquals("falseExp",falseString);
|
||||
|
||||
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
|
||||
|
||||
|
||||
parser.parseExpression("Name").setValue(societyContext, "IEEE");
|
||||
societyContext.setVariable("queryName", "Nikola Tesla");
|
||||
|
||||
String expression = "isMember(#queryName)? #queryName + ' is a member of the ' " +
|
||||
String expression = "isMember(#queryName)? #queryName + ' is a member of the ' " +
|
||||
"+ Name + ' Society' : #queryName + ' is not a member of the ' + Name + ' Society'";
|
||||
|
||||
String queryResultString = parser.parseExpression(expression).getValue(societyContext, String.class);
|
||||
Assert.assertEquals("Nikola Tesla is a member of the IEEE Society",queryResultString);
|
||||
// queryResultString = "Nikola Tesla is a member of the IEEE Society"
|
||||
}
|
||||
|
||||
|
||||
// 7.5.11
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSelection() throws Exception {
|
||||
@@ -475,16 +475,16 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
Assert.assertEquals(1,list.size());
|
||||
Assert.assertEquals("Nikola Tesla",list.get(0).getName());
|
||||
}
|
||||
|
||||
|
||||
// 7.5.12
|
||||
|
||||
|
||||
@Test
|
||||
public void testTemplating() throws Exception {
|
||||
String randomPhrase =
|
||||
String randomPhrase =
|
||||
parser.parseExpression("random number is ${T(java.lang.Math).random()}", new TemplatedParserContext()).getValue(String.class);
|
||||
Assert.assertTrue(randomPhrase.startsWith("random number"));
|
||||
}
|
||||
|
||||
|
||||
static class TemplatedParserContext implements ParserContext {
|
||||
|
||||
public String getExpressionPrefix() {
|
||||
@@ -494,12 +494,12 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
public String getExpressionSuffix() {
|
||||
return "}";
|
||||
}
|
||||
|
||||
|
||||
public boolean isTemplate() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class StringUtils {
|
||||
|
||||
public static String reverseString(String input) {
|
||||
@@ -510,6 +510,6 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
return backwards.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
/**
|
||||
* Utilities for working with Spring Expressions.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class SpelUtilities {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.expression.spel.support.StandardTypeLocator;
|
||||
|
||||
/**
|
||||
* Unit tests for type comparison
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class StandardTypeLocatorTests {
|
||||
@@ -35,7 +35,7 @@ public class StandardTypeLocatorTests {
|
||||
StandardTypeLocator locator = new StandardTypeLocator();
|
||||
Assert.assertEquals(Integer.class,locator.findType("java.lang.Integer"));
|
||||
Assert.assertEquals(String.class,locator.findType("java.lang.String"));
|
||||
|
||||
|
||||
List<String> prefixes = locator.getImportPrefixes();
|
||||
Assert.assertEquals(1,prefixes.size());
|
||||
Assert.assertTrue(prefixes.contains("java.lang"));
|
||||
@@ -44,7 +44,7 @@ public class StandardTypeLocatorTests {
|
||||
Assert.assertEquals(Boolean.class,locator.findType("Boolean"));
|
||||
// currently does not know about java.util by default
|
||||
// assertEquals(java.util.List.class,locator.findType("List"));
|
||||
|
||||
|
||||
try {
|
||||
locator.findType("URL");
|
||||
Assert.fail("Should have failed");
|
||||
@@ -54,7 +54,7 @@ public class StandardTypeLocatorTests {
|
||||
}
|
||||
locator.registerImport("java.net");
|
||||
Assert.assertEquals(java.net.URL.class,locator.findType("URL"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
Expression expr = parser.parseExpression("${'hello'} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Object o = expr.getValue();
|
||||
Assert.assertEquals("hello world", o.toString());
|
||||
|
||||
|
||||
expr = parser.parseExpression("", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
o = expr.getValue();
|
||||
Assert.assertEquals("", o.toString());
|
||||
@@ -135,7 +135,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
Assert.assertEquals(String.class,ex.getValueType(ctx, new Rooty()));
|
||||
Assert.assertEquals(String.class,ex.getValueTypeDescriptor(new Rooty()).getType());
|
||||
Assert.assertEquals(String.class,ex.getValueTypeDescriptor(ctx, new Rooty()).getType());
|
||||
|
||||
|
||||
try {
|
||||
ex.setValue(ctx, null);
|
||||
Assert.fail();
|
||||
@@ -155,9 +155,9 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
// success
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Rooty {}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNestedExpressions() throws Exception {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
@@ -179,22 +179,22 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
Assert.assertEquals("hello 4 10 world",s);
|
||||
|
||||
|
||||
try {
|
||||
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5] world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Assert.fail("Should have failed");
|
||||
} catch (ParseException pe) {
|
||||
Assert.assertEquals("No ending suffix '}' for expression starting at character 41: ${listOfNumbersUpToTen.$[#this>5] world",pe.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1==3]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Assert.fail("Should have failed");
|
||||
} catch (ParseException pe) {
|
||||
Assert.assertEquals("Found closing '}' at position 74 but most recent opening is '[' at position 30",pe.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
public void testClashingWithSuffixes() throws Exception {
|
||||
@@ -211,7 +211,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
Assert.assertEquals("hello 7 wo}rld",s);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParsingNormalExpressionThroughTemplateParser() throws Exception {
|
||||
Expression expr = parser.parseExpression("1+2+3");
|
||||
@@ -219,7 +219,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
expr = parser.parseExpression("1+2+3",null);
|
||||
Assert.assertEquals(6,expr.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testErrorCases() throws Exception {
|
||||
try {
|
||||
@@ -240,29 +240,29 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
Assert.fail("Should have failed");
|
||||
} catch (ParseException pe) {
|
||||
Assert.assertEquals("No expression defined within delimiter '${}' at character 6",pe.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateParserContext() {
|
||||
TemplateParserContext tpc = new TemplateParserContext("abc","def");
|
||||
Assert.assertEquals("abc", tpc.getExpressionPrefix());
|
||||
Assert.assertEquals("def", tpc.getExpressionSuffix());
|
||||
Assert.assertEquals("def", tpc.getExpressionSuffix());
|
||||
Assert.assertTrue(tpc.isTemplate());
|
||||
|
||||
tpc = new TemplateParserContext();
|
||||
Assert.assertEquals("#{", tpc.getExpressionPrefix());
|
||||
Assert.assertEquals("}", tpc.getExpressionSuffix());
|
||||
Assert.assertEquals("}", tpc.getExpressionSuffix());
|
||||
Assert.assertTrue(tpc.isTemplate());
|
||||
|
||||
|
||||
ParserContext pc = ParserContext.TEMPLATE_EXPRESSION;
|
||||
Assert.assertEquals("#{", pc.getExpressionPrefix());
|
||||
Assert.assertEquals("}", pc.getExpressionSuffix());
|
||||
Assert.assertEquals("}", pc.getExpressionSuffix());
|
||||
Assert.assertTrue(pc.isTemplate());
|
||||
}
|
||||
|
||||
|
||||
// ---
|
||||
|
||||
|
||||
private void checkString(String expectedString, Object value) {
|
||||
if (!(value instanceof String)) {
|
||||
Assert.fail("Result was not a string, it was of type " + value.getClass() + " (value=" + value + ")");
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
/**
|
||||
* Tests the evaluation of expressions that access variables and functions (lambda/java).
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class VariableAndFunctionTests extends ExpressionTestCase {
|
||||
@@ -35,7 +35,7 @@ public class VariableAndFunctionTests extends ExpressionTestCase {
|
||||
evaluate("#answer", "42", Integer.class, SHOULD_BE_WRITABLE);
|
||||
evaluate("#answer / 2", 21, Integer.class, SHOULD_NOT_BE_WRITABLE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testVariableAccess_WellKnownVariables() {
|
||||
evaluate("#this.getName()","Nikola Tesla",String.class);
|
||||
|
||||
@@ -28,13 +28,13 @@ import static org.junit.Assert.*;
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class FormatHelperTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void formatMethodWithSingleArgumentForMessage() {
|
||||
String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string")));
|
||||
assertEquals("foo(java.lang.String)", message);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void formatMethodWithMultipleArgumentsForMessage() {
|
||||
String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string"), TypeDescriptor.forObject(Integer.valueOf(5))));
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.expression.spel.support.ReflectionHelper.ArgsMatchKin
|
||||
|
||||
/**
|
||||
* Tests for any helper code.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
@@ -53,7 +53,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
Assert.assertEquals("int[][]",FormatHelper.formatClassNameForMessage(new int[1][2].getClass()));
|
||||
Assert.assertEquals("null",FormatHelper.formatClassNameForMessage(null));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void testFormatHelperForMethod() {
|
||||
@@ -62,7 +62,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
Assert.assertEquals("boo()",FormatHelper.formatMethodForMessage("boo"));
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Test
|
||||
public void testUtilities() throws ParseException {
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("3+4+5+6+7-2");
|
||||
@@ -93,52 +93,52 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
Assert.assertTrue(s.indexOf("===> Expression '3+4+5+6+7-2' - AST start")!=-1);
|
||||
Assert.assertTrue(s.indexOf(" OpPlus value:((((3 + 4) + 5) + 6) + 7) #children:2")!=-1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTypedValue() {
|
||||
TypedValue tValue = new TypedValue("hello");
|
||||
Assert.assertEquals(String.class,tValue.getTypeDescriptor().getType());
|
||||
Assert.assertEquals("TypedValue: 'hello' of [java.lang.String]",tValue.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReflectionHelperCompareArguments_ExactMatching() {
|
||||
StandardTypeConverter typeConverter = new StandardTypeConverter();
|
||||
|
||||
|
||||
// Calling foo(String) with (String) is exact match
|
||||
checkMatch(new Class[]{String.class},new Class[]{String.class},typeConverter,ArgsMatchKind.EXACT);
|
||||
|
||||
|
||||
// Calling foo(String,Integer) with (String,Integer) is exact match
|
||||
checkMatch(new Class[]{String.class,Integer.class},new Class[]{String.class,Integer.class},typeConverter,ArgsMatchKind.EXACT);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReflectionHelperCompareArguments_CloseMatching() {
|
||||
StandardTypeConverter typeConverter = new StandardTypeConverter();
|
||||
|
||||
|
||||
// Calling foo(List) with (ArrayList) is close match (no conversion required)
|
||||
checkMatch(new Class[]{ArrayList.class},new Class[]{List.class},typeConverter,ArgsMatchKind.CLOSE);
|
||||
|
||||
|
||||
// Passing (Sub,String) on call to foo(Super,String) is close match
|
||||
checkMatch(new Class[]{Sub.class,String.class},new Class[]{Super.class,String.class},typeConverter,ArgsMatchKind.CLOSE);
|
||||
|
||||
|
||||
// Passing (String,Sub) on call to foo(String,Super) is close match
|
||||
checkMatch(new Class[]{String.class,Sub.class},new Class[]{String.class,Super.class},typeConverter,ArgsMatchKind.CLOSE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReflectionHelperCompareArguments_RequiresConversionMatching() {
|
||||
StandardTypeConverter typeConverter = new StandardTypeConverter();
|
||||
|
||||
|
||||
// Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one
|
||||
checkMatch(new Class[]{String.class,Integer.TYPE},new Class[]{String.class,Integer.class},typeConverter,ArgsMatchKind.CLOSE,1);
|
||||
|
||||
// Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero
|
||||
checkMatch(new Class[]{Integer.TYPE,String.class},new Class[]{Integer.class, String.class},typeConverter,ArgsMatchKind.CLOSE,0);
|
||||
|
||||
|
||||
// Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero
|
||||
checkMatch(new Class[]{Integer.TYPE,Sub.class},new Class[]{Integer.class, Super.class},typeConverter,ArgsMatchKind.CLOSE,0);
|
||||
|
||||
|
||||
// Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two
|
||||
// TODO checkMatch(new Class[]{Integer.TYPE,Sub.class,Boolean.TYPE},new Class[]{Integer.class, Super.class,Boolean.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,0,2);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testReflectionHelperCompareArguments_NotAMatch() {
|
||||
StandardTypeConverter typeConverter = new StandardTypeConverter();
|
||||
|
||||
|
||||
// Passing (Super,String) on call to foo(Sub,String) is not a match
|
||||
checkMatch(new Class[]{Super.class,String.class},new Class[]{Sub.class,String.class},typeConverter,null);
|
||||
}
|
||||
@@ -156,16 +156,16 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
StandardTypeConverter tc = new StandardTypeConverter();
|
||||
Class<?> stringArrayClass = new String[0].getClass();
|
||||
Class<?> integerArrayClass = new Integer[0].getClass();
|
||||
|
||||
|
||||
// Passing (String[]) on call to (String[]) is exact match
|
||||
checkMatch2(new Class[]{stringArrayClass},new Class[]{stringArrayClass},tc,ArgsMatchKind.EXACT);
|
||||
|
||||
|
||||
// Passing (Integer, String[]) on call to (Integer, String[]) is exact match
|
||||
checkMatch2(new Class[]{Integer.class,stringArrayClass},new Class[]{Integer.class,stringArrayClass},tc,ArgsMatchKind.EXACT);
|
||||
|
||||
// Passing (String, Integer, String[]) on call to (String, String, String[]) is exact match
|
||||
checkMatch2(new Class[]{String.class,Integer.class,stringArrayClass},new Class[]{String.class,Integer.class,stringArrayClass},tc,ArgsMatchKind.EXACT);
|
||||
|
||||
|
||||
// Passing (Sub, String[]) on call to (Super, String[]) is exact match
|
||||
checkMatch2(new Class[]{Sub.class,stringArrayClass},new Class[]{Super.class,stringArrayClass},tc,ArgsMatchKind.CLOSE);
|
||||
|
||||
@@ -174,10 +174,10 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
|
||||
// Passing (Integer, Sub, String[]) on call to (String, Super, String[]) is exact match
|
||||
checkMatch2(new Class[]{Integer.class,Sub.class,String[].class},new Class[]{String.class,Super.class,String[].class},tc,ArgsMatchKind.REQUIRES_CONVERSION,0);
|
||||
|
||||
|
||||
// Passing (String) on call to (String[]) is exact match
|
||||
checkMatch2(new Class[]{String.class},new Class[]{stringArrayClass},tc,ArgsMatchKind.EXACT);
|
||||
|
||||
|
||||
// Passing (Integer,String) on call to (Integer,String[]) is exact match
|
||||
checkMatch2(new Class[]{Integer.class,String.class},new Class[]{Integer.class,stringArrayClass},tc,ArgsMatchKind.EXACT);
|
||||
|
||||
@@ -186,7 +186,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
|
||||
// Passing (Sub) on call to (Super[]) is close match
|
||||
checkMatch2(new Class[]{Sub.class},new Class[]{new Super[0].getClass()},tc,ArgsMatchKind.CLOSE);
|
||||
|
||||
|
||||
// Passing (Super) on call to (Sub[]) is not a match
|
||||
checkMatch2(new Class[]{Super.class},new Class[]{new Sub[0].getClass()},tc,null);
|
||||
|
||||
@@ -261,17 +261,17 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
catch (SpelEvaluationException se) {
|
||||
Assert.assertEquals(SpelMessage.TYPE_CONVERSION_ERROR,se.getMessageCode());
|
||||
}
|
||||
|
||||
|
||||
// null value
|
||||
args = new Object[]{3,null,3.0f};
|
||||
ReflectionHelper.convertAllArguments(tc, args, twoArg);
|
||||
checkArguments(args,"3",null,"3.0");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetupArguments() {
|
||||
Object[] newArray = ReflectionHelper.setupArgumentsForVarargsInvocation(new Class[]{new String[0].getClass()},"a","b","c");
|
||||
|
||||
|
||||
Assert.assertEquals(1,newArray.length);
|
||||
Object firstParam = newArray[0];
|
||||
Assert.assertEquals(String.class,firstParam.getClass().getComponentType());
|
||||
@@ -281,7 +281,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
Assert.assertEquals("b",firstParamArray[1]);
|
||||
Assert.assertEquals("c",firstParamArray[2]);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReflectivePropertyResolver() throws Exception {
|
||||
ReflectivePropertyAccessor rpr = new ReflectivePropertyAccessor();
|
||||
@@ -295,16 +295,16 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
Assert.assertTrue(rpr.canRead(ctx, t, "field"));
|
||||
Assert.assertEquals(3,rpr.read(ctx, t, "field").getValue());
|
||||
Assert.assertEquals(3,rpr.read(ctx, t, "field").getValue()); // cached accessor used
|
||||
|
||||
|
||||
Assert.assertTrue(rpr.canWrite(ctx, t, "property"));
|
||||
rpr.write(ctx, t, "property","goodbye");
|
||||
rpr.write(ctx, t, "property","goodbye"); // cached accessor used
|
||||
|
||||
|
||||
Assert.assertTrue(rpr.canWrite(ctx, t, "field"));
|
||||
rpr.write(ctx, t, "field",12);
|
||||
rpr.write(ctx, t, "field",12);
|
||||
|
||||
// Attempted write as first activity on this field and property to drive testing
|
||||
// Attempted write as first activity on this field and property to drive testing
|
||||
// of populating type descriptor cache
|
||||
rpr.write(ctx,t,"field2",3);
|
||||
rpr.write(ctx, t, "property2","doodoo");
|
||||
@@ -330,7 +330,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
Assert.assertEquals("id",rpr.read(ctx,t,"Id").getValue());
|
||||
Assert.assertTrue(rpr.canRead(ctx,t,"Id"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOptimalReflectivePropertyResolver() throws Exception {
|
||||
ReflectivePropertyAccessor rpr = new ReflectivePropertyAccessor();
|
||||
@@ -340,7 +340,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
// Assert.assertTrue(rpr.canRead(ctx, t, "property"));
|
||||
// Assert.assertEquals("hello",rpr.read(ctx, t, "property").getValue());
|
||||
// Assert.assertEquals("hello",rpr.read(ctx, t, "property").getValue()); // cached accessor used
|
||||
|
||||
|
||||
PropertyAccessor optA = rpr.createOptimalAccessor(ctx, t, "property");
|
||||
Assert.assertTrue(optA.canRead(ctx, t, "property"));
|
||||
Assert.assertFalse(optA.canRead(ctx, t, "property2"));
|
||||
@@ -405,7 +405,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// test classes
|
||||
static class Tester {
|
||||
@@ -426,7 +426,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
public void setProperty2(String value) { property2 = value; }
|
||||
|
||||
public String getProperty3() { return property3; }
|
||||
|
||||
|
||||
public boolean isProperty4() { return property4; }
|
||||
|
||||
public String getiD() { return iD; }
|
||||
@@ -435,17 +435,17 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
|
||||
public String getID() { return ID; }
|
||||
}
|
||||
|
||||
|
||||
static class Super {
|
||||
}
|
||||
|
||||
|
||||
static class Sub extends Super {
|
||||
}
|
||||
|
||||
|
||||
static class Unconvertable {}
|
||||
|
||||
|
||||
// ---
|
||||
|
||||
|
||||
/**
|
||||
* Used to validate the match returned from a compareArguments call.
|
||||
*/
|
||||
@@ -459,10 +459,10 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
|
||||
if (expectedMatchKind==ArgsMatchKind.EXACT) {
|
||||
Assert.assertTrue(matchInfo.isExactMatch());
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
} else if (expectedMatchKind==ArgsMatchKind.CLOSE) {
|
||||
Assert.assertTrue(matchInfo.isCloseMatch());
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
} else if (expectedMatchKind==ArgsMatchKind.REQUIRES_CONVERSION) {
|
||||
Assert.assertTrue("expected to be a match requiring conversion, but was "+matchInfo,matchInfo.isMatchRequiringConversion());
|
||||
if (argsForConversion==null) {
|
||||
@@ -488,10 +488,10 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
|
||||
if (expectedMatchKind==ArgsMatchKind.EXACT) {
|
||||
Assert.assertTrue(matchInfo.isExactMatch());
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
} else if (expectedMatchKind==ArgsMatchKind.CLOSE) {
|
||||
Assert.assertTrue(matchInfo.isCloseMatch());
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
} else if (expectedMatchKind==ArgsMatchKind.REQUIRES_CONVERSION) {
|
||||
Assert.assertTrue("expected to be a match requiring conversion, but was "+matchInfo,matchInfo.isMatchRequiringConversion());
|
||||
if (argsForConversion==null) {
|
||||
@@ -510,7 +510,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
checkArgument(expected[i],args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void checkArgument(Object expected, Object actual) {
|
||||
Assert.assertEquals(expected,actual);
|
||||
}
|
||||
|
||||
@@ -43,19 +43,19 @@ public class StandardComponentsTests {
|
||||
context.setTypeLocator(tl);
|
||||
Assert.assertEquals(tl,context.getTypeLocator());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStandardOperatorOverloader() throws EvaluationException {
|
||||
OperatorOverloader oo = new StandardOperatorOverloader();
|
||||
Assert.assertFalse(oo.overridesOperation(Operation.ADD, null, null));
|
||||
try {
|
||||
try {
|
||||
oo.operate(Operation.ADD, 2, 3);
|
||||
Assert.fail("should have failed");
|
||||
} catch (EvaluationException e) {
|
||||
// success
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStandardTypeLocator() {
|
||||
StandardTypeLocator tl = new StandardTypeLocator();
|
||||
@@ -68,7 +68,7 @@ public class StandardComponentsTests {
|
||||
prefixes = tl.getImportPrefixes();
|
||||
Assert.assertEquals(1,prefixes.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStandardTypeConverter() throws EvaluationException {
|
||||
TypeConverter tc = new StandardTypeConverter();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
/**
|
||||
* Hold the various kinds of primitive array for access through the test evaluation context.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ArrayContainer {
|
||||
@@ -29,7 +29,7 @@ public class ArrayContainer {
|
||||
public short[] shorts = new short[3];
|
||||
public boolean[] booleans = new boolean[3];
|
||||
public float[] floats = new float[3];
|
||||
|
||||
|
||||
public ArrayContainer() {
|
||||
// setup some values
|
||||
ints[0] = 42;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.springframework.expression.spel.testresources;
|
||||
|
||||
///CLOVER:OFF
|
||||
public class Company {
|
||||
String address;
|
||||
|
||||
|
||||
public Company(String string) {
|
||||
this.address = string;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.springframework.expression.spel.testresources;
|
||||
|
||||
@@ -11,7 +11,7 @@ public class Fruit {
|
||||
public Color color; // accessible as property through getter/setter
|
||||
public String colorName; // accessible as property through getter/setter
|
||||
public int stringscount = -1;
|
||||
|
||||
|
||||
public Fruit(String name, Color color, String colorName) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
@@ -21,15 +21,15 @@ public class Fruit {
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
public Fruit(String... strings) {
|
||||
stringscount = strings.length;
|
||||
}
|
||||
|
||||
|
||||
public Fruit(int i, String... strings) {
|
||||
stringscount = i + strings.length;
|
||||
}
|
||||
|
||||
|
||||
public int stringscount() {
|
||||
return stringscount;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Inventor {
|
||||
public String[] stringArrayOfThreeItems = new String[]{"1","2","3"};
|
||||
private String foo;
|
||||
public int counter;
|
||||
|
||||
|
||||
public Inventor(String name, Date birthdate, String nationality) {
|
||||
this.name = name;
|
||||
this._name = name;
|
||||
@@ -88,7 +88,7 @@ public class Inventor {
|
||||
public String[] getInventions() {
|
||||
return inventions;
|
||||
}
|
||||
|
||||
|
||||
public void setInventions(String[] inventions) {
|
||||
this.inventions = inventions;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public class Inventor {
|
||||
public PlaceOfBirth getPlaceOfBirth() {
|
||||
return placeOfBirth;
|
||||
}
|
||||
|
||||
|
||||
public int throwException(int valueIn) throws Exception {
|
||||
counter++;
|
||||
if (valueIn==1) {
|
||||
@@ -110,9 +110,9 @@ public class Inventor {
|
||||
}
|
||||
return valueIn;
|
||||
}
|
||||
|
||||
|
||||
static class TestException extends Exception {}
|
||||
|
||||
|
||||
public String throwException(PlaceOfBirth pob) {
|
||||
return pob.getCity();
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class Inventor {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public boolean getWonNobelPrize() {
|
||||
return wonNobelPrize;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class Inventor {
|
||||
public String sayHelloTo(String person) {
|
||||
return "hello " + person;
|
||||
}
|
||||
|
||||
|
||||
public String printDouble(Double d) {
|
||||
return d.toString();
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public class Inventor {
|
||||
public Inventor(String... strings) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean getSomeProperty() {
|
||||
return accessedThroughGetSet;
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public class Inventor {
|
||||
public void setSomeProperty(boolean b) {
|
||||
this.accessedThroughGetSet = b;
|
||||
}
|
||||
|
||||
|
||||
public Date getBirthdate() { return birthdate;}
|
||||
|
||||
public String getFoo() { return foo; }
|
||||
|
||||
@@ -8,16 +8,16 @@ public class Person {
|
||||
public Person(String name) {
|
||||
this.privateName = name;
|
||||
}
|
||||
|
||||
|
||||
public Person(String name, Company company) {
|
||||
this.privateName = name;
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return privateName;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String n) {
|
||||
this.privateName = n;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package org.springframework.expression.spel.testresources;
|
||||
///CLOVER:OFF
|
||||
public class PlaceOfBirth {
|
||||
private String city;
|
||||
|
||||
|
||||
public String Country;
|
||||
|
||||
|
||||
/**
|
||||
* Keith now has a converter that supports String to X, if X has a ctor that takes a String.
|
||||
* In order for round tripping to work we need toString() for X to return what it was
|
||||
@@ -25,11 +25,11 @@ public class PlaceOfBirth {
|
||||
public PlaceOfBirth(String string) {
|
||||
this.city=string;
|
||||
}
|
||||
|
||||
|
||||
public int doubleIt(int i) {
|
||||
return i*2;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof PlaceOfBirth)) {
|
||||
return false;
|
||||
@@ -37,9 +37,9 @@ public class PlaceOfBirth {
|
||||
PlaceOfBirth oPOB = (PlaceOfBirth)o;
|
||||
return (city.equals(oPOB.city));
|
||||
}
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
return city.hashCode();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.List;
|
||||
public class TestAddress{
|
||||
private String street;
|
||||
private List<String> crossStreets;
|
||||
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.springframework.expression.spel.testresources;
|
||||
public class TestPerson {
|
||||
private String name;
|
||||
private TestAddress address;
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user