From 64afc9170836577634804e3318a80311e132eb43 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 25 Sep 2019 20:49:30 +0200 Subject: [PATCH] Polishing --- .../aop/framework/CglibAopProxy.java | 13 ++++++------ .../framework/ReflectiveMethodInvocation.java | 6 +++--- .../aop/support/ComposablePointcut.java | 17 +++++++++------- .../support/DefaultIntroductionAdvisor.java | 8 ++++---- .../aop/support/NameMatchMethodPointcut.java | 7 ++++--- .../aop/support/Pointcuts.java | 5 +++-- .../AnnotationMatchingPointcut.java | 8 ++++---- .../AutowiredAnnotationBeanPostProcessor.java | 14 +++++++------ ...CglibSubclassingInstantiationStrategy.java | 2 +- .../core/annotation/AnnotationAttributes.java | 20 ------------------- .../mvc/method/annotation/SseEmitter.java | 10 +++------- 11 files changed, 47 insertions(+), 63 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java index fec03681a6..cde45d5071 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -327,10 +327,11 @@ class CglibAopProxy implements AopProxy, Serializable { // TODO: small memory optimization here (can skip creation for methods with no advice) for (int x = 0; x < methods.length; x++) { - List chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(methods[x], rootClass); + Method method = methods[x]; + List chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, rootClass); fixedCallbacks[x] = new FixedChainStaticTargetInterceptor( chain, this.advised.getTargetSource().getTarget(), this.advised.getTargetClass()); - this.fixedInterceptorMap.put(methods[x].toString(), x); + this.fixedInterceptorMap.put(methods.toString(), x); } // Now copy both the callbacks from mainCallbacks @@ -633,8 +634,8 @@ class CglibAopProxy implements AopProxy, Serializable { @Override @Nullable public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { - MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args, - this.targetClass, this.adviceChain, methodProxy); + MethodInvocation invocation = new CglibMethodInvocation( + proxy, this.target, method, args, this.targetClass, this.adviceChain, methodProxy); // If we get here, we need to create a MethodInvocation. Object retVal = invocation.proceed(); retVal = processReturnType(proxy, this.target, method, retVal); @@ -795,7 +796,7 @@ class CglibAopProxy implements AopProxy, Serializable { *
For advised methods:
*
If the target is static and the advice chain is frozen then a * FixedChainStaticTargetInterceptor specific to the method is used to - * invoke the advice chain. Otherwise a DyanmicAdvisedInterceptor is + * invoke the advice chain. Otherwise a DynamicAdvisedInterceptor is * used.
*
For non-advised methods:
*
Where it can be determined that the method will not return {@code this} diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java b/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java index 6517163f93..80aa0113c6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,7 +68,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea protected final Method method; - protected Object[] arguments = new Object[0]; + protected Object[] arguments; @Nullable private final Class targetClass; @@ -158,7 +158,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea @Override @Nullable public Object proceed() throws Throwable { - // We start with an index of -1 and increment early. + // We start with an index of -1 and increment early. if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) { return invokeJoinpoint(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java index d47eea4f4f..54a88cf65a 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,12 +24,15 @@ import org.springframework.aop.Pointcut; import org.springframework.util.Assert; /** - * Convenient class for building up pointcuts. All methods return - * ComposablePointcut, so we can use a concise idiom like: + * Convenient class for building up pointcuts. * - * {@code - * Pointcut pc = new ComposablePointcut().union(classFilter).intersection(methodMatcher).intersection(pointcut); - * } + *

All methods return {@code ComposablePointcut}, so we can use concise idioms + * like in the following example. + * + *

Pointcut pc = new ComposablePointcut()
+ *                      .union(classFilter)
+ *                      .intersection(methodMatcher)
+ *                      .intersection(pointcut);
* * @author Rod Johnson * @author Juergen Hoeller @@ -199,7 +202,7 @@ public class ComposablePointcut implements Pointcut, Serializable { @Override public String toString() { - return "ComposablePointcut: " + this.classFilter + ", " +this.methodMatcher; + return "ComposablePointcut: " + this.classFilter + ", " + this.methodMatcher; } } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java index b8162383bf..8e65ea63f0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ import org.springframework.util.ClassUtils; * @author Juergen Hoeller * @since 11.11.2003 */ -@SuppressWarnings({"serial" }) +@SuppressWarnings("serial") public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFilter, Ordered, Serializable { private final Advice advice; @@ -113,8 +113,8 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil for (Class ifc : this.interfaces) { if (this.advice instanceof DynamicIntroductionAdvice && !((DynamicIntroductionAdvice) this.advice).implementsInterface(ifc)) { - throw new IllegalArgumentException("DynamicIntroductionAdvice [" + this.advice + "] " + - "does not implement interface [" + ifc.getName() + "] specified for introduction"); + throw new IllegalArgumentException("DynamicIntroductionAdvice [" + this.advice + "] " + + "does not implement interface [" + ifc.getName() + "] specified for introduction"); } } } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java index 240d5707c1..20a11aa59c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,9 @@ import org.springframework.lang.Nullable; import org.springframework.util.PatternMatchUtils; /** - * Pointcut bean for simple method name matches, as alternative to regexp patterns. - * Does not handle overloaded methods: all methods with a given name will be eligible. + * Pointcut bean for simple method name matches, as an alternative to regexp patterns. + * + *

Does not handle overloaded methods: all methods with a given name will be eligible. * * @author Juergen Hoeller * @author Rod Johnson diff --git a/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java b/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java index 24e7c98cd0..7cb3e93af4 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,8 @@ import org.springframework.util.Assert; /** * Pointcut constants for matching getters and setters, * and static methods useful for manipulating and evaluating pointcuts. - * These methods are particularly useful for composing pointcuts + * + *

These methods are particularly useful for composing pointcuts * using the union and intersection methods. * * @author Rod Johnson diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java index 017ad739fb..b8c7995e12 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +62,7 @@ public class AnnotationMatchingPointcut implements Pointcut { } /** - * Create a new AnnotationMatchingPointcut for the given annotation type. + * Create a new AnnotationMatchingPointcut for the given annotation types. * @param classAnnotationType the annotation type to look for at the class level * (can be {@code null}) * @param methodAnnotationType the annotation type to look for at the method level @@ -75,7 +75,7 @@ public class AnnotationMatchingPointcut implements Pointcut { } /** - * Create a new AnnotationMatchingPointcut for the given annotation type. + * Create a new AnnotationMatchingPointcut for the given annotation types. * @param classAnnotationType the annotation type to look for at the class level * (can be {@code null}) * @param methodAnnotationType the annotation type to look for at the method level @@ -138,7 +138,7 @@ public class AnnotationMatchingPointcut implements Pointcut { @Override public String toString() { - return "AnnotationMatchingPointcut: " + this.classFilter + ", " +this.methodMatcher; + return "AnnotationMatchingPointcut: " + this.classFilter + ", " + this.methodMatcher; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 7dcf26c6b9..4d3bb04611 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -139,9 +139,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean /** - * Create a new AutowiredAnnotationBeanPostProcessor - * for Spring's standard {@link Autowired} annotation. - *

Also supports JSR-330's {@link javax.inject.Inject} annotation, if available. + * Create a new {@code AutowiredAnnotationBeanPostProcessor} for Spring's + * standard {@link Autowired @Autowired} annotation. + *

Also supports JSR-330's {@link javax.inject.Inject @Inject} annotation, + * if available. */ @SuppressWarnings("unchecked") public AutowiredAnnotationBeanPostProcessor() { @@ -236,7 +237,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean public Constructor[] determineCandidateConstructors(Class beanClass, final String beanName) throws BeanCreationException { - // Let's check for lookup methods here.. + // Let's check for lookup methods here... if (!this.lookupMethodsChecked.contains(beanName)) { try { ReflectionUtils.doWithMethods(beanClass, method -> { @@ -245,7 +246,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean Assert.state(this.beanFactory != null, "No BeanFactory available"); LookupOverride override = new LookupOverride(method, lookup.value()); try { - RootBeanDefinition mbd = (RootBeanDefinition) this.beanFactory.getMergedBeanDefinition(beanName); + RootBeanDefinition mbd = (RootBeanDefinition) + this.beanFactory.getMergedBeanDefinition(beanName); mbd.getMethodOverrides().addOverride(override); } catch (NoSuchBeanDefinitionException ex) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java index f456631c54..064f408213 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java @@ -249,7 +249,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt public int accept(Method method) { MethodOverride methodOverride = getBeanDefinition().getMethodOverrides().getOverride(method); if (logger.isTraceEnabled()) { - logger.trace("Override for '" + method.getName() + "' is [" + methodOverride + "]"); + logger.trace("MethodOverride for " + method + ": " + methodOverride); } if (methodOverride == null) { return PASSTHROUGH; diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java index f1bcf9fd3f..492866e3ea 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java @@ -369,26 +369,6 @@ public class AnnotationAttributes extends LinkedHashMap { } } - /** - * Store the supplied {@code value} in this map under the specified - * {@code key}, unless a value is already stored under the key. - * @param key the key under which to store the value - * @param value the value to store - * @return the current value stored in this map, or {@code null} if no - * value was previously stored in this map - * @see #get - * @see #put - * @since 4.2 - */ - @Override - public Object putIfAbsent(String key, Object value) { - Object obj = get(key); - if (obj == null) { - obj = put(key, value); - } - return obj; - } - @Override public String toString() { Iterator> entries = entrySet().iterator(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java index e55d68285d..de636f2ad8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ public class SseEmitter extends ResponseBodyEmitter { static final MediaType TEXT_PLAIN = new MediaType("text", "plain", StandardCharsets.UTF_8); - static final MediaType UTF8_TEXT_EVENTSTREAM = new MediaType("text", "event-stream", StandardCharsets.UTF_8); + static final MediaType TEXT_EVENTSTREAM = new MediaType("text", "event-stream", StandardCharsets.UTF_8); /** @@ -70,7 +70,7 @@ public class SseEmitter extends ResponseBodyEmitter { HttpHeaders headers = outputMessage.getHeaders(); if (headers.getContentType() == null) { - headers.setContentType(UTF8_TEXT_EVENTSTREAM); + headers.setContentType(TEXT_EVENTSTREAM); } } @@ -82,10 +82,8 @@ public class SseEmitter extends ResponseBodyEmitter { * SseEmitter emitter = new SseEmitter(); * emitter.send(event().data(myObject)); * - * *

Please, see {@link ResponseBodyEmitter#send(Object) parent Javadoc} * for important notes on exception handling. - * * @param object the object to write * @throws IOException raised when an I/O error occurs * @throws java.lang.IllegalStateException wraps any other errors @@ -103,10 +101,8 @@ public class SseEmitter extends ResponseBodyEmitter { * SseEmitter emitter = new SseEmitter(); * emitter.send(event().data(myObject, MediaType.APPLICATION_JSON)); * - * *

Please, see {@link ResponseBodyEmitter#send(Object) parent Javadoc} * for important notes on exception handling. - * * @param object the object to write * @param mediaType a MediaType hint for selecting an HttpMessageConverter * @throws IOException raised when an I/O error occurs