Polishing

This commit is contained in:
Juergen Hoeller
2018-01-19 19:35:02 +01:00
parent a73d9bbed5
commit 8b5a013423
12 changed files with 108 additions and 128 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -149,10 +149,8 @@ public class CodeFlow implements Opcodes {
* Return the descriptor for the item currently on top of the stack (in the current scope).
*/
public String lastDescriptor() {
if (this.compilationScopes.peek().isEmpty()) {
return null;
}
return this.compilationScopes.peek().get(this.compilationScopes.peek().size() - 1);
ArrayList<String> scopes = this.compilationScopes.peek();
return (!scopes.isEmpty() ? scopes.get(scopes.size() - 1) : null);
}
/**
@@ -161,7 +159,7 @@ public class CodeFlow implements Opcodes {
* @param mv the visitor into which new instructions should be inserted
*/
public void unboxBooleanIfNecessary(MethodVisitor mv) {
if (lastDescriptor().equals("Ljava/lang/Boolean")) {
if ("Ljava/lang/Boolean".equals(lastDescriptor())) {
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
}
}

View File

@@ -70,9 +70,8 @@ public class FunctionReference extends SpelNodeImpl {
if (value == TypedValue.NULL) {
throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name);
}
// Two possibilities: a lambda function or a Java static method registered as a function
if (!(value.getValue() instanceof Method)) {
// Two possibilities: a lambda function or a Java static method registered as a function
throw new SpelEvaluationException(
SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass());
}
@@ -96,11 +95,13 @@ public class FunctionReference extends SpelNodeImpl {
private TypedValue executeFunctionJLRMethod(ExpressionState state, Method method) throws EvaluationException {
Object[] functionArgs = getArguments(state);
if (!method.isVarArgs() && method.getParameterCount() != functionArgs.length) {
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
functionArgs.length, method.getParameterCount());
if (!method.isVarArgs()) {
int declaredParamCount = method.getParameterTypes().length;
if (declaredParamCount != functionArgs.length) {
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
functionArgs.length, declaredParamCount);
}
}
// Only static methods can be called in this way
if (!Modifier.isStatic(method.getModifiers())) {
throw new SpelEvaluationException(getStartPosition(),
SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name);