mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Use pattern matching for instanceof where appropriate
Closes gh-28181
This commit is contained in:
parent
b17eb9d6b5
commit
f2101684b7
@ -186,11 +186,10 @@ public class DevToolsDataSourceAutoConfiguration {
|
|||||||
return ConditionOutcome.noMatch(message.didNotFind("a single DataSourceProperties bean").atAll());
|
return ConditionOutcome.noMatch(message.didNotFind("a single DataSourceProperties bean").atAll());
|
||||||
}
|
}
|
||||||
BeanDefinition dataSourceDefinition = context.getRegistry().getBeanDefinition(dataSourceBeanNames[0]);
|
BeanDefinition dataSourceDefinition = context.getRegistry().getBeanDefinition(dataSourceBeanNames[0]);
|
||||||
if (dataSourceDefinition instanceof AnnotatedBeanDefinition
|
if (dataSourceDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition
|
||||||
&& ((AnnotatedBeanDefinition) dataSourceDefinition).getFactoryMethodMetadata() != null
|
&& annotatedBeanDefinition.getFactoryMethodMetadata() != null
|
||||||
&& ((AnnotatedBeanDefinition) dataSourceDefinition).getFactoryMethodMetadata()
|
&& annotatedBeanDefinition.getFactoryMethodMetadata().getDeclaringClassName().startsWith(
|
||||||
.getDeclaringClassName().startsWith(DataSourceAutoConfiguration.class.getPackage().getName()
|
DataSourceAutoConfiguration.class.getPackage().getName() + ".DataSourceConfiguration$")) {
|
||||||
+ ".DataSourceConfiguration$")) {
|
|
||||||
return ConditionOutcome.match(message.foundExactly("auto-configured DataSource"));
|
return ConditionOutcome.match(message.foundExactly("auto-configured DataSource"));
|
||||||
}
|
}
|
||||||
return ConditionOutcome.noMatch(message.didNotFind("an auto-configured DataSource").atAll());
|
return ConditionOutcome.noMatch(message.didNotFind("an auto-configured DataSource").atAll());
|
||||||
|
@ -118,8 +118,8 @@ public class DevToolsR2dbcAutoConfiguration {
|
|||||||
return ConditionOutcome.noMatch(message.didNotFind("a single ConnectionFactory bean").atAll());
|
return ConditionOutcome.noMatch(message.didNotFind("a single ConnectionFactory bean").atAll());
|
||||||
}
|
}
|
||||||
BeanDefinition beanDefinition = context.getRegistry().getBeanDefinition(beanNames[0]);
|
BeanDefinition beanDefinition = context.getRegistry().getBeanDefinition(beanNames[0]);
|
||||||
if (beanDefinition instanceof AnnotatedBeanDefinition
|
if (beanDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition
|
||||||
&& isAutoConfigured((AnnotatedBeanDefinition) beanDefinition)) {
|
&& isAutoConfigured(annotatedBeanDefinition)) {
|
||||||
return ConditionOutcome.match(message.foundExactly("auto-configured ConnectionFactory"));
|
return ConditionOutcome.match(message.foundExactly("auto-configured ConnectionFactory"));
|
||||||
}
|
}
|
||||||
return ConditionOutcome.noMatch(message.didNotFind("an auto-configured ConnectionFactory").atAll());
|
return ConditionOutcome.noMatch(message.didNotFind("an auto-configured ConnectionFactory").atAll());
|
||||||
|
@ -191,8 +191,8 @@ public class LocalDevToolsAutoConfiguration {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ApplicationEvent event) {
|
public void onApplicationEvent(ApplicationEvent event) {
|
||||||
if (event instanceof ContextRefreshedEvent || (event instanceof ClassPathChangedEvent
|
if (event instanceof ContextRefreshedEvent || (event instanceof ClassPathChangedEvent classPathChangedEvent
|
||||||
&& !((ClassPathChangedEvent) event).isRestartRequired())) {
|
&& !classPathChangedEvent.isRestartRequired())) {
|
||||||
this.liveReloadServer.triggerReload();
|
this.liveReloadServer.triggerReload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ final class ConfigurationPropertiesBeanRegistrar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean containsBeanDefinition(BeanFactory beanFactory, String name) {
|
private boolean containsBeanDefinition(BeanFactory beanFactory, String name) {
|
||||||
if (beanFactory instanceof ListableBeanFactory
|
if (beanFactory instanceof ListableBeanFactory listableBeanFactory
|
||||||
&& ((ListableBeanFactory) beanFactory).containsBeanDefinition(name)) {
|
&& listableBeanFactory.containsBeanDefinition(name)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (beanFactory instanceof HierarchicalBeanFactory hierarchicalBeanFactory) {
|
if (beanFactory instanceof HierarchicalBeanFactory hierarchicalBeanFactory) {
|
||||||
|
@ -89,7 +89,7 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
|
|||||||
|
|
||||||
private void bindValue(Bindable<?> target, Collection<Object> collection, ResolvableType aggregateType,
|
private void bindValue(Bindable<?> target, Collection<Object> collection, ResolvableType aggregateType,
|
||||||
ResolvableType elementType, Object value) {
|
ResolvableType elementType, Object value) {
|
||||||
if (value == null || value instanceof CharSequence && ((CharSequence) value).length() == 0) {
|
if (value == null || (value instanceof CharSequence charSequence && charSequence.isEmpty())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object aggregate = convert(value, aggregateType, target.getAnnotations());
|
Object aggregate = convert(value, aggregateType, target.getAnnotations());
|
||||||
|
@ -97,7 +97,7 @@ class OriginTrackedYamlLoader extends YamlProcessor {
|
|||||||
@Override
|
@Override
|
||||||
public Object getData() throws NoSuchElementException {
|
public Object getData() throws NoSuchElementException {
|
||||||
Object data = super.getData();
|
Object data = super.getData();
|
||||||
if (data instanceof CharSequence && ((CharSequence) data).length() == 0) {
|
if (data instanceof CharSequence charSequence && charSequence.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -213,8 +213,8 @@ public class SpringApplicationJsonEnvironmentPostProcessor implements Environmen
|
|||||||
static JsonPropertyValue get(PropertySource<?> propertySource) {
|
static JsonPropertyValue get(PropertySource<?> propertySource) {
|
||||||
for (String candidate : CANDIDATES) {
|
for (String candidate : CANDIDATES) {
|
||||||
Object value = propertySource.getProperty(candidate);
|
Object value = propertySource.getProperty(candidate);
|
||||||
if (value instanceof String && StringUtils.hasLength((String) value)) {
|
if (value instanceof String string && StringUtils.hasLength(string)) {
|
||||||
return new JsonPropertyValue(propertySource, candidate, (String) value);
|
return new JsonPropertyValue(propertySource, candidate, string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -81,8 +81,8 @@ class ServletComponentRegisteringPostProcessor implements BeanFactoryPostProcess
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isRunningInEmbeddedWebServer() {
|
private boolean isRunningInEmbeddedWebServer() {
|
||||||
return this.applicationContext instanceof WebApplicationContext
|
return this.applicationContext instanceof WebApplicationContext webApplicationContext
|
||||||
&& ((WebApplicationContext) this.applicationContext).getServletContext() == null;
|
&& webApplicationContext.getServletContext() == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClassPathScanningCandidateComponentProvider createComponentProvider() {
|
private ClassPathScanningCandidateComponentProvider createComponentProvider() {
|
||||||
|
@ -107,7 +107,7 @@ class StaticResourceJars {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addUrlConnection(List<URL> urls, URL url, URLConnection connection) {
|
private void addUrlConnection(List<URL> urls, URL url, URLConnection connection) {
|
||||||
if (connection instanceof JarURLConnection && isResourcesJar((JarURLConnection) connection)) {
|
if (connection instanceof JarURLConnection jarURLConnection && isResourcesJar(jarURLConnection)) {
|
||||||
urls.add(url);
|
urls.add(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user