Skip to content

Commit ef1e17f

Browse files
committed
Polishing
1 parent 04f7655 commit ef1e17f

File tree

6 files changed

+48
-43
lines changed

6 files changed

+48
-43
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -62,7 +62,7 @@ protected ValueRef getValueRef(ExpressionState state) throws EvaluationException
6262
}
6363
try {
6464
state.pushActiveContextObject(result);
65-
nextNode = this.children[cc-1];
65+
nextNode = this.children[cc - 1];
6666
return nextNode.getValueRef(state);
6767
}
6868
finally {

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -445,15 +445,14 @@ public boolean isCompilable() {
445445
public void generateCode(MethodVisitor mv, CodeFlow cf) {
446446
ReflectiveConstructorExecutor executor = ((ReflectiveConstructorExecutor) this.cachedExecutor);
447447
Constructor<?> constructor = executor.getConstructor();
448-
String classSlashedDescriptor = constructor.getDeclaringClass().getName().replace('.', '/');
449-
mv.visitTypeInsn(NEW, classSlashedDescriptor);
448+
String classDesc = constructor.getDeclaringClass().getName().replace('.', '/');
449+
mv.visitTypeInsn(NEW, classDesc);
450450
mv.visitInsn(DUP);
451451
// children[0] is the type of the constructor, don't want to include that in argument processing
452-
SpelNodeImpl[] arguments = new SpelNodeImpl[children.length-1];
453-
System.arraycopy(children, 1, arguments, 0, children.length-1);
452+
SpelNodeImpl[] arguments = new SpelNodeImpl[children.length - 1];
453+
System.arraycopy(children, 1, arguments, 0, children.length - 1);
454454
generateCodeForArguments(mv, cf, constructor, arguments);
455-
mv.visitMethodInsn(INVOKESPECIAL, classSlashedDescriptor, "<init>",
456-
CodeFlow.createSignatureDescriptor(constructor), false);
455+
mv.visitMethodInsn(INVOKESPECIAL, classDesc, "<init>", CodeFlow.createSignatureDescriptor(constructor), false);
457456
cf.pushDescriptor(this.exitTypeDescriptor);
458457
}
459458

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -33,15 +33,15 @@
3333
import org.springframework.util.ReflectionUtils;
3434

3535
/**
36-
* A function reference is of the form "#someFunction(a,b,c)". Functions may be defined in
37-
* the context prior to the expression being evaluated or within the expression itself
36+
* A function reference is of the form "#someFunction(a,b,c)". Functions may be defined
37+
* in the context prior to the expression being evaluated or within the expression itself
3838
* using a lambda function definition. For example: Lambda function definition in an
3939
* expression: "(#max = {|x,y|$x>$y?$x:$y};max(2,3))" Calling context defined function:
4040
* "#isEven(37)". Functions may also be static java methods, registered in the context
4141
* prior to invocation of the expression.
4242
*
43-
* <p>Functions are very simplistic, the arguments are not part of the definition (right
44-
* now), so the names must be unique.
43+
* <p>Functions are very simplistic, the arguments are not part of the definition
44+
* (right now), so the names must be unique.
4545
*
4646
* @author Andy Clement
4747
* @since 3.0
@@ -72,7 +72,8 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
7272

7373
// Two possibilities: a lambda function or a Java static method registered as a function
7474
if (!(value.getValue() instanceof Method)) {
75-
throw new SpelEvaluationException(SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass());
75+
throw new SpelEvaluationException(
76+
SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass());
7677
}
7778

7879
try {
@@ -113,7 +114,8 @@ private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method
113114
argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method);
114115
}
115116
if (method.isVarArgs()) {
116-
functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation(method.getParameterTypes(), functionArgs);
117+
functionArgs =
118+
ReflectionHelper.setupArgumentsForVarargsInvocation(method.getParameterTypes(), functionArgs);
117119
}
118120

119121
try {
@@ -160,13 +162,12 @@ private Object[] getArguments(ExpressionState state) throws EvaluationException
160162

161163
@Override
162164
public boolean isCompilable() {
163-
if (this.method == null || argumentConversionOccurred) {
165+
if (this.method == null || this.argumentConversionOccurred) {
164166
return false;
165167
}
166168
int methodModifiers = this.method.getModifiers();
167-
if (!Modifier.isStatic(methodModifiers) ||
168-
!Modifier.isPublic(methodModifiers) ||
169-
!Modifier.isPublic(method.getDeclaringClass().getModifiers())) {
169+
if (!Modifier.isStatic(methodModifiers) || !Modifier.isPublic(methodModifiers) ||
170+
!Modifier.isPublic(this.method.getDeclaringClass().getModifiers())) {
170171
return false;
171172
}
172173
for (SpelNodeImpl child : this.children) {
@@ -179,9 +180,9 @@ public boolean isCompilable() {
179180

180181
@Override
181182
public void generateCode(MethodVisitor mv,CodeFlow cf) {
182-
String methodDeclaringClassSlashedDescriptor = this.method.getDeclaringClass().getName().replace('.', '/');
183-
generateCodeForArguments(mv, cf, method, this.children);
184-
mv.visitMethodInsn(INVOKESTATIC, methodDeclaringClassSlashedDescriptor, this.method.getName(),
183+
String classDesc = this.method.getDeclaringClass().getName().replace('.', '/');
184+
generateCodeForArguments(mv, cf, this.method, this.children);
185+
mv.visitMethodInsn(INVOKESTATIC, classDesc, this.method.getName(),
185186
CodeFlow.createSignatureDescriptor(this.method), false);
186187
cf.pushDescriptor(this.exitTypeDescriptor);
187188
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ protected static void generateCodeForArguments(MethodVisitor mv, CodeFlow cf, Me
239239
// The final parameter may or may not need packaging into an array, or nothing may
240240
// have been passed to satisfy the varargs and so something needs to be built.
241241
int p = 0; // Current supplied argument being processed
242-
int childcount = arguments.length;
242+
int childCount = arguments.length;
243243

244244
// Fulfill all the parameter requirements except the last one
245-
for (p = 0; p < paramDescriptors.length-1;p++) {
245+
for (p = 0; p < paramDescriptors.length - 1; p++) {
246246
generateCodeForArgument(mv, cf, arguments[p], paramDescriptors[p]);
247247
}
248248

249-
SpelNodeImpl lastchild = (childcount == 0 ? null : arguments[childcount-1]);
250-
String arraytype = paramDescriptors[paramDescriptors.length-1];
249+
SpelNodeImpl lastchild = (childCount == 0 ? null : arguments[childCount - 1]);
250+
String arraytype = paramDescriptors[paramDescriptors.length - 1];
251251
// Determine if the final passed argument is already suitably packaged in array
252252
// form to be passed to the method
253253
if (lastchild != null && lastchild.getExitDescriptor().equals(arraytype)) {
@@ -256,10 +256,10 @@ protected static void generateCodeForArguments(MethodVisitor mv, CodeFlow cf, Me
256256
else {
257257
arraytype = arraytype.substring(1); // trim the leading '[', may leave other '['
258258
// build array big enough to hold remaining arguments
259-
CodeFlow.insertNewArrayCode(mv, childcount-p, arraytype);
259+
CodeFlow.insertNewArrayCode(mv, childCount - p, arraytype);
260260
// Package up the remaining arguments into the array
261261
int arrayindex = 0;
262-
while (p < childcount) {
262+
while (p < childCount) {
263263
SpelNodeImpl child = arguments[p];
264264
mv.visitInsn(DUP);
265265
CodeFlow.insertOptimalLoad(mv, arrayindex++);
@@ -280,20 +280,20 @@ protected static void generateCodeForArguments(MethodVisitor mv, CodeFlow cf, Me
280280
* Ask an argument to generate its bytecode and then follow it up
281281
* with any boxing/unboxing/checkcasting to ensure it matches the expected parameter descriptor.
282282
*/
283-
protected static void generateCodeForArgument(MethodVisitor mv, CodeFlow cf, SpelNodeImpl argument, String paramDescriptor) {
283+
protected static void generateCodeForArgument(MethodVisitor mv, CodeFlow cf, SpelNodeImpl argument, String paramDesc) {
284284
cf.enterCompilationScope();
285285
argument.generateCode(mv, cf);
286286
boolean primitiveOnStack = CodeFlow.isPrimitive(cf.lastDescriptor());
287287
// Check if need to box it for the method reference?
288-
if (primitiveOnStack && paramDescriptor.charAt(0) == 'L') {
288+
if (primitiveOnStack && paramDesc.charAt(0) == 'L') {
289289
CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
290290
}
291-
else if (paramDescriptor.length() == 1 && !primitiveOnStack) {
292-
CodeFlow.insertUnboxInsns(mv, paramDescriptor.charAt(0), cf.lastDescriptor());
291+
else if (paramDesc.length() == 1 && !primitiveOnStack) {
292+
CodeFlow.insertUnboxInsns(mv, paramDesc.charAt(0), cf.lastDescriptor());
293293
}
294-
else if (!cf.lastDescriptor().equals(paramDescriptor)) {
294+
else if (!cf.lastDescriptor().equals(paramDesc)) {
295295
// This would be unnecessary in the case of subtyping (e.g. method takes Number but Integer passed in)
296-
CodeFlow.insertCheckCast(mv, paramDescriptor);
296+
CodeFlow.insertCheckCast(mv, paramDesc);
297297
}
298298
cf.exitCompilationScope();
299299
}

spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ else if (typeConverter.canConvert(suppliedArg, TypeDescriptor.valueOf(varargsPar
238238
* @return true if some kind of conversion occurred on the argument
239239
* @throws SpelEvaluationException if there is a problem with conversion
240240
*/
241-
public static boolean convertAllArguments(TypeConverter converter, Object[] arguments, Method method) throws SpelEvaluationException {
242-
Integer varargsPosition = method.isVarArgs() ? method.getParameterTypes().length-1:null;
241+
public static boolean convertAllArguments(TypeConverter converter, Object[] arguments, Method method)
242+
throws SpelEvaluationException {
243+
244+
Integer varargsPosition = (method.isVarArgs() ? method.getParameterTypes().length - 1 : null);
243245
return convertArguments(converter, arguments, method, varargsPosition);
244246
}
245247

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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,7 +21,6 @@
2121
import org.w3c.dom.Element;
2222

2323
import org.springframework.beans.factory.config.BeanDefinition;
24-
import org.springframework.beans.factory.config.ConstructorArgumentValues;
2524
import org.springframework.beans.factory.config.RuntimeBeanReference;
2625
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
2726
import org.springframework.beans.factory.support.ManagedMap;
@@ -134,21 +133,25 @@ private BeanDefinition registerHandlerMapping(ParserContext context, Object sour
134133
}
135134

136135
private RootBeanDefinition getRedirectView(Element element, HttpStatus status, Object source) {
137-
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
138-
cavs.addIndexedArgumentValue(0, element.getAttribute("redirect-url"));
139-
RootBeanDefinition redirectView = new RootBeanDefinition(RedirectView.class, cavs, null);
136+
RootBeanDefinition redirectView = new RootBeanDefinition(RedirectView.class);
140137
redirectView.setSource(source);
138+
redirectView.getConstructorArgumentValues().addIndexedArgumentValue(0, element.getAttribute("redirect-url"));
139+
141140
if (status != null) {
142141
redirectView.getPropertyValues().add("statusCode", status);
143142
}
143+
144144
if (element.hasAttribute("context-relative")) {
145145
redirectView.getPropertyValues().add("contextRelative", element.getAttribute("context-relative"));
146-
} else {
146+
}
147+
else {
147148
redirectView.getPropertyValues().add("contextRelative", true);
148149
}
150+
149151
if (element.hasAttribute("keep-query-params")) {
150152
redirectView.getPropertyValues().add("propagateQueryParams", element.getAttribute("keep-query-params"));
151153
}
154+
152155
return redirectView;
153156
}
154157

0 commit comments

Comments
 (0)