Skip to content

Commit 5fcfe0f

Browse files
committed
Polishing
1 parent cab35aa commit 5fcfe0f

File tree

6 files changed

+42
-28
lines changed

6 files changed

+42
-28
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java

Lines changed: 21 additions & 11 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.
@@ -27,11 +27,11 @@
2727

2828
import org.springframework.aop.Advisor;
2929
import org.springframework.aop.IntroductionAdvisor;
30+
import org.springframework.aop.IntroductionAwareMethodMatcher;
3031
import org.springframework.aop.MethodMatcher;
3132
import org.springframework.aop.PointcutAdvisor;
3233
import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry;
3334
import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry;
34-
import org.springframework.aop.support.MethodMatchers;
3535
import org.springframework.lang.Nullable;
3636

3737
/**
@@ -53,19 +53,30 @@ public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
5353

5454
// This is somewhat tricky... We have to process introductions first,
5555
// but we need to preserve order in the ultimate list.
56-
List<Object> interceptorList = new ArrayList<>(config.getAdvisors().length);
57-
Class<?> actualClass = (targetClass != null ? targetClass : method.getDeclaringClass());
58-
boolean hasIntroductions = hasMatchingIntroductions(config, actualClass);
5956
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance();
57+
Advisor[] advisors = config.getAdvisors();
58+
List<Object> interceptorList = new ArrayList<>(advisors.length);
59+
Class<?> actualClass = (targetClass != null ? targetClass : method.getDeclaringClass());
60+
Boolean hasIntroductions = null;
6061

61-
for (Advisor advisor : config.getAdvisors()) {
62+
for (Advisor advisor : advisors) {
6263
if (advisor instanceof PointcutAdvisor) {
6364
// Add it conditionally.
6465
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor;
6566
if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) {
66-
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
6767
MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher();
68-
if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) {
68+
boolean match;
69+
if (mm instanceof IntroductionAwareMethodMatcher) {
70+
if (hasIntroductions == null) {
71+
hasIntroductions = hasMatchingIntroductions(advisors, actualClass);
72+
}
73+
match = ((IntroductionAwareMethodMatcher) mm).matches(method, targetClass, hasIntroductions);
74+
}
75+
else {
76+
match = mm.matches(method, targetClass);
77+
}
78+
if (match) {
79+
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
6980
if (mm.isRuntime()) {
7081
// Creating a new object instance in the getInterceptors() method
7182
// isn't a problem as we normally cache created chains.
@@ -98,9 +109,8 @@ else if (advisor instanceof IntroductionAdvisor) {
98109
/**
99110
* Determine whether the Advisors contain matching introductions.
100111
*/
101-
private static boolean hasMatchingIntroductions(Advised config, Class<?> actualClass) {
102-
for (int i = 0; i < config.getAdvisors().length; i++) {
103-
Advisor advisor = config.getAdvisors()[i];
112+
private static boolean hasMatchingIntroductions(Advisor[] advisors, Class<?> actualClass) {
113+
for (Advisor advisor : advisors) {
104114
if (advisor instanceof IntroductionAdvisor) {
105115
IntroductionAdvisor ia = (IntroductionAdvisor) advisor;
106116
if (ia.getClassFilter().matches(actualClass)) {

spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistry.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
public interface AdvisorAdapterRegistry {
3232

3333
/**
34-
* Return an Advisor wrapping the given advice.
34+
* Return an {@link Advisor} wrapping the given advice.
3535
* <p>Should by default at least support
3636
* {@link org.aopalliance.intercept.MethodInterceptor},
3737
* {@link org.springframework.aop.MethodBeforeAdvice},
3838
* {@link org.springframework.aop.AfterReturningAdvice},
3939
* {@link org.springframework.aop.ThrowsAdvice}.
40-
* @param advice object that should be an advice
41-
* @return an Advisor wrapping the given advice. Never returns {@code null}.
42-
* If the advice parameter is an Advisor, return it.
40+
* @param advice an object that should be an advice
41+
* @return an Advisor wrapping the given advice (never {@code null};
42+
* if the advice parameter is an Advisor, it is to be returned as-is)
4343
* @throws UnknownAdviceTypeException if no registered advisor adapter
4444
* can wrap the supposed advice
4545
*/
@@ -48,21 +48,20 @@ public interface AdvisorAdapterRegistry {
4848
/**
4949
* Return an array of AOP Alliance MethodInterceptors to allow use of the
5050
* given Advisor in an interception-based framework.
51-
* <p>Don't worry about the pointcut associated with the Advisor,
52-
* if it's a PointcutAdvisor: just return an interceptor.
51+
* <p>Don't worry about the pointcut associated with the {@link Advisor}, if it is
52+
* a {@link org.springframework.aop.PointcutAdvisor}: just return an interceptor.
5353
* @param advisor the Advisor to find an interceptor for
5454
* @return an array of MethodInterceptors to expose this Advisor's behavior
5555
* @throws UnknownAdviceTypeException if the Advisor type is
56-
* not understood by any registered AdvisorAdapter.
56+
* not understood by any registered AdvisorAdapter
5757
*/
5858
MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException;
5959

6060
/**
61-
* Register the given AdvisorAdapter. Note that it is not necessary to register
61+
* Register the given {@link AdvisorAdapter}. Note that it is not necessary to register
6262
* adapters for an AOP Alliance Interceptors or Spring Advices: these must be
63-
* automatically recognized by an AdvisorAdapterRegistry implementation.
64-
* @param adapter the AdvisorAdapter that understands a particular Advisor
65-
* or Advice types
63+
* automatically recognized by an {@code AdvisorAdapterRegistry} implementation.
64+
* @param adapter an AdvisorAdapter that understands particular Advisor or Advice types
6665
*/
6766
void registerAdvisorAdapter(AdvisorAdapter adapter);
6867

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected JCacheOperationSource getCacheOperationSource() {
4141
}
4242
};
4343

44+
4445
/**
4546
* Set the cache operation attribute source which is used to find cache
4647
* attributes. This should usually be identical to the source reference

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
* @since 4.1
3030
* @param <A> the annotation type
3131
*/
32-
class DefaultCacheKeyInvocationContext<A extends Annotation>
33-
extends DefaultCacheInvocationContext<A> implements CacheKeyInvocationContext<A> {
32+
class DefaultCacheKeyInvocationContext<A extends Annotation> extends DefaultCacheInvocationContext<A>
33+
implements CacheKeyInvocationContext<A> {
3434

3535
private final CacheInvocationParameter[] keyParameters;
3636

spring-context/src/main/java/org/springframework/validation/DataBinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ public void validate() {
857857
Assert.state(target != null, "No target to validate");
858858
BindingResult bindingResult = getBindingResult();
859859
// Call each validator with the same binding result
860-
for (Validator validator : this.validators) {
860+
for (Validator validator : getValidators()) {
861861
validator.validate(target, bindingResult);
862862
}
863863
}

spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ protected Object constructAttribute(Constructor<?> ctor, String attributeName, M
309309
for (int i = 0; i < paramNames.length; i++) {
310310
String paramName = paramNames[i];
311311
if (!failedParams.contains(paramName)) {
312-
result.recordFieldValue(paramName, paramTypes[i], args[i]);
313-
validateValueIfApplicable(binder, parameter, ctor.getDeclaringClass(), paramName, args[i]);
312+
Object value = args[i];
313+
result.recordFieldValue(paramName, paramTypes[i], value);
314+
validateValueIfApplicable(binder, parameter, ctor.getDeclaringClass(), paramName, value);
314315
}
315316
}
316317
throw new BindException(result);
@@ -410,7 +411,10 @@ private Object[] determineValidationHints(Annotation ann) {
410411
Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
411412
if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
412413
Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
413-
return (hints instanceof Object[] ? (Object[]) hints : new Object[]{hints});
414+
if (hints == null) {
415+
return new Object[0];
416+
}
417+
return (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
414418
}
415419
return null;
416420
}

0 commit comments

Comments
 (0)