From 98f4692c629c03b7a8d3d2ade5794a2fe1980394 Mon Sep 17 00:00:00 2001 From: igor-suhorukov Date: Sun, 25 Feb 2018 00:50:47 +0300 Subject: [PATCH] Polish This commit changes invocations to immediately return the expression instead of assigning it to a temporary variable. The method name should be sufficient for callers to know exactly what will be returned. Closes gh-12211 --- .../jersey/JerseyManagementChildContextConfiguration.java | 3 +-- .../data/elasticsearch/ElasticsearchAutoConfiguration.java | 3 +-- .../data/neo4j/Neo4jDataAutoConfiguration.java | 4 +--- .../cli/app/SpringApplicationWebApplicationInitializer.java | 3 +-- .../springframework/boot/cli/compiler/GroovyCompiler.java | 3 +-- .../boot/cli/compiler/grape/AetherGrapeEngine.java | 3 +-- .../org/springframework/boot/cli/util/ResourceUtils.java | 3 +-- .../boot/test/context/ImportsContextCustomizer.java | 3 +-- .../boot/test/context/SpringBootContextLoader.java | 3 +-- .../boot/configurationprocessor/MetadataStore.java | 6 ++---- .../boot/liquibase/SpringPackageScanClassResolver.java | 3 +-- 11 files changed, 12 insertions(+), 25 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementChildContextConfiguration.java index 7a331ce578..4e66aa867a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementChildContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementChildContextConfiguration.java @@ -55,9 +55,8 @@ public class JerseyManagementChildContextConfiguration { @Bean public ServletRegistrationBean jerseyServletRegistration() { - ServletRegistrationBean registration = new ServletRegistrationBean<>( + return new ServletRegistrationBean<>( new ServletContainer(endpointResourceConfig()), "/*"); - return registration; } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java index f64a7a1e2a..040dfba616 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java @@ -57,8 +57,7 @@ public class ElasticsearchAutoConfiguration { factory.setClusterNodes(this.properties.getClusterNodes()); factory.setProperties(createProperties()); factory.afterPropertiesSet(); - TransportClient client = factory.getObject(); - return client; + return factory.getObject(); } private Properties createProperties() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java index 7409379d21..8d5d33fa58 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java @@ -64,9 +64,7 @@ public class Neo4jDataAutoConfiguration { @Bean @ConditionalOnMissingBean public org.neo4j.ogm.config.Configuration configuration(Neo4jProperties properties) { - org.neo4j.ogm.config.Configuration configuration = properties - .createConfiguration(); - return configuration; + return properties.createConfiguration(); } @Bean diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationWebApplicationInitializer.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationWebApplicationInitializer.java index b87d8e262d..d800fb5d17 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationWebApplicationInitializer.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/app/SpringApplicationWebApplicationInitializer.java @@ -64,8 +64,7 @@ public class SpringApplicationWebApplicationInitializer private Manifest getManifest(ServletContext servletContext) throws IOException { InputStream stream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF"); - Manifest manifest = (stream == null ? null : new Manifest(stream)); - return manifest; + return (stream == null ? null : new Manifest(stream)); } @Override diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java index 462f48aa71..8558bbe53a 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java @@ -235,8 +235,7 @@ public class GroovyCompiler { try { Field field = CompilationUnit.class.getDeclaredField("phaseOperations"); field.setAccessible(true); - LinkedList[] phaseOperations = (LinkedList[]) field.get(compilationUnit); - return phaseOperations; + return (LinkedList[]) field.get(compilationUnit); } catch (Exception ex) { throw new IllegalStateException( diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java index 27803cf69a..5c9ce72ec3 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java @@ -324,10 +324,9 @@ public class AetherGrapeEngine implements GrapeEngine { } private DependencyRequest getDependencyRequest(CollectRequest collectRequest) { - DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, + return new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME)); - return dependencyRequest; } private void addManagedDependencies(DependencyResult result) { diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java index 289d048afe..1589c83918 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java @@ -160,8 +160,7 @@ public abstract class ResourceUtils { } else { if (location.startsWith(FILE_URL_PREFIX)) { - Resource resource = this.files.getResource(location); - return resource; + return this.files.getResource(location); } try { // Try to parse the location as a URL... diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java index 6fc78d9c00..932560de50 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java @@ -112,8 +112,7 @@ class ImportsContextCustomizer implements ContextCustomizer { private BeanDefinition registerBean(BeanDefinitionRegistry registry, AnnotatedBeanDefinitionReader reader, String beanName, Class type) { reader.registerBean(type, beanName); - BeanDefinition definition = registry.getBeanDefinition(beanName); - return definition; + return registry.getBeanDefinition(beanName); } @Override diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java index 1acb71d7fb..fd9aaeece3 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java @@ -135,8 +135,7 @@ public class SpringBootContextLoader extends AbstractContextLoader { application.setWebApplicationType(WebApplicationType.NONE); } application.setInitializers(initializers); - ConfigurableApplicationContext context = application.run(); - return context; + return application.run(); } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataStore.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataStore.java index f12400d8b0..f917107b1a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataStore.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataStore.java @@ -95,15 +95,13 @@ public class MetadataStore { } private FileObject getMetadataResource() throws IOException { - FileObject resource = this.environment.getFiler() + return this.environment.getFiler() .getResource(StandardLocation.CLASS_OUTPUT, "", METADATA_PATH); - return resource; } private FileObject createMetadataResource() throws IOException { - FileObject resource = this.environment.getFiler() + return this.environment.getFiler() .createResource(StandardLocation.CLASS_OUTPUT, "", METADATA_PATH); - return resource; } private InputStream getAdditionalMetadataStream() throws IOException { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/SpringPackageScanClassResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/SpringPackageScanClassResolver.java index 90ac46584b..cc9811860e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/SpringPackageScanClassResolver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/liquibase/SpringPackageScanClassResolver.java @@ -68,8 +68,7 @@ public class SpringPackageScanClassResolver extends DefaultPackageScanClassResol loader); String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(packageName) + "/**/*.class"; - Resource[] resources = resolver.getResources(pattern); - return resources; + return resolver.getResources(pattern); } private Class loadClass(ClassLoader loader, MetadataReaderFactory readerFactory,