From 6a48bb7b4defa47f7bd07bf95358c4a1d20e9ce3 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 7 Nov 2019 22:08:29 +0100 Subject: [PATCH] Polishing --- .../beans/PropertyDescriptorUtils.java | 5 ++--- .../factory/support/ConstructorResolver.java | 14 ++++++-------- .../springframework/util/ReflectionUtils.java | 16 ++++++---------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java index 9cf7acceee..aa9909822d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -66,8 +66,7 @@ abstract class PropertyDescriptorUtils { Class propertyType = null; if (readMethod != null) { - int parameterCount = readMethod.getParameterCount(); - if (parameterCount != 0) { + if (readMethod.getParameterCount() != 0) { throw new IntrospectionException("Bad read method arg count: " + readMethod); } propertyType = readMethod.getReturnType(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java index e43306b50b..cf43c433a2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java @@ -342,22 +342,20 @@ class ConstructorResolver { if (uniqueCandidate == null) { uniqueCandidate = candidate; } - else { - boolean paramsNotMatch = isParamsNotMatch(uniqueCandidate, candidate); - if (paramsNotMatch) { - uniqueCandidate = null; - break; - } + else if (isParamMismatch(uniqueCandidate, candidate)) { + uniqueCandidate = null; + break; } } } mbd.factoryMethodToIntrospect = uniqueCandidate; } - private boolean isParamsNotMatch(Method uniqueCandidate, Method candidate) { + private boolean isParamMismatch(Method uniqueCandidate, Method candidate) { int uniqueCandidateParameterCount = uniqueCandidate.getParameterCount(); int candidateParameterCount = candidate.getParameterCount(); - return uniqueCandidateParameterCount != candidateParameterCount || !Arrays.equals(uniqueCandidate.getParameterTypes(), candidate.getParameterTypes()); + return (uniqueCandidateParameterCount != candidateParameterCount || + !Arrays.equals(uniqueCandidate.getParameterTypes(), candidate.getParameterTypes())); } /** diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java index 8f7b320d2d..9b9decee73 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -235,12 +235,10 @@ public abstract class ReflectionUtils { Assert.notNull(name, "Method name must not be null"); Class searchType = clazz; while (searchType != null) { - Method[] methods = searchType.isInterface() ? - searchType.getMethods() : - getDeclaredMethods(searchType, false); + Method[] methods = (searchType.isInterface() ? searchType.getMethods() : + getDeclaredMethods(searchType, false)); for (Method method : methods) { - if (name.equals(method.getName()) && - (paramTypes == null || hasSameParams(method, paramTypes))) { + if (name.equals(method.getName()) && (paramTypes == null || hasSameParams(method, paramTypes))) { return method; } } @@ -249,11 +247,9 @@ public abstract class ReflectionUtils { return null; } - private static boolean hasSameParams(Method method, @Nullable Class[] paramTypes) { - if (paramTypes.length != method.getParameterCount()) { - return false; - } - return Arrays.equals(paramTypes, method.getParameterTypes()); + private static boolean hasSameParams(Method method, Class[] paramTypes) { + return (paramTypes.length == method.getParameterCount() && + Arrays.equals(paramTypes, method.getParameterTypes())); } /**