Skip to content

Commit d6525cf

Browse files
committed
Polishing
1 parent d018303 commit d6525cf

File tree

4 files changed

+56
-50
lines changed

4 files changed

+56
-50
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656

5757
/**
5858
* Factory that can create Spring AOP Advisors given AspectJ classes from
59-
* classes honoring the AspectJ 5 annotation syntax, using reflection to
60-
* invoke the corresponding advice methods.
59+
* classes honoring AspectJ's annotation syntax, using reflection to invoke the
60+
* corresponding advice methods.
6161
*
6262
* @author Rod Johnson
6363
* @author Adrian Colyer

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -50,27 +50,27 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
5050

5151

5252
/**
53-
* Sort the rest by AspectJ precedence. If two pieces of advice have
54-
* come from the same aspect they will have the same order.
55-
* Advice from the same aspect is then further ordered according to the
53+
* Sort the supplied {@link Advisor} instances according to AspectJ precedence.
54+
* <p>If two pieces of advice come from the same aspect, they will have the same
55+
* order. Advice from the same aspect is then further ordered according to the
5656
* following rules:
5757
* <ul>
58-
* <li>if either of the pair is after advice, then the advice declared
59-
* last gets highest precedence (runs last)</li>
60-
* <li>otherwise the advice declared first gets highest precedence (runs first)</li>
58+
* <li>If either of the pair is <em>after</em> advice, then the advice declared
59+
* last gets highest precedence (i.e., runs last).</li>
60+
* <li>Otherwise the advice declared first gets highest precedence (i.e., runs
61+
* first).</li>
6162
* </ul>
6263
* <p><b>Important:</b> Advisors are sorted in precedence order, from highest
6364
* precedence to lowest. "On the way in" to a join point, the highest precedence
64-
* advisor should run first. "On the way out" of a join point, the highest precedence
65-
* advisor should run last.
65+
* advisor should run first. "On the way out" of a join point, the highest
66+
* precedence advisor should run last.
6667
*/
6768
@Override
68-
@SuppressWarnings("unchecked")
6969
protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
7070
List<PartiallyComparableAdvisorHolder> partiallyComparableAdvisors = new ArrayList<>(advisors.size());
71-
for (Advisor element : advisors) {
71+
for (Advisor advisor : advisors) {
7272
partiallyComparableAdvisors.add(
73-
new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR));
73+
new PartiallyComparableAdvisorHolder(advisor, DEFAULT_PRECEDENCE_COMPARATOR));
7474
}
7575
List<PartiallyComparableAdvisorHolder> sorted = PartialOrder.sort(partiallyComparableAdvisors);
7676
if (sorted != null) {
@@ -86,8 +86,8 @@ protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
8686
}
8787

8888
/**
89-
* Adds an {@link ExposeInvocationInterceptor} to the beginning of the advice chain.
90-
* These additional advices are needed when using AspectJ expression pointcuts
89+
* Add an {@link ExposeInvocationInterceptor} to the beginning of the advice chain.
90+
* <p>This additional advice is needed when using AspectJ pointcut expressions
9191
* and when using AspectJ-style advice.
9292
*/
9393
@Override
@@ -110,7 +110,7 @@ protected boolean shouldSkip(Class<?> beanClass, String beanName) {
110110

111111

112112
/**
113-
* Implements AspectJ PartialComparable interface for defining partial orderings.
113+
* Implements AspectJ's {@link PartialComparable} interface for defining partial orderings.
114114
*/
115115
private static class PartiallyComparableAdvisorHolder implements PartialComparable {
116116

@@ -140,17 +140,19 @@ public Advisor getAdvisor() {
140140

141141
@Override
142142
public String toString() {
143-
StringBuilder sb = new StringBuilder();
144143
Advice advice = this.advisor.getAdvice();
145-
sb.append(ClassUtils.getShortName(advice.getClass()));
146-
sb.append(": ");
144+
StringBuilder sb = new StringBuilder(ClassUtils.getShortName(advice.getClass()));
145+
boolean appended = false;
147146
if (this.advisor instanceof Ordered) {
148-
sb.append("order ").append(((Ordered) this.advisor).getOrder()).append(", ");
147+
sb.append(": order = ").append(((Ordered) this.advisor).getOrder());
148+
appended = true;
149149
}
150150
if (advice instanceof AbstractAspectJAdvice) {
151+
sb.append(!appended ? ": " : ", ");
151152
AbstractAspectJAdvice ajAdvice = (AbstractAspectJAdvice) advice;
153+
sb.append("aspect name = ");
152154
sb.append(ajAdvice.getAspectName());
153-
sb.append(", declaration order ");
155+
sb.append(", declaration order = ");
154156
sb.append(ajAdvice.getDeclarationOrder());
155157
}
156158
return sb.toString();

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@
2727
/**
2828
* Orders AspectJ advice/advisors by precedence (<i>not</i> invocation order).
2929
*
30-
* <p>Given two pieces of advice, {@code a} and {@code b}:
30+
* <p>Given two pieces of advice, {@code A} and {@code B}:
3131
* <ul>
32-
* <li>if {@code a} and {@code b} are defined in different aspects, then the advice
33-
* in the aspect with the lowest order value has the highest precedence</li>
34-
* <li>if {@code a} and {@code b} are defined in the same aspect, then if one of
35-
* {@code a} or {@code b} is a form of after advice, then the advice declared last
36-
* in the aspect has the highest precedence. If neither {@code a} nor {@code b} is
37-
* a form of after advice, then the advice declared first in the aspect has the
38-
* highest precedence.</li>
32+
* <li>If {@code A} and {@code B} are defined in different aspects, then the advice
33+
* in the aspect with the lowest order value has the highest precedence.</li>
34+
* <li>If {@code A} and {@code B} are defined in the same aspect, if one of
35+
* {@code A} or {@code B} is a form of <em>after</em> advice, then the advice declared
36+
* last in the aspect has the highest precedence. If neither {@code A} nor {@code B}
37+
* is a form of <em>after</em> advice, then the advice declared first in the aspect
38+
* has the highest precedence.</li>
3939
* </ul>
4040
*
41-
* <p>Important: Note that unlike a normal comparator a return of 0 means
42-
* we don't care about the ordering, not that the two elements must be sorted
43-
* identically. Used with AspectJ PartialOrder class.
41+
* <p>Important: This comparator is used with AspectJ's
42+
* {@link org.aspectj.util.PartialOrder PartialOrder} sorting utility. Thus, unlike
43+
* a normal {@link Comparator}, a return value of {@code 0} from this comparator
44+
* means we don't care about the ordering, not that the two elements must be sorted
45+
* identically.
4446
*
4547
* @author Adrian Colyer
4648
* @author Juergen Hoeller
@@ -59,16 +61,16 @@ class AspectJPrecedenceComparator implements Comparator<Advisor> {
5961

6062

6163
/**
62-
* Create a default AspectJPrecedenceComparator.
64+
* Create a default {@code AspectJPrecedenceComparator}.
6365
*/
6466
public AspectJPrecedenceComparator() {
6567
this.advisorComparator = AnnotationAwareOrderComparator.INSTANCE;
6668
}
6769

6870
/**
69-
* Create a AspectJPrecedenceComparator, using the given Comparator
71+
* Create an {@code AspectJPrecedenceComparator}, using the given {@link Comparator}
7072
* for comparing {@link org.springframework.aop.Advisor} instances.
71-
* @param advisorComparator the Comparator to use for Advisors
73+
* @param advisorComparator the {@code Comparator} to use for advisors
7274
*/
7375
public AspectJPrecedenceComparator(Comparator<? super Advisor> advisorComparator) {
7476
Assert.notNull(advisorComparator, "Advisor comparator must not be null");
@@ -125,20 +127,20 @@ private boolean declaredInSameAspect(Advisor advisor1, Advisor advisor2) {
125127
getAspectName(advisor1).equals(getAspectName(advisor2)));
126128
}
127129

128-
private boolean hasAspectName(Advisor anAdvisor) {
129-
return (anAdvisor instanceof AspectJPrecedenceInformation ||
130-
anAdvisor.getAdvice() instanceof AspectJPrecedenceInformation);
130+
private boolean hasAspectName(Advisor advisor) {
131+
return (advisor instanceof AspectJPrecedenceInformation ||
132+
advisor.getAdvice() instanceof AspectJPrecedenceInformation);
131133
}
132134

133135
// pre-condition is that hasAspectName returned true
134-
private String getAspectName(Advisor anAdvisor) {
135-
AspectJPrecedenceInformation pi = AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor);
136-
Assert.state(pi != null, "Unresolvable precedence information");
137-
return pi.getAspectName();
136+
private String getAspectName(Advisor advisor) {
137+
AspectJPrecedenceInformation precedenceInfo = AspectJAopUtils.getAspectJPrecedenceInformationFor(advisor);
138+
Assert.state(precedenceInfo != null, () -> "Unresolvable AspectJPrecedenceInformation for " + advisor);
139+
return precedenceInfo.getAspectName();
138140
}
139141

140-
private int getAspectDeclarationOrder(Advisor anAdvisor) {
141-
AspectJPrecedenceInformation precedenceInfo = AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor);
142+
private int getAspectDeclarationOrder(Advisor advisor) {
143+
AspectJPrecedenceInformation precedenceInfo = AspectJAopUtils.getAspectJPrecedenceInformationFor(advisor);
142144
return (precedenceInfo != null ? precedenceInfo.getDeclarationOrder() : 0);
143145
}
144146

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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,11 +36,13 @@
3636
* also override the inherited {@link #shouldSkip} method to exclude certain
3737
* objects from auto-proxying.
3838
*
39-
* <p>Advisors or advices requiring ordering should implement the
39+
* <p>Advisors or advices requiring ordering should be annotated with
40+
* {@link org.springframework.core.annotation.Order @Order} or implement the
4041
* {@link org.springframework.core.Ordered} interface. This class sorts
41-
* Advisors by Ordered order value. Advisors that don't implement the
42-
* Ordered interface will be considered as unordered; they will appear
43-
* at the end of the advisor chain in undefined order.
42+
* advisors using the {@link AnnotationAwareOrderComparator}. Advisors that are
43+
* not annotated with {@code @Order} or don't implement the {@code Ordered}
44+
* interface will be considered as unordered; they will appear at the end of the
45+
* advisor chain in an undefined order.
4446
*
4547
* @author Rod Johnson
4648
* @author Juergen Hoeller

0 commit comments

Comments
 (0)