Introduce Checkstyle rule for separator symbol location

This commit is contained in:
Sam Brannen
2025-03-19 15:35:35 +01:00
parent 18c3b637e4
commit 208d52d852
97 changed files with 378 additions and 403 deletions

View File

@@ -288,8 +288,8 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
}
}
catch (NoSuchBeanDefinitionException ex) {
throw new NoSuchBeanDefinitionException(CacheManager.class, "no CacheResolver specified - "
+ "register a CacheManager bean or remove the @EnableCaching annotation from your configuration.");
throw new NoSuchBeanDefinitionException(CacheManager.class, "no CacheResolver specified - " +
"register a CacheManager bean or remove the @EnableCaching annotation from your configuration.");
}
}
this.initialized = true;

View File

@@ -85,8 +85,8 @@ public class NameMatchCacheOperationSource implements CacheOperationSource, Seri
// Look for most specific name match.
String bestNameMatch = null;
for (String mappedName : this.nameMap.keySet()) {
if (isMatch(methodName, mappedName)
&& (bestNameMatch == null || bestNameMatch.length() <= mappedName.length())) {
if (isMatch(methodName, mappedName) &&
(bestNameMatch == null || bestNameMatch.length() <= mappedName.length())) {
ops = this.nameMap.get(mappedName);
bestNameMatch = mappedName;
}

View File

@@ -105,8 +105,8 @@ class ConfigurationClassParser {
(className.startsWith("java.lang.annotation.") || className.startsWith("org.springframework.stereotype."));
private static final Predicate<Condition> REGISTER_BEAN_CONDITION_FILTER = condition ->
(condition instanceof ConfigurationCondition configurationCondition
&& ConfigurationPhase.REGISTER_BEAN.equals(configurationCondition.getConfigurationPhase()));
(condition instanceof ConfigurationCondition configurationCondition &&
ConfigurationPhase.REGISTER_BEAN.equals(configurationCondition.getConfigurationPhase()));
private static final Comparator<DeferredImportSelectorHolder> DEFERRED_IMPORT_COMPARATOR =
(o1, o2) -> AnnotationAwareOrderComparator.INSTANCE.compare(o1.getImportSelector(), o2.getImportSelector());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -150,12 +150,12 @@ class ApplicationContextInitializationCodeGenerator implements BeanFactoryInitia
@Nullable
private CodeBlock apply(ClassName className) {
String name = className.canonicalName();
if (name.equals(DefaultListableBeanFactory.class.getName())
|| name.equals(ConfigurableListableBeanFactory.class.getName())) {
if (name.equals(DefaultListableBeanFactory.class.getName()) ||
name.equals(ConfigurableListableBeanFactory.class.getName())) {
return CodeBlock.of(BEAN_FACTORY_VARIABLE);
}
else if (name.equals(ConfigurableEnvironment.class.getName())
|| name.equals(Environment.class.getName())) {
else if (name.equals(ConfigurableEnvironment.class.getName()) ||
name.equals(Environment.class.getName())) {
return CodeBlock.of("$L.getEnvironment()", APPLICATION_CONTEXT_VARIABLE);
}
else if (name.equals(ResourceLoader.class.getName())) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -201,8 +201,8 @@ public class StandardBeanExpressionResolver implements BeanExpressionResolver {
try {
int maxLength = Integer.parseInt(value.trim());
Assert.isTrue(maxLength > 0, () -> "Value [" + maxLength + "] for system property ["
+ MAX_SPEL_EXPRESSION_LENGTH_PROPERTY_NAME + "] must be positive");
Assert.isTrue(maxLength > 0, () -> "Value [" + maxLength + "] for system property [" +
MAX_SPEL_EXPRESSION_LENGTH_PROPERTY_NAME + "] must be positive");
return maxLength;
}
catch (NumberFormatException ex) {

View File

@@ -493,8 +493,8 @@ final class PostProcessorRegistrationDelegate {
private void postProcessValue(List<MergedBeanDefinitionPostProcessor> postProcessors,
BeanDefinitionValueResolver valueResolver, @Nullable Object value) {
if (value instanceof BeanDefinitionHolder bdh
&& bdh.getBeanDefinition() instanceof AbstractBeanDefinition innerBd) {
if (value instanceof BeanDefinitionHolder bdh &&
bdh.getBeanDefinition() instanceof AbstractBeanDefinition innerBd) {
Class<?> innerBeanType = resolveBeanType(innerBd);
resolveInnerBeanDefinition(valueResolver, innerBd, (innerBeanName, innerBeanDefinition)

View File

@@ -143,8 +143,8 @@ public abstract class DurationFormatterUtils {
private static final Pattern ISO_8601_PATTERN = Pattern.compile("^[+-]?[pP].*$");
private static final Pattern SIMPLE_PATTERN = Pattern.compile("^([+-]?\\d+)([a-zA-Z]{0,2})$");
private static final Pattern COMPOSITE_PATTERN = Pattern.compile("^([+-]?)\\(?\\s?(\\d+d)?\\s?(\\d+h)?\\s?(\\d+m)?"
+ "\\s?(\\d+s)?\\s?(\\d+ms)?\\s?(\\d+us)?\\s?(\\d+ns)?\\)?$");
private static final Pattern COMPOSITE_PATTERN = Pattern.compile("^([+-]?)\\(?\\s?(\\d+d)?\\s?(\\d+h)?\\s?(\\d+m)?" +
"\\s?(\\d+s)?\\s?(\\d+ms)?\\s?(\\d+us)?\\s?(\\d+ns)?\\)?$");
private static Duration parseIso8601(String value) {
try {

View File

@@ -48,8 +48,8 @@ public class DefaultScheduledTaskObservationConvention implements ScheduledTaskO
@Override
public String getContextualName(ScheduledTaskObservationContext context) {
return "task " + StringUtils.uncapitalize(context.getTargetClass().getSimpleName())
+ "." + context.getMethod().getName();
return "task " + StringUtils.uncapitalize(context.getTargetClass().getSimpleName()) +
"." + context.getMethod().getName();
}
@Override

View File

@@ -106,8 +106,8 @@ class AspectAndAdvicePrecedenceTests {
private void checkAdvice(String whatJustHappened) {
//System.out.println("[" + adviceInvocationNumber + "] " + whatJustHappened + " ==> " + EXPECTED[adviceInvocationNumber]);
if (adviceInvocationNumber > (EXPECTED.length - 1)) {
throw new AssertionError("Too many advice invocations, expecting " + EXPECTED.length
+ " but had " + adviceInvocationNumber);
throw new AssertionError("Too many advice invocations, expecting " + EXPECTED.length +
" but had " + adviceInvocationNumber);
}
String expecting = EXPECTED[adviceInvocationNumber++];
if (!whatJustHappened.equals(expecting)) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -277,9 +277,9 @@ public class GroovyScriptFactoryTests {
@Test
void testScriptCompilationException() {
assertThatExceptionOfType(NestedRuntimeException.class).isThrownBy(() ->
new ClassPathXmlApplicationContext("org/springframework/scripting/groovy/groovyBrokenContext.xml"))
.matches(ex -> ex.contains(ScriptCompilationException.class));
assertThatExceptionOfType(NestedRuntimeException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext("org/springframework/scripting/groovy/groovyBrokenContext.xml"))
.matches(ex -> ex.contains(ScriptCompilationException.class));
}
@Test
@@ -288,11 +288,10 @@ public class GroovyScriptFactoryTests {
String badScript = "class Foo { public Foo(String foo) {}}";
given(script.getScriptAsString()).willReturn(badScript);
given(script.suggestedClassName()).willReturn("someName");
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX
+ badScript);
assertThatExceptionOfType(ScriptCompilationException.class).isThrownBy(() ->
factory.getScriptedObject(script))
.matches(ex -> ex.contains(NoSuchMethodException.class));
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript);
assertThatExceptionOfType(ScriptCompilationException.class)
.isThrownBy(() -> factory.getScriptedObject(script))
.matches(ex -> ex.contains(NoSuchMethodException.class));
}
@Test
@@ -327,27 +326,24 @@ public class GroovyScriptFactoryTests {
@Test
void testCtorWithNullScriptSourceLocator() {
assertThatIllegalArgumentException().isThrownBy(() ->
new GroovyScriptFactory(null));
assertThatIllegalArgumentException().isThrownBy(() -> new GroovyScriptFactory(null));
}
@Test
void testCtorWithEmptyScriptSourceLocator() {
assertThatIllegalArgumentException().isThrownBy(() ->
new GroovyScriptFactory(""));
assertThatIllegalArgumentException().isThrownBy(() -> new GroovyScriptFactory(""));
}
@Test
void testCtorWithWhitespacedScriptSourceLocator() {
assertThatIllegalArgumentException().isThrownBy(() ->
new GroovyScriptFactory("\n "));
assertThatIllegalArgumentException().isThrownBy(() -> new GroovyScriptFactory("\n "));
}
@Test
void testWithInlineScriptWithLeadingWhitespace() {
assertThatExceptionOfType(BeanCreationException.class).as("'inline:' prefix was preceded by whitespace").isThrownBy(() ->
new ClassPathXmlApplicationContext("lwspBadGroovyContext.xml", getClass()))
.matches(ex -> ex.contains(FileNotFoundException.class));
assertThatExceptionOfType(BeanCreationException.class).as("'inline:' prefix was preceded by whitespace")
.isThrownBy(() -> new ClassPathXmlApplicationContext("lwspBadGroovyContext.xml", getClass()))
.matches(ex -> ex.contains(FileNotFoundException.class));
}
@Test
@@ -364,8 +360,8 @@ public class GroovyScriptFactoryTests {
@Test
void testGetScriptedObjectDoesChokeOnNullScriptSourceBeingPassedIn() {
GroovyScriptFactory factory = new GroovyScriptFactory("a script source locator (doesn't matter here)");
assertThatNullPointerException().as("NullPointerException as per contract ('null' ScriptSource supplied)").isThrownBy(() ->
factory.getScriptedObject(null));
assertThatNullPointerException().as("NullPointerException as per contract ('null' ScriptSource supplied)")
.isThrownBy(() -> factory.getScriptedObject(null));
}
@Test