Skip to content

Commit fc64b80

Browse files
committed
Polish "Replace relevant code with lambda"
Closes gh-1454
1 parent 4b1478d commit fc64b80

File tree

29 files changed

+186
-189
lines changed

29 files changed

+186
-189
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java

Lines changed: 1 addition & 1 deletion
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-2017 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.

spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -28,7 +28,6 @@
2828
import java.lang.reflect.Method;
2929
import java.lang.reflect.Modifier;
3030
import java.util.ArrayList;
31-
import java.util.Collections;
3231
import java.util.Comparator;
3332
import java.util.List;
3433
import java.util.Set;
@@ -139,7 +138,7 @@ private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescript
139138
// Sort non-void returning write methods to guard against the ill effects of
140139
// non-deterministic sorting of methods returned from Class#getDeclaredMethods
141140
// under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
142-
Collections.sort(matches, (m1, m2) -> m2.toString().compareTo(m1.toString()));
141+
matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString()));
143142
return matches;
144143
}
145144

spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -412,43 +412,43 @@ private InjectionMetadata buildAutowiringMetadata(final Class<?> clazz) {
412412
final LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<>();
413413

414414
ReflectionUtils.doWithLocalFields(targetClass, field -> {
415-
AnnotationAttributes ann = findAutowiredAnnotation(field);
416-
if (ann != null) {
417-
if (Modifier.isStatic(field.getModifiers())) {
418-
if (logger.isWarnEnabled()) {
419-
logger.warn("Autowired annotation is not supported on static fields: " + field);
420-
}
421-
return;
422-
}
423-
boolean required = determineRequiredStatus(ann);
424-
currElements.add(new AutowiredFieldElement(field, required));
425-
}
426-
});
415+
AnnotationAttributes ann = findAutowiredAnnotation(field);
416+
if (ann != null) {
417+
if (Modifier.isStatic(field.getModifiers())) {
418+
if (logger.isWarnEnabled()) {
419+
logger.warn("Autowired annotation is not supported on static fields: " + field);
420+
}
421+
return;
422+
}
423+
boolean required = determineRequiredStatus(ann);
424+
currElements.add(new AutowiredFieldElement(field, required));
425+
}
426+
});
427427

428428
ReflectionUtils.doWithLocalMethods(targetClass, method -> {
429-
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
430-
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
431-
return;
432-
}
433-
AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod);
434-
if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
435-
if (Modifier.isStatic(method.getModifiers())) {
436-
if (logger.isWarnEnabled()) {
437-
logger.warn("Autowired annotation is not supported on static methods: " + method);
438-
}
439-
return;
440-
}
441-
if (method.getParameterCount() == 0) {
442-
if (logger.isWarnEnabled()) {
443-
logger.warn("Autowired annotation should only be used on methods with parameters: " +
444-
method);
445-
}
446-
}
447-
boolean required = determineRequiredStatus(ann);
448-
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
449-
currElements.add(new AutowiredMethodElement(method, required, pd));
450-
}
451-
});
429+
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
430+
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
431+
return;
432+
}
433+
AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod);
434+
if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
435+
if (Modifier.isStatic(method.getModifiers())) {
436+
if (logger.isWarnEnabled()) {
437+
logger.warn("Autowired annotation is not supported on static methods: " + method);
438+
}
439+
return;
440+
}
441+
if (method.getParameterCount() == 0) {
442+
if (logger.isWarnEnabled()) {
443+
logger.warn("Autowired annotation should only be used on methods with parameters: " +
444+
method);
445+
}
446+
}
447+
boolean required = determineRequiredStatus(ann);
448+
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
449+
currElements.add(new AutowiredMethodElement(method, required, pd));
450+
}
451+
});
452452

453453
elements.addAll(0, currElements);
454454
targetClass = targetClass.getSuperclass();

spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java

Lines changed: 1 addition & 1 deletion
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-2017 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.

spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.

spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java

Lines changed: 1 addition & 1 deletion
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-2017 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.

spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ else if (ejbRefClass != null && field.isAnnotationPresent(ejbRefClass)) {
363363
throw new IllegalStateException("@EJB annotation is not supported on static fields");
364364
}
365365
currElements.add(new EjbRefElement(field, field, null));
366-
}
366+
}
367367
else if (field.isAnnotationPresent(Resource.class)) {
368368
if (Modifier.isStatic(field.getModifiers())) {
369369
throw new IllegalStateException("@Resource annotation is not supported on static fields");

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import java.beans.PropertyDescriptor;
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
22-
import java.util.Collections;
23-
import java.util.Comparator;
2422
import java.util.HashSet;
2523
import java.util.LinkedHashMap;
2624
import java.util.LinkedHashSet;
@@ -280,7 +278,7 @@ else if (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.
280278
}
281279

282280
// Sort by previously determined @Order value, if applicable
283-
Collections.sort(configCandidates, (bd1, bd2) -> {
281+
configCandidates.sort((bd1, bd2) -> {
284282
int i1 = ConfigurationClassUtils.getOrder(bd1.getBeanDefinition());
285283
int i2 = ConfigurationClassUtils.getOrder(bd2.getBeanDefinition());
286284
return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0;

spring-core/src/main/java/org/springframework/util/ReflectionUtils.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@
4747
*/
4848
public abstract class ReflectionUtils {
4949

50-
/**
51-
* Pre-built FieldFilter that matches all non-static, non-final fields.
52-
*/
53-
public static final FieldFilter COPYABLE_FIELDS =
54-
field -> !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()));
55-
5650
/**
5751
* Naming prefix for CGLIB-renamed methods.
5852
* @see #isCglibRenamedMethod
@@ -851,6 +845,13 @@ public interface FieldFilter {
851845
}
852846

853847

848+
/**
849+
* Pre-built FieldFilter that matches all non-static, non-final fields.
850+
*/
851+
public static final FieldFilter COPYABLE_FIELDS =
852+
field -> !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()));
853+
854+
854855
/**
855856
* Pre-built MethodFilter that matches all non-bridge methods.
856857
*/

0 commit comments

Comments
 (0)