mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +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());
|
||||
}
|
||||
BeanDefinition dataSourceDefinition = context.getRegistry().getBeanDefinition(dataSourceBeanNames[0]);
|
||||
if (dataSourceDefinition instanceof AnnotatedBeanDefinition
|
||||
&& ((AnnotatedBeanDefinition) dataSourceDefinition).getFactoryMethodMetadata() != null
|
||||
&& ((AnnotatedBeanDefinition) dataSourceDefinition).getFactoryMethodMetadata()
|
||||
.getDeclaringClassName().startsWith(DataSourceAutoConfiguration.class.getPackage().getName()
|
||||
+ ".DataSourceConfiguration$")) {
|
||||
if (dataSourceDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition
|
||||
&& annotatedBeanDefinition.getFactoryMethodMetadata() != null
|
||||
&& annotatedBeanDefinition.getFactoryMethodMetadata().getDeclaringClassName().startsWith(
|
||||
DataSourceAutoConfiguration.class.getPackage().getName() + ".DataSourceConfiguration$")) {
|
||||
return ConditionOutcome.match(message.foundExactly("auto-configured DataSource"));
|
||||
}
|
||||
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());
|
||||
}
|
||||
BeanDefinition beanDefinition = context.getRegistry().getBeanDefinition(beanNames[0]);
|
||||
if (beanDefinition instanceof AnnotatedBeanDefinition
|
||||
&& isAutoConfigured((AnnotatedBeanDefinition) beanDefinition)) {
|
||||
if (beanDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition
|
||||
&& isAutoConfigured(annotatedBeanDefinition)) {
|
||||
return ConditionOutcome.match(message.foundExactly("auto-configured ConnectionFactory"));
|
||||
}
|
||||
return ConditionOutcome.noMatch(message.didNotFind("an auto-configured ConnectionFactory").atAll());
|
||||
|
@ -191,8 +191,8 @@ public class LocalDevToolsAutoConfiguration {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (event instanceof ContextRefreshedEvent || (event instanceof ClassPathChangedEvent
|
||||
&& !((ClassPathChangedEvent) event).isRestartRequired())) {
|
||||
if (event instanceof ContextRefreshedEvent || (event instanceof ClassPathChangedEvent classPathChangedEvent
|
||||
&& !classPathChangedEvent.isRestartRequired())) {
|
||||
this.liveReloadServer.triggerReload();
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ final class ConfigurationPropertiesBeanRegistrar {
|
||||
}
|
||||
|
||||
private boolean containsBeanDefinition(BeanFactory beanFactory, String name) {
|
||||
if (beanFactory instanceof ListableBeanFactory
|
||||
&& ((ListableBeanFactory) beanFactory).containsBeanDefinition(name)) {
|
||||
if (beanFactory instanceof ListableBeanFactory listableBeanFactory
|
||||
&& listableBeanFactory.containsBeanDefinition(name)) {
|
||||
return true;
|
||||
}
|
||||
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,
|
||||
ResolvableType elementType, Object value) {
|
||||
if (value == null || value instanceof CharSequence && ((CharSequence) value).length() == 0) {
|
||||
if (value == null || (value instanceof CharSequence charSequence && charSequence.isEmpty())) {
|
||||
return;
|
||||
}
|
||||
Object aggregate = convert(value, aggregateType, target.getAnnotations());
|
||||
|
@ -97,7 +97,7 @@ class OriginTrackedYamlLoader extends YamlProcessor {
|
||||
@Override
|
||||
public Object getData() throws NoSuchElementException {
|
||||
Object data = super.getData();
|
||||
if (data instanceof CharSequence && ((CharSequence) data).length() == 0) {
|
||||
if (data instanceof CharSequence charSequence && charSequence.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
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");
|
||||
* 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) {
|
||||
for (String candidate : CANDIDATES) {
|
||||
Object value = propertySource.getProperty(candidate);
|
||||
if (value instanceof String && StringUtils.hasLength((String) value)) {
|
||||
return new JsonPropertyValue(propertySource, candidate, (String) value);
|
||||
if (value instanceof String string && StringUtils.hasLength(string)) {
|
||||
return new JsonPropertyValue(propertySource, candidate, string);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -81,8 +81,8 @@ class ServletComponentRegisteringPostProcessor implements BeanFactoryPostProcess
|
||||
}
|
||||
|
||||
private boolean isRunningInEmbeddedWebServer() {
|
||||
return this.applicationContext instanceof WebApplicationContext
|
||||
&& ((WebApplicationContext) this.applicationContext).getServletContext() == null;
|
||||
return this.applicationContext instanceof WebApplicationContext webApplicationContext
|
||||
&& webApplicationContext.getServletContext() == null;
|
||||
}
|
||||
|
||||
private ClassPathScanningCandidateComponentProvider createComponentProvider() {
|
||||
|
@ -107,7 +107,7 @@ class StaticResourceJars {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user