1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -109,29 +109,22 @@ public InstantiationModelAwarePointcutAdvisorImpl(AspectJExpressionPointcut decl
109
109
110
110
111
111
/**
112
- * The pointcut for Spring AOP to use. Actual behaviour of the pointcut will change
113
- * depending on the state of the advice.
112
+ * The pointcut for Spring AOP to use.
113
+ * Actual behaviour of the pointcut will change depending on the state of the advice.
114
114
*/
115
115
@ Override
116
116
public Pointcut getPointcut () {
117
117
return this .pointcut ;
118
118
}
119
119
120
- /**
121
- * This is only of interest for Spring AOP: AspectJ instantiation semantics
122
- * are much richer. In AspectJ terminology, all a return of {@code true}
123
- * means here is that the aspect is not a SINGLETON.
124
- */
125
120
@ Override
126
- public boolean isPerInstance () {
127
- return ( getAspectMetadata (). getAjType (). getPerClause (). getKind () != PerClauseKind . SINGLETON ) ;
121
+ public boolean isLazy () {
122
+ return this . lazy ;
128
123
}
129
124
130
- /**
131
- * Return the AspectJ AspectMetadata for this advisor.
132
- */
133
- public AspectMetadata getAspectMetadata () {
134
- return this .aspectInstanceFactory .getAspectMetadata ();
125
+ @ Override
126
+ public synchronized boolean isAdviceInstantiated () {
127
+ return (this .instantiatedAdvice != null );
135
128
}
136
129
137
130
/**
@@ -145,20 +138,26 @@ public synchronized Advice getAdvice() {
145
138
return this .instantiatedAdvice ;
146
139
}
147
140
148
- @ Override
149
- public boolean isLazy () {
150
- return this .lazy ;
141
+ private Advice instantiateAdvice ( AspectJExpressionPointcut pcut ) {
142
+ return this . aspectJAdvisorFactory . getAdvice ( this . aspectJAdviceMethod , pcut ,
143
+ this . aspectInstanceFactory , this .declarationOrder , this . aspectName ) ;
151
144
}
152
145
146
+ /**
147
+ * This is only of interest for Spring AOP: AspectJ instantiation semantics
148
+ * are much richer. In AspectJ terminology, all a return of {@code true}
149
+ * means here is that the aspect is not a SINGLETON.
150
+ */
153
151
@ Override
154
- public synchronized boolean isAdviceInstantiated () {
155
- return (this . instantiatedAdvice != null );
152
+ public boolean isPerInstance () {
153
+ return (getAspectMetadata (). getAjType (). getPerClause (). getKind () != PerClauseKind . SINGLETON );
156
154
}
157
155
158
-
159
- private Advice instantiateAdvice (AspectJExpressionPointcut pcut ) {
160
- return this .aspectJAdvisorFactory .getAdvice (this .aspectJAdviceMethod , pcut ,
161
- this .aspectInstanceFactory , this .declarationOrder , this .aspectName );
156
+ /**
157
+ * Return the AspectJ AspectMetadata for this advisor.
158
+ */
159
+ public AspectMetadata getAspectMetadata () {
160
+ return this .aspectInstanceFactory .getAspectMetadata ();
162
161
}
163
162
164
163
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory () {
@@ -213,33 +212,26 @@ private void determineAdviceType() {
213
212
}
214
213
else {
215
214
switch (aspectJAnnotation .getAnnotationType ()) {
216
- case AtAfter :
217
- case AtAfterReturning :
218
- case AtAfterThrowing :
219
- this .isAfterAdvice = true ;
220
- this .isBeforeAdvice = false ;
221
- break ;
222
- case AtAround :
223
215
case AtPointcut :
224
- this . isAfterAdvice = false ;
216
+ case AtAround :
225
217
this .isBeforeAdvice = false ;
218
+ this .isAfterAdvice = false ;
226
219
break ;
227
220
case AtBefore :
228
- this .isAfterAdvice = false ;
229
221
this .isBeforeAdvice = true ;
222
+ this .isAfterAdvice = false ;
223
+ break ;
224
+ case AtAfter :
225
+ case AtAfterReturning :
226
+ case AtAfterThrowing :
227
+ this .isBeforeAdvice = false ;
228
+ this .isAfterAdvice = true ;
229
+ break ;
230
230
}
231
231
}
232
232
}
233
233
234
234
235
- @ Override
236
- public String toString () {
237
- return "InstantiationModelAwarePointcutAdvisor: expression [" + getDeclaredPointcut ().getExpression () +
238
- "]; advice method [" + this .aspectJAdviceMethod + "]; perClauseKind=" +
239
- this .aspectInstanceFactory .getAspectMetadata ().getAjType ().getPerClause ().getKind ();
240
-
241
- }
242
-
243
235
private void readObject (ObjectInputStream inputStream ) throws IOException , ClassNotFoundException {
244
236
inputStream .defaultReadObject ();
245
237
try {
@@ -250,11 +242,18 @@ private void readObject(ObjectInputStream inputStream) throws IOException, Class
250
242
}
251
243
}
252
244
245
+ @ Override
246
+ public String toString () {
247
+ return "InstantiationModelAwarePointcutAdvisor: expression [" + getDeclaredPointcut ().getExpression () +
248
+ "]; advice method [" + this .aspectJAdviceMethod + "]; perClauseKind=" +
249
+ this .aspectInstanceFactory .getAspectMetadata ().getAjType ().getPerClause ().getKind ();
250
+ }
251
+
253
252
254
253
/**
255
254
* Pointcut implementation that changes its behaviour when the advice is instantiated.
256
- * Note that this is a <i>dynamic</i> pointcut. Otherwise it might
257
- * be optimized out if it does not at first match statically.
255
+ * Note that this is a <i>dynamic</i> pointcut; otherwise it might be optimized out
256
+ * if it does not at first match statically.
258
257
*/
259
258
private class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPointcut {
260
259
@@ -264,8 +263,9 @@ private class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPo
264
263
265
264
private LazySingletonAspectInstanceFactoryDecorator aspectInstanceFactory ;
266
265
267
- private PerTargetInstantiationModelPointcut (AspectJExpressionPointcut declaredPointcut ,
266
+ public PerTargetInstantiationModelPointcut (AspectJExpressionPointcut declaredPointcut ,
268
267
Pointcut preInstantiationPointcut , MetadataAwareAspectInstanceFactory aspectInstanceFactory ) {
268
+
269
269
this .declaredPointcut = declaredPointcut ;
270
270
this .preInstantiationPointcut = preInstantiationPointcut ;
271
271
if (aspectInstanceFactory instanceof LazySingletonAspectInstanceFactoryDecorator ) {
@@ -275,7 +275,8 @@ private PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPo
275
275
276
276
@ Override
277
277
public boolean matches (Method method , Class <?> targetClass ) {
278
- // We're either instantiated and matching on declared pointcut, or uninstantiated matching on either pointcut
278
+ // We're either instantiated and matching on declared pointcut,
279
+ // or uninstantiated matching on either pointcut...
279
280
return (isAspectMaterialized () && this .declaredPointcut .matches (method , targetClass )) ||
280
281
this .preInstantiationPointcut .getMethodMatcher ().matches (method , targetClass );
281
282
}
0 commit comments