Skip to content

Commit 37b110a

Browse files
committed
Polishing
1 parent 18a3b52 commit 37b110a

24 files changed

+144
-147
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ default void addFile(Kind kind, String path, InputStreamSource content) {
181181
*/
182182
void handleFile(Kind kind, String path, ThrowingConsumer<FileHandler> handler);
183183

184+
184185
private static String getClassNamePath(String className) {
185186
Assert.hasLength(className, "'className' must not be empty");
186187
validatePackage(ClassUtils.getPackageName(className), className);
@@ -232,13 +233,12 @@ enum Kind {
232233
* generated using CGLIB.
233234
*/
234235
CLASS
235-
236236
}
237237

238+
238239
/**
239240
* Provide access to a particular file and offer convenient methods to retrieve,
240241
* save, or override its content.
241-
*
242242
* @since 6.2
243243
*/
244244
abstract class FileHandler {
@@ -292,7 +292,6 @@ public void override(InputStreamSource content) {
292292
}
293293

294294
protected abstract void copy(InputStreamSource content, boolean override);
295-
296295
}
297296

298297
}

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@
4848
* packages can use this annotation as well.
4949
*
5050
* <p>To register reflection hints for the type itself, only member categories
51-
* should be specified:<pre><code class="java">
51+
* should be specified:
52+
* <pre><code class="java">
5253
* &#064;Component
5354
* &#064;RegisterReflection(memberCategories = INVOKE_PUBLIC_METHODS)
5455
* class MyComponent {
5556
* // ...
5657
* }</code></pre>
5758
*
5859
* <p>Reflection hints can be registered from a method. In this case, at least
59-
* one target class should be specified:<pre><code class="java">
60+
* one target class should be specified:
61+
* <pre><code class="java">
6062
* class MyProcessor {
6163
*
6264
* &#064;RegisterReflection(classes = CustomerEntry.class, memberCategories = PUBLIC_FIELDS)
@@ -81,11 +83,10 @@
8183

8284
/**
8385
* Classes for which reflection hints should be registered. Consider using
84-
* {@link #classNames()} for classes that are not public in the current
85-
* scope. If both {@code classes} and {@code classNames} are specified, they
86-
* are merged in a single set.
87-
* <p>
88-
* By default, the annotated type is the target of the registration. When
86+
* {@link #classNames()} for classes that are not public in the current scope.
87+
* If both {@code classes} and {@code classNames} are specified, they are
88+
* merged into a single set.
89+
* <p>By default, the annotated type is the target of the registration. When
8990
* placed on a method, at least one class must be specified.
9091
* @see #classNames()
9192
*/

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ public class RegisterReflectionReflectiveProcessor implements ReflectiveProcesso
4545

4646
private static final Log logger = LogFactory.getLog(RegisterReflectionReflectiveProcessor.class);
4747

48+
4849
@Override
4950
public final void registerReflectionHints(ReflectionHints hints, AnnotatedElement element) {
50-
RegisterReflection annotation = AnnotatedElementUtils.getMergedAnnotation(
51-
element, RegisterReflection.class);
52-
Assert.notNull(annotation, "Element must be annotated with @" + RegisterReflection.class.getSimpleName()
53-
+ ": " + element);
51+
RegisterReflection annotation = AnnotatedElementUtils.getMergedAnnotation(element, RegisterReflection.class);
52+
Assert.notNull(annotation, () -> "Element must be annotated with @RegisterReflection: " + element);
5453
ReflectionRegistration registration = parse(element, annotation);
5554
registerReflectionHints(hints, registration);
5655
}
@@ -65,12 +64,10 @@ protected ReflectionRegistration parse(AnnotatedElement element, RegisterReflect
6564
allClassNames.add(clazz);
6665
}
6766
else {
68-
throw new IllegalStateException("At least one class must be specified, "
69-
+ "could not detect target from '" + element + "'");
67+
throw new IllegalStateException("At least one class must be specified: " + element);
7068
}
7169
}
72-
return new ReflectionRegistration(allClassNames.toArray(new Class<?>[0]),
73-
annotation.memberCategories());
70+
return new ReflectionRegistration(allClassNames.toArray(new Class<?>[0]), annotation.memberCategories());
7471
}
7572

7673
protected void registerReflectionHints(ReflectionHints hints, ReflectionRegistration registration) {
@@ -89,11 +86,15 @@ private Class<?> loadClass(String className) {
8986
return ClassUtils.forName(className, getClass().getClassLoader());
9087
}
9188
catch (Exception ex) {
92-
logger.warn("Ignoring '" + className + "': " + ex.getMessage());
89+
if (logger.isWarnEnabled()) {
90+
logger.warn("Ignoring '" + className + "': " + ex);
91+
}
9392
return null;
9493
}
9594
}
9695

97-
protected record ReflectionRegistration(Class<?>[] classes, MemberCategory[] memberCategories) {}
96+
97+
protected record ReflectionRegistration(Class<?>[] classes, MemberCategory[] memberCategories) {
98+
}
9899

99100
}

spring-core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* used when converting property values from one type to another.
2727
*
2828
* @author Chris Beams
29+
* @author Stephane Nicoll
2930
* @since 3.1
3031
*/
3132
public interface ConfigurablePropertyResolver extends PropertyResolver {
@@ -75,9 +76,8 @@ public interface ConfigurablePropertyResolver extends PropertyResolver {
7576
void setValueSeparator(@Nullable String valueSeparator);
7677

7778
/**
78-
* Specify the escape character to use to ignore placeholder prefix
79-
* or value separator, or {@code null} if no escaping should take
80-
* place.
79+
* Specify the escape character to use to ignore placeholder prefix or
80+
* value separator, or {@code null} if no escaping should take place.
8181
* @since 6.2
8282
*/
8383
void setEscapeCharacter(@Nullable Character escapeCharacter);

spring-core/src/main/java/org/springframework/core/io/buffer/JettyDataBuffer.java

+11-16
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,15 @@ public final class JettyDataBuffer implements PooledDataBuffer {
6767
this.chunk = null;
6868
}
6969

70+
7071
@Override
7172
public boolean isAllocated() {
7273
return this.refCount.get() > 0;
7374
}
7475

7576
@Override
7677
public PooledDataBuffer retain() {
77-
int result = this.refCount.updateAndGet(c -> {
78-
if (c != 0) {
79-
return c + 1;
80-
}
81-
else {
82-
return 0;
83-
}
84-
});
78+
int result = this.refCount.updateAndGet(c -> (c != 0 ? c + 1 : 0));
8579
if (result != 0 && this.chunk != null) {
8680
this.chunk.retain();
8781
}
@@ -107,7 +101,7 @@ public boolean release() {
107101
return this.chunk.release();
108102
}
109103
else {
110-
return result == 0;
104+
return (result == 0);
111105
}
112106
}
113107

@@ -116,6 +110,7 @@ public DataBufferFactory factory() {
116110
return this.bufferFactory;
117111
}
118112

113+
119114
// delegation
120115

121116
@Override
@@ -305,15 +300,16 @@ public String toString(int index, int length, Charset charset) {
305300
return this.delegate.toString(index, length, charset);
306301
}
307302

303+
308304
@Override
309-
public int hashCode() {
310-
return this.delegate.hashCode();
305+
public boolean equals(Object other) {
306+
return (this == other || (other instanceof JettyDataBuffer otherBuffer &&
307+
this.delegate.equals(otherBuffer.delegate)));
311308
}
312309

313310
@Override
314-
public boolean equals(Object o) {
315-
return this == o || (o instanceof JettyDataBuffer other &&
316-
this.delegate.equals(other.delegate));
311+
public int hashCode() {
312+
return this.delegate.hashCode();
317313
}
318314

319315
@Override
@@ -322,13 +318,13 @@ public String toString() {
322318
readPosition(), writePosition(), capacity());
323319
}
324320

321+
325322
private static final class JettyByteBufferIterator implements ByteBufferIterator {
326323

327324
private final ByteBufferIterator delegate;
328325

329326
private final Content.Chunk chunk;
330327

331-
332328
public JettyByteBufferIterator(ByteBufferIterator delegate, Content.Chunk chunk) {
333329
Assert.notNull(delegate, "Delegate must not be null");
334330
Assert.notNull(chunk, "Chunk must not be null");
@@ -338,7 +334,6 @@ public JettyByteBufferIterator(ByteBufferIterator delegate, Content.Chunk chunk)
338334
this.chunk.retain();
339335
}
340336

341-
342337
@Override
343338
public void close() {
344339
this.delegate.close();

spring-core/src/main/java/org/springframework/core/io/buffer/JettyDataBufferFactory.java

+1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,5 @@ public JettyDataBuffer join(List<? extends DataBuffer> dataBuffers) {
105105
public boolean isDirect() {
106106
return this.delegate.isDirect();
107107
}
108+
108109
}

spring-core/src/main/java/org/springframework/lang/CheckReturnValue.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
/**
2424
* Specifies that the method return value must be used.
2525
*
26-
* <p>Inspired from {@code org.jetbrains.annotations.CheckReturnValue}, this variant
27-
* has been introduce in the {@code org.springframework.lang} package to avoid
26+
* <p>Inspired by {@code org.jetbrains.annotations.CheckReturnValue}, this variant
27+
* has been introduced in the {@code org.springframework.lang} package to avoid
2828
* requiring an extra dependency, while still following similar semantics.
2929
*
3030
* <p>This annotation should not be used if the return value of the method

spring-core/src/main/java/org/springframework/lang/Contract.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
* just describes how the code works and doesn't add any functionality by means of
2929
* code generation.
3030
*
31-
* <p>Inspired from {@code org.jetbrains.annotations.Contract}, this variant has
32-
* been introduce in the {@code org.springframework.lang} package to avoid requiring
33-
* an extra dependency, while still following the same semantics.
31+
* <p>Inspired by {@code org.jetbrains.annotations.Contract}, this variant has
32+
* been introduced in the {@code org.springframework.lang} package to avoid
33+
* requiring an extra dependency, while still following the same semantics.
3434
*
3535
* <p>Method contract has the following syntax:
3636
* <pre>{@code
@@ -85,4 +85,5 @@
8585
* Contains the contract clauses describing causal relations between call arguments and the returned value.
8686
*/
8787
String value() default "";
88+
8889
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1502,8 +1502,7 @@ private static Method findInterfaceMethodIfPossible(String methodName, Class<?>[
15021502
* (if there is one). For {@code toString()}, it may traverse as far as {@link Object}.
15031503
* @param method the method to be invoked, potentially from an implementation class
15041504
* @param targetClass the target class to invoke the method on, or {@code null} if unknown
1505-
* @return the corresponding publicly accessible method, or the original method if none
1506-
* found
1505+
* @return the corresponding publicly accessible method, or the original method if none found
15071506
* @since 6.2
15081507
* @see #getInterfaceMethodIfPossible(Method, Class)
15091508
* @see #getMostSpecificMethod(Method, Class)

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

-2
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,6 @@ public static <K, V> MultiValueMap<K, V> unmodifiableMultiValueMap(
515515
* Return a (partially unmodifiable) map that combines the provided two
516516
* maps. Invoking {@link Map#put(Object, Object)} or {@link Map#putAll(Map)}
517517
* on the returned map results in an {@link UnsupportedOperationException}.
518-
*
519518
* <p>In the case of a key collision, {@code first} takes precedence over
520519
* {@code second}. In other words, entries in {@code second} with a key
521520
* that is also mapped by {@code first} are effectively ignored.
@@ -535,7 +534,6 @@ public static <K, V> Map<K, V> compositeMap(Map<K,V> first, Map<K,V> second) {
535534
* {@link UnsupportedOperationException} {@code putFunction} is
536535
* {@code null}. The same applies to {@link Map#putAll(Map)} and
537536
* {@code putAllFunction}.
538-
*
539537
* <p>In the case of a key collision, {@code first} takes precedence over
540538
* {@code second}. In other words, entries in {@code second} with a key
541539
* that is also mapped by {@code first} are effectively ignored.

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

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CompositeCollection<E> implements Collection<E> {
4343
this.second = second;
4444
}
4545

46+
4647
@Override
4748
public int size() {
4849
return this.first.size() + this.second.size();
@@ -160,4 +161,5 @@ public void clear() {
160161
this.first.clear();
161162
this.second.clear();
162163
}
164+
163165
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,5 @@ public String toString() {
186186
sb.append(',').append(' ');
187187
}
188188
}
189+
189190
}

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.Set;
2020

21+
import org.springframework.lang.Nullable;
22+
2123
/**
2224
* Composite set that combines two other sets. This type is only exposed through
2325
* {@link CompositeMap#keySet()} and {@link CompositeMap#entrySet()}.
@@ -34,24 +36,19 @@ final class CompositeSet<E> extends CompositeCollection<E> implements Set<E> {
3436

3537

3638
@Override
37-
public boolean equals(Object obj) {
38-
if (obj == this) {
39+
public boolean equals(@Nullable Object other) {
40+
if (this == other) {
3941
return true;
4042
}
41-
else if (obj instanceof Set<?> set) {
42-
if (set.size() != size()) {
43-
return false;
44-
}
43+
if (other instanceof Set<?> otherSet && size() == otherSet.size()) {
4544
try {
46-
return containsAll(set);
45+
return containsAll(otherSet);
4746
}
4847
catch (ClassCastException | NullPointerException ignored) {
49-
return false;
48+
// fall through
5049
}
5150
}
52-
else {
53-
return false;
54-
}
51+
return false;
5552
}
5653

5754
@Override
@@ -64,4 +61,5 @@ public int hashCode() {
6461
}
6562
return hashCode;
6663
}
64+
6765
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/**
2525
* Collection that filters out values that do not match a predicate.
2626
* This type is used by {@link CompositeMap}.
27+
*
2728
* @author Arjen Poutsma
2829
* @since 6.2
2930
* @param <E> the type of elements maintained by this collection
@@ -38,11 +39,11 @@ class FilteredCollection<E> extends AbstractCollection<E> {
3839
public FilteredCollection(Collection<E> delegate, Predicate<E> filter) {
3940
Assert.notNull(delegate, "Delegate must not be null");
4041
Assert.notNull(filter, "Filter must not be null");
41-
4242
this.delegate = delegate;
4343
this.filter = filter;
4444
}
4545

46+
4647
@Override
4748
public int size() {
4849
int size = 0;
@@ -87,4 +88,5 @@ public boolean contains(Object o) {
8788
public void clear() {
8889
this.delegate.clear();
8990
}
91+
9092
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/**
2626
* Iterator that filters out values that do not match a predicate.
2727
* This type is used by {@link CompositeMap}.
28+
*
2829
* @author Arjen Poutsma
2930
* @since 6.2
3031
* @param <E> the type of elements returned by this iterator
@@ -44,7 +45,6 @@ final class FilteredIterator<E> implements Iterator<E> {
4445
public FilteredIterator(Iterator<E> delegate, Predicate<E> filter) {
4546
Assert.notNull(delegate, "Delegate must not be null");
4647
Assert.notNull(filter, "Filter must not be null");
47-
4848
this.delegate = delegate;
4949
this.filter = filter;
5050
}
@@ -83,4 +83,5 @@ private boolean setNext() {
8383
}
8484
return false;
8585
}
86+
8687
}

0 commit comments

Comments
 (0)