Skip to content

Commit 7737175

Browse files
committed
Polishing
1 parent e00fd52 commit 7737175

File tree

2 files changed

+55
-55
lines changed

2 files changed

+55
-55
lines changed

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

Lines changed: 46 additions & 46 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.
@@ -116,29 +116,22 @@ public InstantiationModelAwarePointcutAdvisorImpl(AspectJExpressionPointcut decl
116116

117117

118118
/**
119-
* The pointcut for Spring AOP to use. Actual behaviour of the pointcut will change
120-
* depending on the state of the advice.
119+
* The pointcut for Spring AOP to use.
120+
* Actual behaviour of the pointcut will change depending on the state of the advice.
121121
*/
122122
@Override
123123
public Pointcut getPointcut() {
124124
return this.pointcut;
125125
}
126126

127-
/**
128-
* This is only of interest for Spring AOP: AspectJ instantiation semantics
129-
* are much richer. In AspectJ terminology, all a return of {@code true}
130-
* means here is that the aspect is not a SINGLETON.
131-
*/
132127
@Override
133-
public boolean isPerInstance() {
134-
return (getAspectMetadata().getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON);
128+
public boolean isLazy() {
129+
return this.lazy;
135130
}
136131

137-
/**
138-
* Return the AspectJ AspectMetadata for this advisor.
139-
*/
140-
public AspectMetadata getAspectMetadata() {
141-
return this.aspectInstanceFactory.getAspectMetadata();
132+
@Override
133+
public synchronized boolean isAdviceInstantiated() {
134+
return (this.instantiatedAdvice != null);
142135
}
143136

144137
/**
@@ -152,21 +145,27 @@ public synchronized Advice getAdvice() {
152145
return this.instantiatedAdvice;
153146
}
154147

155-
@Override
156-
public boolean isLazy() {
157-
return this.lazy;
148+
private Advice instantiateAdvice(AspectJExpressionPointcut pointcut) {
149+
Advice advice = this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pointcut,
150+
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
151+
return (advice != null ? advice : EMPTY_ADVICE);
158152
}
159153

154+
/**
155+
* This is only of interest for Spring AOP: AspectJ instantiation semantics
156+
* are much richer. In AspectJ terminology, all a return of {@code true}
157+
* means here is that the aspect is not a SINGLETON.
158+
*/
160159
@Override
161-
public synchronized boolean isAdviceInstantiated() {
162-
return (this.instantiatedAdvice != null);
160+
public boolean isPerInstance() {
161+
return (getAspectMetadata().getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON);
163162
}
164163

165-
166-
private Advice instantiateAdvice(AspectJExpressionPointcut pointcut) {
167-
Advice advice = this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pointcut,
168-
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
169-
return (advice != null ? advice : EMPTY_ADVICE);
164+
/**
165+
* Return the AspectJ AspectMetadata for this advisor.
166+
*/
167+
public AspectMetadata getAspectMetadata() {
168+
return this.aspectInstanceFactory.getAspectMetadata();
170169
}
171170

172171
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory() {
@@ -221,33 +220,26 @@ private void determineAdviceType() {
221220
}
222221
else {
223222
switch (aspectJAnnotation.getAnnotationType()) {
224-
case AtAfter:
225-
case AtAfterReturning:
226-
case AtAfterThrowing:
227-
this.isAfterAdvice = true;
228-
this.isBeforeAdvice = false;
229-
break;
230-
case AtAround:
231223
case AtPointcut:
232-
this.isAfterAdvice = false;
224+
case AtAround:
233225
this.isBeforeAdvice = false;
226+
this.isAfterAdvice = false;
234227
break;
235228
case AtBefore:
236-
this.isAfterAdvice = false;
237229
this.isBeforeAdvice = true;
230+
this.isAfterAdvice = false;
231+
break;
232+
case AtAfter:
233+
case AtAfterReturning:
234+
case AtAfterThrowing:
235+
this.isBeforeAdvice = false;
236+
this.isAfterAdvice = true;
237+
break;
238238
}
239239
}
240240
}
241241

242242

243-
@Override
244-
public String toString() {
245-
return "InstantiationModelAwarePointcutAdvisor: expression [" + getDeclaredPointcut().getExpression() +
246-
"]; advice method [" + this.aspectJAdviceMethod + "]; perClauseKind=" +
247-
this.aspectInstanceFactory.getAspectMetadata().getAjType().getPerClause().getKind();
248-
249-
}
250-
251243
private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
252244
inputStream.defaultReadObject();
253245
try {
@@ -258,11 +250,18 @@ private void readObject(ObjectInputStream inputStream) throws IOException, Class
258250
}
259251
}
260252

253+
@Override
254+
public String toString() {
255+
return "InstantiationModelAwarePointcutAdvisor: expression [" + getDeclaredPointcut().getExpression() +
256+
"]; advice method [" + this.aspectJAdviceMethod + "]; perClauseKind=" +
257+
this.aspectInstanceFactory.getAspectMetadata().getAjType().getPerClause().getKind();
258+
}
259+
261260

262261
/**
263262
* Pointcut implementation that changes its behaviour when the advice is instantiated.
264-
* Note that this is a <i>dynamic</i> pointcut. Otherwise it might
265-
* be optimized out if it does not at first match statically.
263+
* Note that this is a <i>dynamic</i> pointcut; otherwise it might be optimized out
264+
* if it does not at first match statically.
266265
*/
267266
private class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPointcut {
268267

@@ -273,7 +272,7 @@ private class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPo
273272
@Nullable
274273
private LazySingletonAspectInstanceFactoryDecorator aspectInstanceFactory;
275274

276-
private PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPointcut,
275+
public PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPointcut,
277276
Pointcut preInstantiationPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory) {
278277

279278
this.declaredPointcut = declaredPointcut;
@@ -285,7 +284,8 @@ private PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPo
285284

286285
@Override
287286
public boolean matches(Method method, @Nullable Class<?> targetClass) {
288-
// We're either instantiated and matching on declared pointcut, or uninstantiated matching on either pointcut
287+
// We're either instantiated and matching on declared pointcut,
288+
// or uninstantiated matching on either pointcut...
289289
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass)) ||
290290
this.preInstantiationPointcut.getMethodMatcher().matches(method, targetClass);
291291
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut
246246
AbstractAspectJAdvice springAdvice;
247247

248248
switch (aspectJAnnotation.getAnnotationType()) {
249+
case AtPointcut:
250+
if (logger.isDebugEnabled()) {
251+
logger.debug("Processing pointcut '" + candidateAdviceMethod.getName() + "'");
252+
}
253+
return null;
254+
case AtAround:
255+
springAdvice = new AspectJAroundAdvice(
256+
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
257+
break;
249258
case AtBefore:
250259
springAdvice = new AspectJMethodBeforeAdvice(
251260
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
@@ -270,15 +279,6 @@ public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut
270279
springAdvice.setThrowingName(afterThrowingAnnotation.throwing());
271280
}
272281
break;
273-
case AtAround:
274-
springAdvice = new AspectJAroundAdvice(
275-
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
276-
break;
277-
case AtPointcut:
278-
if (logger.isDebugEnabled()) {
279-
logger.debug("Processing pointcut '" + candidateAdviceMethod.getName() + "'");
280-
}
281-
return null;
282282
default:
283283
throw new UnsupportedOperationException(
284284
"Unsupported advice type on method: " + candidateAdviceMethod);

0 commit comments

Comments
 (0)