Use enhanced switch expressions where feasible
Closes gh-28014
This commit is contained in:
@@ -68,14 +68,10 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
|
||||
*/
|
||||
@Override
|
||||
public String[] selectImports(AdviceMode adviceMode) {
|
||||
switch (adviceMode) {
|
||||
case PROXY:
|
||||
return getProxyImports();
|
||||
case ASPECTJ:
|
||||
return getAspectJImports();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch (adviceMode) {
|
||||
case PROXY -> getProxyImports();
|
||||
case ASPECTJ -> getAspectJImports();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,38 +78,32 @@ public abstract class TypeFilterUtils {
|
||||
|
||||
for (Class<?> filterClass : filterAttributes.getClassArray("classes")) {
|
||||
switch (filterType) {
|
||||
case ANNOTATION:
|
||||
case ANNOTATION -> {
|
||||
Assert.isAssignable(Annotation.class, filterClass,
|
||||
"@ComponentScan ANNOTATION type filter requires an annotation type");
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<Annotation> annotationType = (Class<Annotation>) filterClass;
|
||||
typeFilters.add(new AnnotationTypeFilter(annotationType));
|
||||
break;
|
||||
case ASSIGNABLE_TYPE:
|
||||
typeFilters.add(new AssignableTypeFilter(filterClass));
|
||||
break;
|
||||
case CUSTOM:
|
||||
}
|
||||
case ASSIGNABLE_TYPE -> typeFilters.add(new AssignableTypeFilter(filterClass));
|
||||
case CUSTOM -> {
|
||||
Assert.isAssignable(TypeFilter.class, filterClass,
|
||||
"@ComponentScan CUSTOM type filter requires a TypeFilter implementation");
|
||||
TypeFilter filter = ParserStrategyUtils.instantiateClass(filterClass, TypeFilter.class,
|
||||
environment, resourceLoader, registry);
|
||||
typeFilters.add(filter);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
|
||||
}
|
||||
default -> throw new IllegalArgumentException(
|
||||
"Filter type not supported with Class value: " + filterType);
|
||||
}
|
||||
}
|
||||
|
||||
for (String expression : filterAttributes.getStringArray("pattern")) {
|
||||
switch (filterType) {
|
||||
case ASPECTJ:
|
||||
typeFilters.add(new AspectJTypeFilter(expression, resourceLoader.getClassLoader()));
|
||||
break;
|
||||
case REGEX:
|
||||
typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Filter type not supported with String pattern: " + filterType);
|
||||
case ASPECTJ -> typeFilters.add(new AspectJTypeFilter(expression, resourceLoader.getClassLoader()));
|
||||
case REGEX -> typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
|
||||
default -> throw new IllegalArgumentException(
|
||||
"Filter type not supported with String pattern: " + filterType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -209,11 +209,11 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
|
||||
}
|
||||
|
||||
private DateTimeFormatter getFallbackFormatter(Type type) {
|
||||
switch (type) {
|
||||
case DATE: return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
|
||||
case TIME: return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
|
||||
default: return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
|
||||
}
|
||||
return switch (type) {
|
||||
case DATE -> DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
|
||||
case TIME -> DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
|
||||
case DATE_TIME -> DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.scheduling.annotation;
|
||||
|
||||
import org.springframework.context.annotation.AdviceMode;
|
||||
import org.springframework.context.annotation.AdviceModeImportSelector;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
/**
|
||||
* Selects which implementation of {@link AbstractAsyncConfiguration} should
|
||||
@@ -43,16 +43,12 @@ public class AsyncConfigurationSelector extends AdviceModeImportSelector<EnableA
|
||||
* respectively.
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
@NonNull
|
||||
public String[] selectImports(AdviceMode adviceMode) {
|
||||
switch (adviceMode) {
|
||||
case PROXY:
|
||||
return new String[] {ProxyAsyncConfiguration.class.getName()};
|
||||
case ASPECTJ:
|
||||
return new String[] {ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch (adviceMode) {
|
||||
case PROXY -> new String[]{ProxyAsyncConfiguration.class.getName()};
|
||||
case ASPECTJ -> new String[]{ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME};
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user