Use pattern matching for instanceof where appropriate

Closes gh-28181
This commit is contained in:
dreis2211
2022-06-20 19:20:03 +02:00
committed by Andy Wilkinson
parent b17eb9d6b5
commit f2101684b7
9 changed files with 18 additions and 19 deletions

View File

@@ -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());

View File

@@ -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());

View File

@@ -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();
}
}