From 0e3f23eeb71b0c5291ece040c837e07318ccdb8a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 13 Aug 2018 13:42:19 +0200 Subject: [PATCH] Polishing --- .../AutowiredAnnotationBeanPostProcessor.java | 2 +- .../factory/support/ConstructorResolver.java | 18 +++++------ .../support/InstantiationStrategy.java | 14 ++++----- .../cache/jcache/JCacheCache.java | 9 +++--- .../cache/jcache/JCacheCacheManager.java | 6 ++-- .../SpringCacheAnnotationParser.java | 8 +++-- .../util/xml/StaxStreamXMLReader.java | 2 +- .../http/codec/xml/XmlEventDecoder.java | 30 ++++++++++--------- 8 files changed, 47 insertions(+), 42 deletions(-) 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 c41a0972ff..12c2bb35e8 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 @@ -252,7 +252,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } catch (NoSuchBeanDefinitionException ex) { throw new BeanCreationException(beanName, - "Cannot apply @Lookup to beans without corresponding bean definition"); + "Cannot apply @Lookup to beans without corresponding bean definition"); } } }); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java index dde17da10e..691910b8cc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java @@ -107,8 +107,8 @@ class ConstructorResolver { * or {@code null} if none (-> use constructor argument values from bean definition) * @return a BeanWrapper for the new instance */ - public BeanWrapper autowireConstructor(final String beanName, final RootBeanDefinition mbd, - @Nullable Constructor[] chosenCtors, @Nullable final Object[] explicitArgs) { + public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd, + @Nullable Constructor[] chosenCtors, @Nullable Object[] explicitArgs) { BeanWrapperImpl bw = new BeanWrapperImpl(); this.beanFactory.initBeanWrapper(bw); @@ -326,7 +326,7 @@ class ConstructorResolver { * the {@link RootBeanDefinition#isNonPublicAccessAllowed()} flag. * Called as the starting point for factory method determination. */ - private Method[] getCandidateMethods(final Class factoryClass, final RootBeanDefinition mbd) { + private Method[] getCandidateMethods(Class factoryClass, RootBeanDefinition mbd) { if (System.getSecurityManager() != null) { return AccessController.doPrivileged((PrivilegedAction) () -> (mbd.isNonPublicAccessAllowed() ? @@ -354,7 +354,7 @@ class ConstructorResolver { * @return a BeanWrapper for the new instance */ public BeanWrapper instantiateUsingFactoryMethod( - final String beanName, final RootBeanDefinition mbd, @Nullable final Object[] explicitArgs) { + String beanName, RootBeanDefinition mbd, @Nullable Object[] explicitArgs) { BeanWrapperImpl bw = new BeanWrapperImpl(); this.beanFactory.initBeanWrapper(bw); @@ -417,13 +417,13 @@ class ConstructorResolver { factoryClass = ClassUtils.getUserClass(factoryClass); Method[] rawCandidates = getCandidateMethods(factoryClass, mbd); - List candidateSet = new ArrayList<>(); + List candidateList = new ArrayList<>(); for (Method candidate : rawCandidates) { if (Modifier.isStatic(candidate.getModifiers()) == isStatic && mbd.isFactoryMethod(candidate)) { - candidateSet.add(candidate); + candidateList.add(candidate); } } - Method[] candidates = candidateSet.toArray(new Method[0]); + Method[] candidates = candidateList.toArray(new Method[0]); AutowireUtils.sortFactoryMethods(candidates); ConstructorArgumentValues resolvedValues = null; @@ -456,7 +456,7 @@ class ConstructorResolver { if (paramTypes.length >= minNrOfArgs) { ArgumentsHolder argsHolder; - if (explicitArgs != null){ + if (explicitArgs != null) { // Explicit arguments given -> arguments length must match exactly. if (paramTypes.length != explicitArgs.length) { continue; @@ -529,7 +529,7 @@ class ConstructorResolver { argTypes.add(arg != null ? arg.getClass().getSimpleName() : "null"); } } - else if (resolvedValues != null){ + else if (resolvedValues != null) { Set valueHolders = new LinkedHashSet<>(resolvedValues.getArgumentCount()); valueHolders.addAll(resolvedValues.getIndexedArgumentValues().values()); valueHolders.addAll(resolvedValues.getGenericArgumentValues()); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java index e2f38783ff..84450315ca 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -38,8 +38,8 @@ public interface InstantiationStrategy { /** * Return an instance of the bean with the given name in this factory. * @param bd the bean definition - * @param beanName the name of the bean when it's created in this context. - * The name can be {@code null} if we're autowiring a bean which doesn't + * @param beanName the name of the bean when it is created in this context. + * The name can be {@code null} if we are autowiring a bean which doesn't * belong to the factory. * @param owner the owning BeanFactory * @return a bean instance for this bean definition @@ -52,8 +52,8 @@ public interface InstantiationStrategy { * Return an instance of the bean with the given name in this factory, * creating it via the given constructor. * @param bd the bean definition - * @param beanName the name of the bean when it's created in this context. - * The name can be {@code null} if we're autowiring a bean which doesn't + * @param beanName the name of the bean when it is created in this context. + * The name can be {@code null} if we are autowiring a bean which doesn't * belong to the factory. * @param owner the owning BeanFactory * @param ctor the constructor to use @@ -68,8 +68,8 @@ public interface InstantiationStrategy { * Return an instance of the bean with the given name in this factory, * creating it via the given factory method. * @param bd the bean definition - * @param beanName the name of the bean when it's created in this context. - * The name can be {@code null} if we're autowiring a bean which doesn't + * @param beanName the name of the bean when it is created in this context. + * The name can be {@code null} if we are autowiring a bean which doesn't * belong to the factory. * @param owner the owning BeanFactory * @param factoryBean the factory bean instance to call the factory method on, diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java index ed6f8cbaa0..fb341119d9 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java @@ -17,6 +17,7 @@ package org.springframework.cache.jcache; import java.util.concurrent.Callable; +import javax.cache.Cache; import javax.cache.processor.EntryProcessor; import javax.cache.processor.EntryProcessorException; import javax.cache.processor.MutableEntry; @@ -37,14 +38,14 @@ import org.springframework.util.Assert; */ public class JCacheCache extends AbstractValueAdaptingCache { - private final javax.cache.Cache cache; + private final Cache cache; /** * Create an {@link org.springframework.cache.jcache.JCacheCache} instance. * @param jcache backing JCache Cache instance */ - public JCacheCache(javax.cache.Cache jcache) { + public JCacheCache(Cache jcache) { this(jcache, true); } @@ -53,7 +54,7 @@ public class JCacheCache extends AbstractValueAdaptingCache { * @param jcache backing JCache Cache instance * @param allowNullValues whether to accept and convert null values for this cache */ - public JCacheCache(javax.cache.Cache jcache, boolean allowNullValues) { + public JCacheCache(Cache jcache, boolean allowNullValues) { super(allowNullValues); Assert.notNull(jcache, "Cache must not be null"); this.cache = jcache; @@ -66,7 +67,7 @@ public class JCacheCache extends AbstractValueAdaptingCache { } @Override - public final javax.cache.Cache getNativeCache() { + public final Cache getNativeCache() { return this.cache; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java index 50a39b3dc3..69c094ebce 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java @@ -39,7 +39,7 @@ import org.springframework.util.Assert; public class JCacheCacheManager extends AbstractTransactionSupportingCacheManager { @Nullable - private javax.cache.CacheManager cacheManager; + private CacheManager cacheManager; private boolean allowNullValues = true; @@ -63,7 +63,7 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage /** * Set the backing JCache {@link javax.cache.CacheManager}. */ - public void setCacheManager(@Nullable javax.cache.CacheManager cacheManager) { + public void setCacheManager(@Nullable CacheManager cacheManager) { this.cacheManager = cacheManager; } @@ -71,7 +71,7 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage * Return the backing JCache {@link javax.cache.CacheManager}. */ @Nullable - public javax.cache.CacheManager getCacheManager() { + public CacheManager getCacheManager() { return this.cacheManager; } diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java b/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java index 17874bba4e..bac6e7930c 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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 SpringCacheAnnotationParser implements CacheAnnotationParser, Seria } @Nullable - protected Collection parseCacheAnnotations(DefaultCacheConfig cachingConfig, AnnotatedElement ae) { + private Collection parseCacheAnnotations(DefaultCacheConfig cachingConfig, AnnotatedElement ae) { Collection ops = parseCacheAnnotations(cachingConfig, ae, false); if (ops != null && ops.size() > 1 && ae.getAnnotations().length > 0) { // More than one operation found -> local declarations override interface-declared ones... @@ -88,6 +88,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria ops.add(parseCacheableAnnotation(ae, cachingConfig, cacheable)); } } + Collection evicts = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, CacheEvict.class) : AnnotatedElementUtils.findAllMergedAnnotations(ae, CacheEvict.class)); if (!evicts.isEmpty()) { @@ -96,6 +97,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria ops.add(parseEvictAnnotation(ae, cachingConfig, evict)); } } + Collection puts = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, CachePut.class) : AnnotatedElementUtils.findAllMergedAnnotations(ae, CachePut.class)); if (!puts.isEmpty()) { @@ -104,6 +106,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria ops.add(parsePutAnnotation(ae, cachingConfig, put)); } } + Collection cachings = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, Caching.class) : AnnotatedElementUtils.findAllMergedAnnotations(ae, Caching.class)); if (!cachings.isEmpty()) { @@ -313,7 +316,6 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria builder.setCacheManager(this.cacheManager); } } - } } diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java b/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java index 06c9a7069d..2a20b94b94 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java @@ -243,7 +243,7 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { private void handleDtd() throws SAXException { if (getLexicalHandler() != null) { - javax.xml.stream.Location location = this.reader.getLocation(); + Location location = this.reader.getLocation(); getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId()); } if (getLexicalHandler() != null) { diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java index e8e1cbf5e8..4971353b99 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java @@ -47,17 +47,19 @@ import org.springframework.util.MimeTypeUtils; import org.springframework.util.xml.StaxUtils; /** - * Decodes a {@link DataBuffer} stream into a stream of {@link XMLEvent}s. - * That is, given the following XML: + * Decodes a {@link DataBuffer} stream into a stream of {@link XMLEvent XMLEvents}. * - *
{@code
- * 
- *     foo
- *     bar
- * }
+ * 

Given the following XML: + * + *

+ * <root>
+ *     <child>foo</child>
+ *     <child>bar</child>
+ * </root>
  * 
* - * this method with result in a flux with the following events: + * this decoder will produce a {@link Flux} with the following events: + * *
    *
  1. {@link javax.xml.stream.events.StartDocument}
  2. *
  3. {@link javax.xml.stream.events.StartElement} {@code root}
  4. @@ -70,8 +72,8 @@ import org.springframework.util.xml.StaxUtils; *
  5. {@link javax.xml.stream.events.EndElement} {@code root}
  6. *
* - * Note that this decoder is not registered by default but used internally - * by other decoders who are there by default. + *

Note that this decoder is not registered by default but is used internally + * by other decoders which are registered by default. * * @author Arjen Poutsma * @since 5.0 @@ -97,7 +99,7 @@ public class XmlEventDecoder extends AbstractDecoder { @Nullable MimeType mimeType, @Nullable Map hints) { Flux flux = Flux.from(inputStream); - if (useAalto) { + if (this.useAalto) { AaltoDataBufferToXmlEvent aaltoMapper = new AaltoDataBufferToXmlEvent(); return flux.flatMap(aaltoMapper) .doFinally(signalType -> aaltoMapper.endOfInput()); @@ -135,15 +137,15 @@ public class XmlEventDecoder extends AbstractDecoder { @Override public Publisher apply(DataBuffer dataBuffer) { try { - streamReader.getInputFeeder().feedInput(dataBuffer.asByteBuffer()); + this.streamReader.getInputFeeder().feedInput(dataBuffer.asByteBuffer()); List events = new ArrayList<>(); while (true) { - if (streamReader.next() == AsyncXMLStreamReader.EVENT_INCOMPLETE) { + if (this.streamReader.next() == AsyncXMLStreamReader.EVENT_INCOMPLETE) { // no more events with what currently has been fed to the reader break; } else { - XMLEvent event = eventAllocator.allocate(streamReader); + XMLEvent event = this.eventAllocator.allocate(this.streamReader); events.add(event); if (event.isEndDocument()) { break;