Skip to content

Commit 7c07c43

Browse files
committed
Polishing
1 parent 6791ea9 commit 7c07c43

File tree

16 files changed

+120
-124
lines changed

16 files changed

+120
-124
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorDelegates.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,15 +47,15 @@
4747
abstract class BeanDefinitionPropertyValueCodeGeneratorDelegates {
4848

4949
/**
50-
* Return the {@link Delegate} implementations for common bean definition
51-
* property value types. These are:
50+
* A list of {@link Delegate} implementations for the following common bean
51+
* definition property value types.
5252
* <ul>
53-
* <li>{@link ManagedList},</li>
54-
* <li>{@link ManagedSet},</li>
55-
* <li>{@link ManagedMap},</li>
56-
* <li>{@link LinkedHashMap},</li>
57-
* <li>{@link BeanReference},</li>
58-
* <li>{@link TypedStringValue}.</li>
53+
* <li>{@link ManagedList}</li>
54+
* <li>{@link ManagedSet}</li>
55+
* <li>{@link ManagedMap}</li>
56+
* <li>{@link LinkedHashMap}</li>
57+
* <li>{@link BeanReference}</li>
58+
* <li>{@link TypedStringValue}</li>
5959
* </ul>
6060
* When combined with {@linkplain ValueCodeGeneratorDelegates#INSTANCES the
6161
* delegates for common value types}, this should be added first as they have

spring-beans/src/main/java/org/springframework/beans/factory/aot/CodeWarnings.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.util.Collections;
2121
import java.util.LinkedHashSet;
2222
import java.util.Set;
23-
import java.util.StringJoiner;
2423
import java.util.stream.Stream;
2524

2625
import org.springframework.javapoet.AnnotationSpec;
@@ -118,9 +117,7 @@ private CodeBlock generateValueCode() {
118117

119118
@Override
120119
public String toString() {
121-
return new StringJoiner(", ", CodeWarnings.class.getSimpleName(), "")
122-
.add(this.warnings.toString())
123-
.toString();
120+
return CodeWarnings.class.getSimpleName() + this.warnings;
124121
}
125122

126123
}

spring-beans/src/test/java/org/springframework/beans/factory/aot/CodeWarningsTests.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,14 +43,10 @@ class CodeWarningsTests {
4343
private static final TestCompiler TEST_COMPILER = TestCompiler.forSystem()
4444
.withCompilerOptions("-Xlint:all", "-Werror");
4545

46-
private final CodeWarnings codeWarnings;
46+
private final CodeWarnings codeWarnings = new CodeWarnings();
4747

48-
private final TestGenerationContext generationContext;
48+
private final TestGenerationContext generationContext = new TestGenerationContext();
4949

50-
CodeWarningsTests() {
51-
this.codeWarnings = new CodeWarnings();
52-
this.generationContext = new TestGenerationContext();
53-
}
5450

5551
@Test
5652
void registerNoWarningDoesNotIncludeAnnotation() {
@@ -67,8 +63,7 @@ void registerWarningSuppressesIt() {
6763
compile(method -> {
6864
this.codeWarnings.suppress(method);
6965
method.addStatement("$T bean = new $T()", DeprecatedBean.class, DeprecatedBean.class);
70-
}, compiled -> assertThat(compiled.getSourceFile())
71-
.contains("@SuppressWarnings(\"deprecation\")"));
66+
}, compiled -> assertThat(compiled.getSourceFile()).contains("@SuppressWarnings(\"deprecation\")"));
7267
}
7368

7469
@Test
@@ -80,26 +75,25 @@ void registerSeveralWarningsSuppressesThem() {
8075
this.codeWarnings.suppress(method);
8176
method.addStatement("$T bean = new $T()", DeprecatedBean.class, DeprecatedBean.class);
8277
method.addStatement("$T another = new $T()", DeprecatedForRemovalBean.class, DeprecatedForRemovalBean.class);
83-
}, compiled -> assertThat(compiled.getSourceFile())
84-
.contains("@SuppressWarnings({ \"deprecation\", \"removal\" })"));
78+
}, compiled -> assertThat(compiled.getSourceFile()).contains("@SuppressWarnings({ \"deprecation\", \"removal\" })"));
8579
}
8680

8781
@Test
8882
@SuppressWarnings("deprecation")
8983
void detectDeprecationOnAnnotatedElementWithDeprecated() {
9084
this.codeWarnings.detectDeprecation(DeprecatedBean.class);
91-
assertThat(this.codeWarnings.getWarnings()).containsExactly("deprecation");
85+
assertThat(this.codeWarnings.getWarnings()).containsOnly("deprecation");
9286
}
9387

9488
@Test
9589
@SuppressWarnings("removal")
9690
void detectDeprecationOnAnnotatedElementWithDeprecatedForRemoval() {
9791
this.codeWarnings.detectDeprecation(DeprecatedForRemovalBean.class);
98-
assertThat(this.codeWarnings.getWarnings()).containsExactly("removal");
92+
assertThat(this.codeWarnings.getWarnings()).containsOnly("removal");
9993
}
10094

10195
@Test
102-
void toStringIncludeWarnings() {
96+
void toStringIncludesWarnings() {
10397
this.codeWarnings.register("deprecation");
10498
this.codeWarnings.register("rawtypes");
10599
assertThat(this.codeWarnings).hasToString("CodeWarnings[deprecation, rawtypes]");

spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-context/src/main/java/org/springframework/scheduling/support/CronExpression.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ private CronExpression(CronField seconds, CronField minutes, CronField hours,
142142
*
143143
* <p>Example expressions:
144144
* <ul>
145-
* <li>{@code "0 0 * * * *"} = the top of every hour of every day.</li>
146-
* <li><code>"*&#47;10 * * * * *"</code> = every ten seconds.</li>
147-
* <li>{@code "0 0 8-10 * * *"} = 8, 9 and 10 o'clock of every day.</li>
148-
* <li>{@code "0 0 6,19 * * *"} = 6:00 AM and 7:00 PM every day.</li>
149-
* <li>{@code "0 0/30 8-10 * * *"} = 8:00, 8:30, 9:00, 9:30, 10:00 and 10:30 every day.</li>
145+
* <li>{@code "0 0 * * * *"} = the top of every hour of every day</li>
146+
* <li><code>"*&#47;10 * * * * *"</code> = every ten seconds</li>
147+
* <li>{@code "0 0 8-10 * * *"} = 8, 9 and 10 o'clock of every day</li>
148+
* <li>{@code "0 0 6,19 * * *"} = 6:00 AM and 7:00 PM every day</li>
149+
* <li>{@code "0 0/30 8-10 * * *"} = 8:00, 8:30, 9:00, 9:30, 10:00 and 10:30 every day</li>
150150
* <li>{@code "0 0 9-17 * * MON-FRI"} = on the hour nine-to-five weekdays</li>
151151
* <li>{@code "0 0 0 25 12 ?"} = every Christmas Day at midnight</li>
152152
* <li>{@code "0 0 0 L * *"} = last day of the month at midnight</li>
@@ -159,13 +159,13 @@ private CronExpression(CronField seconds, CronField minutes, CronField hours,
159159
* <li>{@code "0 0 0 ? * MON#1"} = the first Monday in the month at midnight</li>
160160
* </ul>
161161
*
162-
* <p>The following macros are also supported:
162+
* <p>The following macros are also supported.
163163
* <ul>
164-
* <li>{@code "@yearly"} (or {@code "@annually"}) to run un once a year, i.e. {@code "0 0 0 1 1 *"},</li>
165-
* <li>{@code "@monthly"} to run once a month, i.e. {@code "0 0 0 1 * *"},</li>
166-
* <li>{@code "@weekly"} to run once a week, i.e. {@code "0 0 0 * * 0"},</li>
167-
* <li>{@code "@daily"} (or {@code "@midnight"}) to run once a day, i.e. {@code "0 0 0 * * *"},</li>
168-
* <li>{@code "@hourly"} to run once an hour, i.e. {@code "0 0 * * * *"}.</li>
164+
* <li>{@code "@yearly"} (or {@code "@annually"}) to run un once a year, i.e. {@code "0 0 0 1 1 *"}</li>
165+
* <li>{@code "@monthly"} to run once a month, i.e. {@code "0 0 0 1 * *"}</li>
166+
* <li>{@code "@weekly"} to run once a week, i.e. {@code "0 0 0 * * 0"}</li>
167+
* <li>{@code "@daily"} (or {@code "@midnight"}) to run once a day, i.e. {@code "0 0 0 * * *"}</li>
168+
* <li>{@code "@hourly"} to run once an hour, i.e. {@code "0 0 * * * *"}</li>
169169
* </ul>
170170
* @param expression the expression string to parse
171171
* @return the parsed {@code CronExpression} object

spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGeneratorDelegates.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,19 +47,19 @@
4747
public abstract class ValueCodeGeneratorDelegates {
4848

4949
/**
50-
* Return the {@link Delegate} implementations for common value types.
51-
* These are:
50+
* A list of {@link Delegate} implementations for the following common value
51+
* types.
5252
* <ul>
53-
* <li>Primitive types,</li>
54-
* <li>String,</li>
55-
* <li>Charset,</li>
56-
* <li>Enum,</li>
57-
* <li>Class,</li>
58-
* <li>{@link ResolvableType},</li>
59-
* <li>Array,</li>
60-
* <li>List via {@code List.of},</li>
61-
* <li>Set via {@code Set.of} and support of {@link LinkedHashSet},</li>
62-
* <li>Map via {@code Map.of} or {@code Map.ofEntries}.</li>
53+
* <li>Primitive types</li>
54+
* <li>String</li>
55+
* <li>Charset</li>
56+
* <li>Enum</li>
57+
* <li>Class</li>
58+
* <li>{@link ResolvableType}</li>
59+
* <li>Array</li>
60+
* <li>List via {@code List.of}</li>
61+
* <li>Set via {@code Set.of} and support for {@link LinkedHashSet}</li>
62+
* <li>Map via {@code Map.of} or {@code Map.ofEntries}</li>
6363
* </ul>
6464
* Those implementations do not require the {@link ValueCodeGenerator} to be
6565
* {@linkplain ValueCodeGenerator#scoped(GeneratedMethods) scoped}.

spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.Map;
2424
import java.util.Objects;
2525
import java.util.Set;
26-
import java.util.StringJoiner;
2726
import java.util.function.Consumer;
2827
import java.util.stream.Collectors;
2928
import java.util.stream.Stream;
@@ -123,9 +122,7 @@ public Set<MemberCategory> getMemberCategories() {
123122

124123
@Override
125124
public String toString() {
126-
return new StringJoiner(", ", TypeHint.class.getSimpleName() + "[", "]")
127-
.add("type=" + this.type)
128-
.toString();
125+
return TypeHint.class.getSimpleName() + "[type=" + this.type + "]";
129126
}
130127

131128
/**

spring-core/src/main/java/org/springframework/core/ResolvableType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,8 @@ public static ResolvableType forClassWithGenerics(Class<?> clazz, ResolvableType
11691169
Assert.notNull(clazz, "Class must not be null");
11701170
Assert.notNull(generics, "Generics array must not be null");
11711171
TypeVariable<?>[] variables = clazz.getTypeParameters();
1172-
Assert.isTrue(variables.length == generics.length, () -> "Mismatched number of generics specified for " + clazz.toGenericString());
1172+
Assert.isTrue(variables.length == generics.length,
1173+
() -> "Mismatched number of generics specified for " + clazz.toGenericString());
11731174

11741175
Type[] arguments = new Type[generics.length];
11751176
for (int i = 0; i < generics.length; i++) {

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,10 +1019,10 @@ public static String getDescriptiveType(@Nullable Object value) {
10191019
}
10201020
Class<?> clazz = value.getClass();
10211021
if (Proxy.isProxyClass(clazz)) {
1022-
String prefix = clazz.getName() + " implementing ";
1022+
String prefix = clazz.getTypeName() + " implementing ";
10231023
StringJoiner result = new StringJoiner(",", prefix, "");
10241024
for (Class<?> ifc : clazz.getInterfaces()) {
1025-
result.add(ifc.getName());
1025+
result.add(ifc.getTypeName());
10261026
}
10271027
return result.toString();
10281028
}

spring-core/src/main/java/org/springframework/util/PlaceholderParser.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
* a given key can involve the resolution of nested placeholders. Default values
4747
* can also have placeholders.
4848
*
49-
* <p>For situations where the syntax of a valid placeholder match a String that
49+
* <p>For situations where the syntax of a valid placeholder matches a String that
5050
* must be rendered as is, the placeholder can be escaped using an {@code escape}
5151
* character. For instance {@code \${name}} resolves as {@code ${name}}.
5252
*
5353
* <p>The prefix, suffix, separator, and escape characters are configurable. Only
54-
* the prefix and suffix are mandatory and the support of default values or
55-
* escaping are conditional on providing a non-null value for them.
54+
* the prefix and suffix are mandatory, and the support for default values or
55+
* escaping is conditional on providing non-null values for them.
5656
*
5757
* <p>This parser makes sure to resolves placeholders as lazily as possible.
5858
*
@@ -64,7 +64,11 @@ final class PlaceholderParser {
6464
private static final Log logger = LogFactory.getLog(PlaceholderParser.class);
6565

6666
private static final Map<String, String> wellKnownSimplePrefixes = Map.of(
67-
"}", "{", "]", "[", ")", "(");
67+
"}", "{",
68+
"]", "[",
69+
")", "("
70+
);
71+
6872

6973
private final String prefix;
7074

@@ -80,17 +84,17 @@ final class PlaceholderParser {
8084
@Nullable
8185
private final Character escape;
8286

87+
8388
/**
8489
* Create an instance using the specified input for the parser.
85-
*
8690
* @param prefix the prefix that denotes the start of a placeholder
8791
* @param suffix the suffix that denotes the end of a placeholder
8892
* @param ignoreUnresolvablePlaceholders whether unresolvable placeholders
8993
* should be ignored ({@code true}) or cause an exception ({@code false})
9094
* @param separator the separating character between the placeholder
9195
* variable and the associated default value, if any
9296
* @param escape the character to use at the beginning of a placeholder
93-
* to escape it and render it as is
97+
* prefix or separator to escape it and render it as is
9498
*/
9599
PlaceholderParser(String prefix, String suffix, boolean ignoreUnresolvablePlaceholders,
96100
@Nullable String separator, @Nullable Character escape) {
@@ -109,7 +113,7 @@ final class PlaceholderParser {
109113
}
110114

111115
/**
112-
* Replaces all placeholders of format {@code ${name}} with the value returned
116+
* Replace all placeholders of format {@code ${name}} with the value returned
113117
* from the supplied {@link PlaceholderResolver}.
114118
* @param value the value containing the placeholders to be replaced
115119
* @param placeholderResolver the {@code PlaceholderResolver} to use for replacement
@@ -138,8 +142,7 @@ private List<Part> parse(String value, boolean inPlaceholder) {
138142
LinkedList<Part> parts = new LinkedList<>();
139143
int startIndex = nextStartPrefix(value, 0);
140144
if (startIndex == -1) {
141-
Part part = inPlaceholder ? createSimplePlaceholderPart(value)
142-
: new TextPart(value);
145+
Part part = (inPlaceholder ? createSimplePlaceholderPart(value) : new TextPart(value));
143146
parts.add(part);
144147
return parts;
145148
}
@@ -168,13 +171,13 @@ else if (isEscaped(value, startIndex)) { // Not a valid index, accumulate and sk
168171
}
169172
// Add rest of text if necessary
170173
addText(value, position, value.length(), parts);
171-
return inPlaceholder ? List.of(createNestedPlaceholderPart(value, parts)) : parts;
174+
return (inPlaceholder ? List.of(createNestedPlaceholderPart(value, parts)) : parts);
172175
}
173176

174177
private SimplePlaceholderPart createSimplePlaceholderPart(String text) {
175178
String[] keyAndDefault = splitKeyAndDefault(text);
176-
return (keyAndDefault != null) ? new SimplePlaceholderPart(text, keyAndDefault[0], keyAndDefault[1])
177-
: new SimplePlaceholderPart(text, text, null);
179+
return ((keyAndDefault != null) ? new SimplePlaceholderPart(text, keyAndDefault[0], keyAndDefault[1]) :
180+
new SimplePlaceholderPart(text, text, null));
178181
}
179182

180183
private NestedPlaceholderPart createNestedPlaceholderPart(String text, List<Part> parts) {
@@ -291,7 +294,7 @@ private boolean isEscaped(String value, int index) {
291294
}
292295

293296
/**
294-
* Provide the necessary to handle and resolve underlying placeholders.
297+
* Provide the necessary context to handle and resolve underlying placeholders.
295298
*/
296299
static class PartResolutionContext implements PlaceholderResolver {
297300

@@ -308,6 +311,7 @@ static class PartResolutionContext implements PlaceholderResolver {
308311
@Nullable
309312
private Set<String> visitedPlaceholders;
310313

314+
311315
PartResolutionContext(PlaceholderResolver resolver, String prefix, String suffix,
312316
boolean ignoreUnresolvablePlaceholders, Function<String, List<Part>> parser) {
313317
this.prefix = prefix;

0 commit comments

Comments
 (0)