Skip to content

Commit 139dc1d

Browse files
committed
Polishing (collapsed if checks, consistent downcasts, refined javadoc)
1 parent 0f7485b commit 139dc1d

File tree

50 files changed

+326
-425
lines changed

Some content is hidden

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

50 files changed

+326
-425
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -224,6 +224,9 @@ public int getOrder() {
224224
}
225225

226226

227+
/**
228+
* Set the name of the aspect (bean) in which the advice was declared.
229+
*/
227230
public void setAspectName(String name) {
228231
this.aspectName = name;
229232
}
@@ -234,7 +237,7 @@ public String getAspectName() {
234237
}
235238

236239
/**
237-
* Sets the <b>declaration order</b> of this advice within the aspect
240+
* Set the declaration order of this advice within the aspect.
238241
*/
239242
public void setDeclarationOrder(int order) {
240243
this.declarationOrder = order;

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ public void setOrder(int order) {
5757
this.order = order;
5858
}
5959

60+
@Override
61+
public int getOrder() {
62+
if (this.order != null) {
63+
return this.order;
64+
}
65+
else {
66+
return this.advice.getOrder();
67+
}
68+
}
69+
6070
@Override
6171
public boolean isPerInstance() {
6272
return true;
@@ -72,14 +82,13 @@ public Pointcut getPointcut() {
7282
return this.pointcut;
7383
}
7484

75-
@Override
76-
public int getOrder() {
77-
if (this.order != null) {
78-
return this.order;
79-
}
80-
else {
81-
return this.advice.getOrder();
82-
}
85+
/**
86+
* Return the name of the aspect (bean) in which the advice was declared.
87+
* @since 4.3.15
88+
* @see AbstractAspectJAdvice#getAspectName()
89+
*/
90+
public String getAspectName() {
91+
return this.advice.getAspectName();
8392
}
8493

8594

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -36,12 +36,12 @@ public interface AspectJPrecedenceInformation extends Ordered {
3636
// its advice for aspects with non-singleton instantiation models.
3737

3838
/**
39-
* The name of the aspect (bean) in which the advice was declared.
39+
* Return the name of the aspect (bean) in which the advice was declared.
4040
*/
4141
String getAspectName();
4242

4343
/**
44-
* The declaration order of the advice member within the aspect.
44+
* Return the declaration order of the advice member within the aspect.
4545
*/
4646
int getDeclarationOrder();
4747

spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJAwareAdvisorAutoProxyCreator.java

Lines changed: 6 additions & 9 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-2018 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.
@@ -67,14 +67,12 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
6767
@Override
6868
@SuppressWarnings("unchecked")
6969
protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
70-
List<PartiallyComparableAdvisorHolder> partiallyComparableAdvisors =
71-
new ArrayList<>(advisors.size());
70+
List<PartiallyComparableAdvisorHolder> partiallyComparableAdvisors = new ArrayList<>(advisors.size());
7271
for (Advisor element : advisors) {
7372
partiallyComparableAdvisors.add(
7473
new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR));
7574
}
76-
List<PartiallyComparableAdvisorHolder> sorted =
77-
PartialOrder.sort(partiallyComparableAdvisors);
75+
List<PartiallyComparableAdvisorHolder> sorted = PartialOrder.sort(partiallyComparableAdvisors);
7876
if (sorted != null) {
7977
List<Advisor> result = new ArrayList<>(advisors.size());
8078
for (PartiallyComparableAdvisorHolder pcAdvisor : sorted) {
@@ -102,10 +100,9 @@ protected boolean shouldSkip(Class<?> beanClass, String beanName) {
102100
// TODO: Consider optimization by caching the list of the aspect names
103101
List<Advisor> candidateAdvisors = findCandidateAdvisors();
104102
for (Advisor advisor : candidateAdvisors) {
105-
if (advisor instanceof AspectJPointcutAdvisor) {
106-
if (((AbstractAspectJAdvice) advisor.getAdvice()).getAspectName().equals(beanName)) {
107-
return true;
108-
}
103+
if (advisor instanceof AspectJPointcutAdvisor &&
104+
((AspectJPointcutAdvisor) advisor).getAspectName().equals(beanName)) {
105+
return true;
109106
}
110107
}
111108
return super.shouldSkip(beanClass, beanName);

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -349,10 +349,9 @@ public PropertyEditor findCustomEditor(@Nullable Class<?> requiredType, @Nullabl
349349
public boolean hasCustomEditorForElement(@Nullable Class<?> elementType, @Nullable String propertyPath) {
350350
if (propertyPath != null && this.customEditorsForPath != null) {
351351
for (Map.Entry<String, CustomEditorHolder> entry : this.customEditorsForPath.entrySet()) {
352-
if (PropertyAccessorUtils.matchesProperty(entry.getKey(), propertyPath)) {
353-
if (entry.getValue().getPropertyEditor(elementType) != null) {
354-
return true;
355-
}
352+
if (PropertyAccessorUtils.matchesProperty(entry.getKey(), propertyPath) &&
353+
entry.getValue().getPropertyEditor(elementType) != null) {
354+
return true;
356355
}
357356
}
358357
}

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,10 @@ protected void inject(Object bean, @Nullable String beanName, @Nullable Property
593593
registerDependentBeans(beanName, autowiredBeanNames);
594594
if (autowiredBeanNames.size() == 1) {
595595
String autowiredBeanName = autowiredBeanNames.iterator().next();
596-
if (beanFactory.containsBean(autowiredBeanName)) {
597-
if (beanFactory.isTypeMatch(autowiredBeanName, field.getType())) {
598-
this.cachedFieldValue = new ShortcutDependencyDescriptor(
599-
desc, autowiredBeanName, field.getType());
600-
}
596+
if (beanFactory.containsBean(autowiredBeanName) &&
597+
beanFactory.isTypeMatch(autowiredBeanName, field.getType())) {
598+
this.cachedFieldValue = new ShortcutDependencyDescriptor(
599+
desc, autowiredBeanName, field.getType());
601600
}
602601
}
603602
}
@@ -678,11 +677,10 @@ protected void inject(Object bean, @Nullable String beanName, @Nullable Property
678677
Iterator<String> it = autowiredBeans.iterator();
679678
for (int i = 0; i < paramTypes.length; i++) {
680679
String autowiredBeanName = it.next();
681-
if (beanFactory.containsBean(autowiredBeanName)) {
682-
if (beanFactory.isTypeMatch(autowiredBeanName, paramTypes[i])) {
683-
cachedMethodArguments[i] = new ShortcutDependencyDescriptor(
684-
descriptors[i], autowiredBeanName, paramTypes[i]);
685-
}
680+
if (beanFactory.containsBean(autowiredBeanName) &&
681+
beanFactory.isTypeMatch(autowiredBeanName, paramTypes[i])) {
682+
cachedMethodArguments[i] = new ShortcutDependencyDescriptor(
683+
descriptors[i], autowiredBeanName, paramTypes[i]);
686684
}
687685
}
688686
}

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -205,21 +205,17 @@ private LifecycleMetadata buildLifecycleMetadata(final Class<?> clazz) {
205205
final LinkedList<LifecycleElement> currDestroyMethods = new LinkedList<>();
206206

207207
ReflectionUtils.doWithLocalMethods(targetClass, method -> {
208-
if (initAnnotationType != null) {
209-
if (method.getAnnotation(initAnnotationType) != null) {
210-
LifecycleElement element = new LifecycleElement(method);
211-
currInitMethods.add(element);
212-
if (debug) {
213-
logger.debug("Found init method on class [" + clazz.getName() + "]: " + method);
214-
}
208+
if (initAnnotationType != null && method.isAnnotationPresent(initAnnotationType)) {
209+
LifecycleElement element = new LifecycleElement(method);
210+
currInitMethods.add(element);
211+
if (debug) {
212+
logger.debug("Found init method on class [" + clazz.getName() + "]: " + method);
215213
}
216214
}
217-
if (destroyAnnotationType != null) {
218-
if (method.getAnnotation(destroyAnnotationType) != null) {
219-
currDestroyMethods.add(new LifecycleElement(method));
220-
if (debug) {
221-
logger.debug("Found destroy method on class [" + clazz.getName() + "]: " + method);
222-
}
215+
if (destroyAnnotationType != null && method.isAnnotationPresent(destroyAnnotationType)) {
216+
currDestroyMethods.add(new LifecycleElement(method));
217+
if (debug) {
218+
logger.debug("Found destroy method on class [" + clazz.getName() + "]: " + method);
223219
}
224220
}
225221
});

spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,8 @@ else if ("ref".equals(name)) {
381381
refName = args[0].toString();
382382
}
383383
boolean parentRef = false;
384-
if (args.length > 1) {
385-
if (args[1] instanceof Boolean) {
386-
parentRef = (Boolean) args[1];
387-
}
384+
if (args.length > 1 && args[1] instanceof Boolean) {
385+
parentRef = (Boolean) args[1];
388386
}
389387
return new RuntimeBeanReference(refName, parentRef);
390388
}

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,15 +1556,13 @@ protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrap
15561556
return;
15571557
}
15581558

1559+
if (System.getSecurityManager() != null && bw instanceof BeanWrapperImpl) {
1560+
((BeanWrapperImpl) bw).setSecurityContext(getAccessControlContext());
1561+
}
1562+
15591563
MutablePropertyValues mpvs = null;
15601564
List<PropertyValue> original;
15611565

1562-
if (System.getSecurityManager() != null) {
1563-
if (bw instanceof BeanWrapperImpl) {
1564-
((BeanWrapperImpl) bw).setSecurityContext(getAccessControlContext());
1565-
}
1566-
}
1567-
15681566
if (pvs instanceof MutablePropertyValues) {
15691567
mpvs = (MutablePropertyValues) pvs;
15701568
if (mpvs.isConverted()) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -105,10 +105,8 @@ public boolean shouldSkip(@Nullable AnnotatedTypeMetadata metadata, @Nullable Co
105105
if (condition instanceof ConfigurationCondition) {
106106
requiredPhase = ((ConfigurationCondition) condition).getConfigurationPhase();
107107
}
108-
if (requiredPhase == null || requiredPhase == phase) {
109-
if (!condition.matches(this.context, metadata)) {
110-
return true;
111-
}
108+
if ((requiredPhase == null || requiredPhase == phase) && !condition.matches(this.context, metadata)) {
109+
return true;
112110
}
113111
}
114112

0 commit comments

Comments
 (0)