Skip to content

Commit e83bdda

Browse files
committed
Polish SpEL code
1 parent 4830ea6 commit e83bdda

File tree

93 files changed

+2373
-1629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2373
-1629
lines changed

spring-expression/src/main/java/org/springframework/expression/ConstructorExecutor.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,13 +19,15 @@
1919

2020
// TODO Is the resolver/executor model too pervasive in this package?
2121
/**
22-
* Executors are built by resolvers and can be cached by the infrastructure to repeat an operation quickly without going
23-
* back to the resolvers. For example, the particular constructor to run on a class may be discovered by the reflection
24-
* constructor resolver - it will then build a ConstructorExecutor that executes that constructor and the
25-
* ConstructorExecutor can be reused without needing to go back to the resolver to discover the constructor again.
22+
* Executors are built by resolvers and can be cached by the infrastructure to repeat an
23+
* operation quickly without going back to the resolvers. For example, the particular
24+
* constructor to run on a class may be discovered by the reflection constructor resolver
25+
* - it will then build a ConstructorExecutor that executes that constructor and the
26+
* ConstructorExecutor can be reused without needing to go back to the resolver to
27+
* discover the constructor again.
2628
*
27-
* They can become stale, and in that case should throw an AccessException - this will cause the infrastructure to go
28-
* back to the resolvers to ask for a new one.
29+
* <p>They can become stale, and in that case should throw an AccessException - this will
30+
* cause the infrastructure to go back to the resolvers to ask for a new one.
2931
*
3032
* @author Andy Clement
3133
* @since 3.0
@@ -34,11 +36,13 @@ public interface ConstructorExecutor {
3436

3537
/**
3638
* Execute a constructor in the specified context using the specified arguments.
39+
*
3740
* @param context the evaluation context in which the command is being executed
38-
* @param arguments the arguments to the constructor call, should match (in terms of number and type) whatever the
39-
* command will need to run
41+
* @param arguments the arguments to the constructor call, should match (in terms of
42+
* number and type) whatever the command will need to run
4043
* @return the new object
41-
* @throws AccessException if there is a problem executing the command or the CommandExecutor is no longer valid
44+
* @throws AccessException if there is a problem executing the command or the
45+
* CommandExecutor is no longer valid
4246
*/
4347
TypedValue execute(EvaluationContext context, Object... arguments) throws AccessException;
4448

spring-expression/src/main/java/org/springframework/expression/ConstructorResolver.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,18 +21,19 @@
2121
import org.springframework.core.convert.TypeDescriptor;
2222

2323
/**
24-
* A constructor resolver attempts locate a constructor and returns a ConstructorExecutor that can be used to invoke
25-
* that constructor. The ConstructorExecutor will be cached but if it 'goes stale' the resolvers will be called again.
26-
*
24+
* A constructor resolver attempts locate a constructor and returns a ConstructorExecutor
25+
* that can be used to invoke that constructor. The ConstructorExecutor will be cached but
26+
* if it 'goes stale' the resolvers will be called again.
27+
*
2728
* @author Andy Clement
2829
* @since 3.0
2930
*/
3031
public interface ConstructorResolver {
3132

3233
/**
33-
* Within the supplied context determine a suitable constructor on the supplied type that can handle the
34-
* specified arguments. Return a ConstructorExecutor that can be used to invoke that constructor
35-
* (or {@code null} if no constructor could be found).
34+
* Within the supplied context determine a suitable constructor on the supplied type
35+
* that can handle the specified arguments. Return a ConstructorExecutor that can be
36+
* used to invoke that constructor (or {@code null} if no constructor could be found).
3637
* @param context the current evaluation context
3738
* @param typeName the type upon which to look for the constructor
3839
* @param argumentTypes the arguments that the constructor must be able to handle

spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,12 +19,12 @@
1919
import java.util.List;
2020

2121
/**
22-
* Expressions are executed in an evaluation context. It is in this context that references
23-
* are resolved when encountered during expression evaluation.
22+
* Expressions are executed in an evaluation context. It is in this context that
23+
* references are resolved when encountered during expression evaluation.
2424
*
2525
* <p>There is a default implementation of the EvaluationContext,
26-
* {@link org.springframework.expression.spel.support.StandardEvaluationContext}
27-
* that can be extended, rather than having to implement everything.
26+
* {@link org.springframework.expression.spel.support.StandardEvaluationContext} that can
27+
* be extended, rather than having to implement everything.
2828
*
2929
* @author Andy Clement
3030
* @author Juergen Hoeller
@@ -33,8 +33,9 @@
3333
public interface EvaluationContext {
3434

3535
/**
36-
* @return the default root context object against which unqualified properties/methods/etc
37-
* should be resolved. This can be overridden when evaluating an expression.
36+
* @return the default root context object against which unqualified
37+
* properties/methods/etc should be resolved. This can be overridden when
38+
* evaluating an expression.
3839
*/
3940
TypedValue getRootObject();
4041

@@ -54,7 +55,8 @@ public interface EvaluationContext {
5455
List<PropertyAccessor> getPropertyAccessors();
5556

5657
/**
57-
* @return a type locator that can be used to find types, either by short or fully qualified name.
58+
* @return a type locator that can be used to find types, either by short or fully
59+
* qualified name.
5860
*/
5961
TypeLocator getTypeLocator();
6062

spring-expression/src/main/java/org/springframework/expression/Expression.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,10 +19,9 @@
1919
import org.springframework.core.convert.TypeDescriptor;
2020

2121
/**
22-
* An expression capable of evaluating itself against context objects.
23-
* Encapsulates the details of a previously parsed expression string.
24-
* Provides a common abstraction for expression evaluation independent
25-
* of any language like OGNL or the Unified EL.
22+
* An expression capable of evaluating itself against context objects. Encapsulates the
23+
* details of a previously parsed expression string. Provides a common abstraction for
24+
* expression evaluation independent of any language like OGNL or the Unified EL.
2625
*
2726
* @author Keith Donald
2827
* @author Andy Clement

spring-expression/src/main/java/org/springframework/expression/ExpressionException.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.expression;
1818

19-
2019
/**
2120
* Super class for exceptions that can occur whilst processing expressions
2221
*
@@ -27,8 +26,10 @@
2726
public class ExpressionException extends RuntimeException {
2827

2928
protected String expressionString;
29+
3030
protected int position; // -1 if not known - but should be known in all reasonable cases
3131

32+
3233
/**
3334
* Creates a new expression exception.
3435
* @param expressionString the expression string
@@ -85,15 +86,16 @@ public ExpressionException(String message, Throwable cause) {
8586
super(message,cause);
8687
}
8788

89+
8890
public String toDetailedString() {
8991
StringBuilder output = new StringBuilder();
90-
if (expressionString!=null) {
92+
if (this.expressionString!=null) {
9193
output.append("Expression '");
92-
output.append(expressionString);
94+
output.append(this.expressionString);
9395
output.append("'");
94-
if (position!=-1) {
96+
if (this.position!=-1) {
9597
output.append(" @ ");
96-
output.append(position);
98+
output.append(this.position);
9799
}
98100
output.append(": ");
99101
}
@@ -106,7 +108,7 @@ public final String getExpressionString() {
106108
}
107109

108110
public final int getPosition() {
109-
return position;
111+
return this.position;
110112
}
111113

112114
}

spring-expression/src/main/java/org/springframework/expression/ExpressionInvocationTargetException.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,13 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.expression;
1718

1819
/**
19-
* This exception wraps (as cause) a checked exception thrown by some method that SpEL invokes.
20-
* It differs from a SpelEvaluationException because this indicates the occurrence of a checked exception
21-
* that the invoked method was defined to throw. SpelEvaluationExceptions are for handling (and wrapping)
22-
* unexpected exceptions.
20+
* This exception wraps (as cause) a checked exception thrown by some method that SpEL
21+
* invokes. It differs from a SpelEvaluationException because this indicates the
22+
* occurrence of a checked exception that the invoked method was defined to throw.
23+
* SpelEvaluationExceptions are for handling (and wrapping) unexpected exceptions.
2324
*
2425
* @author Andy Clement
2526
* @since 3.0.3

spring-expression/src/main/java/org/springframework/expression/MethodExecutor.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,27 +17,31 @@
1717
package org.springframework.expression;
1818

1919
/**
20-
* MethodExecutors are built by the resolvers and can be cached by the infrastructure to repeat an operation quickly
21-
* without going back to the resolvers. For example, the particular method to run on an object may be discovered by the
22-
* reflection method resolver - it will then build a MethodExecutor that executes that method and the MethodExecutor can
23-
* be reused without needing to go back to the resolver to discover the method again.
20+
* MethodExecutors are built by the resolvers and can be cached by the infrastructure to
21+
* repeat an operation quickly without going back to the resolvers. For example, the
22+
* particular method to run on an object may be discovered by the reflection method
23+
* resolver - it will then build a MethodExecutor that executes that method and the
24+
* MethodExecutor can be reused without needing to go back to the resolver to discover the
25+
* method again.
2426
*
25-
* <p>They can become stale, and in that case should throw an AccessException - this will cause the infrastructure to go
26-
* back to the resolvers to ask for a new one.
27+
* <p>They can become stale, and in that case should throw an AccessException - this will
28+
* cause the infrastructure to go back to the resolvers to ask for a new one.
2729
*
2830
* @author Andy Clement
2931
* @since 3.0
3032
*/
3133
public interface MethodExecutor {
3234

3335
/**
34-
* Execute a command using the specified arguments, and using the specified expression state.
36+
* Execute a command using the specified arguments, and using the specified expression
37+
* state.
3538
* @param context the evaluation context in which the command is being executed
3639
* @param target the target object of the call - null for static methods
37-
* @param arguments the arguments to the executor, should match (in terms of number and type) whatever the
38-
* command will need to run
40+
* @param arguments the arguments to the executor, should match (in terms of number
41+
* and type) whatever the command will need to run
3942
* @return the value returned from execution
40-
* @throws AccessException if there is a problem executing the command or the MethodExecutor is no longer valid
43+
* @throws AccessException if there is a problem executing the command or the
44+
* MethodExecutor is no longer valid
4145
*/
4246
TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException;
4347

spring-expression/src/main/java/org/springframework/expression/MethodFilter.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,31 +13,31 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.expression;
1718

1819
import java.lang.reflect.Method;
1920
import java.util.List;
2021

2122
/**
22-
* MethodFilter instances allow SpEL users to fine tune the behaviour of the method resolution
23-
* process. Method resolution (which translates from a method name in an expression to a real
24-
* method to invoke) will normally retrieve candidate methods for invocation via a simple call
25-
* to 'Class.getMethods()' and will choose the first one that is suitable for the
26-
* input parameters. By registering a MethodFilter the user can receive a callback
27-
* and change the methods that will be considered suitable.
23+
* MethodFilter instances allow SpEL users to fine tune the behaviour of the method
24+
* resolution process. Method resolution (which translates from a method name in an
25+
* expression to a real method to invoke) will normally retrieve candidate methods for
26+
* invocation via a simple call to 'Class.getMethods()' and will choose the first one that
27+
* is suitable for the input parameters. By registering a MethodFilter the user can
28+
* receive a callback and change the methods that will be considered suitable.
2829
*
2930
* @author Andy Clement
3031
* @since 3.0.1
3132
*/
3233
public interface MethodFilter {
3334

3435
/**
35-
* Called by the method resolver to allow the SpEL user to organize the list of candidate
36-
* methods that may be invoked. The filter can remove methods that should not be
37-
* considered candidates and it may sort the results. The resolver will then search
38-
* through the methods as returned from the filter when looking for a suitable
36+
* Called by the method resolver to allow the SpEL user to organize the list of
37+
* candidate methods that may be invoked. The filter can remove methods that should
38+
* not be considered candidates and it may sort the results. The resolver will then
39+
* search through the methods as returned from the filter when looking for a suitable
3940
* candidate to invoke.
40-
*
4141
* @param methods the full list of methods the resolver was going to choose from
4242
* @return a possible subset of input methods that may be sorted by order of relevance
4343
*/

spring-expression/src/main/java/org/springframework/expression/MethodResolver.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,22 +21,24 @@
2121
import org.springframework.core.convert.TypeDescriptor;
2222

2323
/**
24-
* A method resolver attempts locate a method and returns a command executor that can be used to invoke that method.
25-
* The command executor will be cached but if it 'goes stale' the resolvers will be called again.
24+
* A method resolver attempts locate a method and returns a command executor that can be
25+
* used to invoke that method. The command executor will be cached but if it 'goes stale'
26+
* the resolvers will be called again.
2627
*
2728
* @author Andy Clement
2829
* @since 3.0
2930
*/
3031
public interface MethodResolver {
3132

3233
/**
33-
* Within the supplied context determine a suitable method on the supplied object that can handle the
34-
* specified arguments. Return a MethodExecutor that can be used to invoke that method
35-
* (or {@code null} if no method could be found).
34+
* Within the supplied context determine a suitable method on the supplied object that
35+
* can handle the specified arguments. Return a MethodExecutor that can be used to
36+
* invoke that method (or {@code null} if no method could be found).
3637
* @param context the current evaluation context
3738
* @param targetObject the object upon which the method is being called
3839
* @param argumentTypes the arguments that the constructor must be able to handle
39-
* @return a MethodExecutor that can invoke the method, or null if the method cannot be found
40+
* @return a MethodExecutor that can invoke the method, or null if the method cannot
41+
* be found
4042
*/
4143
MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
4244
List<TypeDescriptor> argumentTypes) throws AccessException;

spring-expression/src/main/java/org/springframework/expression/Operation.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,13 +17,24 @@
1717
package org.springframework.expression;
1818

1919
/**
20-
* Supported operations that an {@link OperatorOverloader} can implement for any pair of operands.
20+
* Supported operations that an {@link OperatorOverloader} can implement for any pair of
21+
* operands.
2122
*
2223
* @author Andy Clement
2324
* @since 3.0
2425
*/
2526
public enum Operation {
2627

27-
ADD, SUBTRACT, DIVIDE, MULTIPLY, MODULUS, POWER
28+
ADD,
29+
30+
SUBTRACT,
31+
32+
DIVIDE,
33+
34+
MULTIPLY,
35+
36+
MODULUS,
37+
38+
POWER
2839

2940
}

0 commit comments

Comments
 (0)