Skip to content

Commit e41d865

Browse files
committed
Polishing
1 parent d68bb4e commit e41d865

File tree

2 files changed

+64
-64
lines changed

2 files changed

+64
-64
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -48,11 +48,11 @@
4848
* {@link #getGeneric(int...) generic parameters} along with the ability to ultimately
4949
* {@link #resolve() resolve} to a {@link java.lang.Class}.
5050
*
51-
* <p>{@code ResolvableTypes} may be obtained from {@link #forField(Field) fields},
52-
* {@link #forMethodParameter(Method, int) method parameters},
53-
* {@link #forMethodReturnType(Method) method returns} or
54-
* {@link #forClass(Class) classes}. Most methods on this class will themselves return
55-
* {@link ResolvableType ResolvableTypes}, allowing easy navigation. For example:
51+
* <p>A {@code ResolvableType} may be obtained from a {@linkplain #forField(Field) field},
52+
* a {@linkplain #forMethodParameter(Method, int) method parameter},
53+
* a {@linkplain #forMethodReturnType(Method) method return type}, or a
54+
* {@linkplain #forClass(Class) class}. Most methods on this class will themselves return
55+
* a {@code ResolvableType}, allowing for easy navigation. For example:
5656
* <pre class="code">
5757
* private HashMap&lt;Integer, List&lt;String&gt;&gt; myMap;
5858
*
@@ -182,7 +182,7 @@ private ResolvableType(Type type, @Nullable TypeProvider typeProvider,
182182

183183
/**
184184
* Private constructor used to create a new {@link ResolvableType} on a {@link Class} basis.
185-
* Avoids all {@code instanceof} checks in order to create a straight {@link Class} wrapper.
185+
* <p>Avoids all {@code instanceof} checks in order to create a straight {@link Class} wrapper.
186186
* @since 4.2
187187
*/
188188
private ResolvableType(@Nullable Class<?> clazz) {
@@ -406,7 +406,7 @@ public ResolvableType getComponentType() {
406406

407407
/**
408408
* Convenience method to return this type as a resolvable {@link Collection} type.
409-
* Returns {@link #NONE} if this type does not implement or extend
409+
* <p>Returns {@link #NONE} if this type does not implement or extend
410410
* {@link Collection}.
411411
* @see #as(Class)
412412
* @see #asMap()
@@ -417,7 +417,7 @@ public ResolvableType asCollection() {
417417

418418
/**
419419
* Convenience method to return this type as a resolvable {@link Map} type.
420-
* Returns {@link #NONE} if this type does not implement or extend
420+
* <p>Returns {@link #NONE} if this type does not implement or extend
421421
* {@link Map}.
422422
* @see #as(Class)
423423
* @see #asCollection()
@@ -458,7 +458,7 @@ public ResolvableType as(Class<?> type) {
458458

459459
/**
460460
* Return a {@link ResolvableType} representing the direct supertype of this type.
461-
* If no supertype is available this method returns {@link #NONE}.
461+
* <p>If no supertype is available this method returns {@link #NONE}.
462462
* <p>Note: The resulting {@link ResolvableType} instance may not be {@link Serializable}.
463463
* @see #getInterfaces()
464464
*/
@@ -608,7 +608,7 @@ private boolean isWildcardWithoutBounds() {
608608

609609
/**
610610
* Return a {@link ResolvableType} for the specified nesting level.
611-
* See {@link #getNested(int, Map)} for details.
611+
* <p>See {@link #getNested(int, Map)} for details.
612612
* @param nestingLevel the nesting level
613613
* @return the {@link ResolvableType} type, or {@code #NONE}
614614
*/
@@ -999,7 +999,7 @@ public String toString() {
999999
/**
10001000
* Return a {@link ResolvableType} for the specified {@link Class},
10011001
* using the full generic type information for assignability checks.
1002-
* For example: {@code ResolvableType.forClass(MyArrayList.class)}.
1002+
* <p>For example: {@code ResolvableType.forClass(MyArrayList.class)}.
10031003
* @param clazz the class to introspect ({@code null} is semantically
10041004
* equivalent to {@code Object.class} for typical use cases here)
10051005
* @return a {@link ResolvableType} for the specified class
@@ -1014,7 +1014,7 @@ public static ResolvableType forClass(@Nullable Class<?> clazz) {
10141014
* Return a {@link ResolvableType} for the specified {@link Class},
10151015
* doing assignability checks against the raw class only (analogous to
10161016
* {@link Class#isAssignableFrom}, which this serves as a wrapper for.
1017-
* For example: {@code ResolvableType.forRawClass(List.class)}.
1017+
* <p>For example: {@code ResolvableType.forRawClass(List.class)}.
10181018
* @param clazz the class to introspect ({@code null} is semantically
10191019
* equivalent to {@code Object.class} for typical use cases here)
10201020
* @return a {@link ResolvableType} for the specified class
@@ -1043,7 +1043,7 @@ public boolean isAssignableFrom(ResolvableType other) {
10431043
/**
10441044
* Return a {@link ResolvableType} for the specified base type
10451045
* (interface or base class) with a given implementation class.
1046-
* For example: {@code ResolvableType.forClass(List.class, MyArrayList.class)}.
1046+
* <p>For example: {@code ResolvableType.forClass(List.class, MyArrayList.class)}.
10471047
* @param baseType the base type (must not be {@code null})
10481048
* @param implementationClass the implementation class
10491049
* @return a {@link ResolvableType} for the specified base type backed by the
@@ -1238,7 +1238,7 @@ public static ResolvableType forMethodReturnType(Method method) {
12381238

12391239
/**
12401240
* Return a {@link ResolvableType} for the specified {@link Method} return type.
1241-
* Use this variant when the class that declares the method includes generic
1241+
* <p>Use this variant when the class that declares the method includes generic
12421242
* parameter variables that are satisfied by the implementation class.
12431243
* @param method the source for the method return type
12441244
* @param implementationClass the implementation class

spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -83,19 +83,19 @@ void noneReturnValues() throws Exception {
8383
assertThat(none.asMap()).isEqualTo(ResolvableType.NONE);
8484
assertThat(none.getComponentType()).isEqualTo(ResolvableType.NONE);
8585
assertThat(none.getGeneric(0)).isEqualTo(ResolvableType.NONE);
86-
assertThat(none.getGenerics().length).isEqualTo(0);
87-
assertThat(none.getInterfaces().length).isEqualTo(0);
86+
assertThat(none.getGenerics()).isEmpty();
87+
assertThat(none.getInterfaces()).isEmpty();
8888
assertThat(none.getSuperType()).isEqualTo(ResolvableType.NONE);
8989
assertThat(none.getType()).isEqualTo(ResolvableType.EmptyType.INSTANCE);
90-
assertThat(none.hasGenerics()).isEqualTo(false);
91-
assertThat(none.isArray()).isEqualTo(false);
90+
assertThat(none.hasGenerics()).isFalse();
91+
assertThat(none.isArray()).isFalse();
9292
assertThat(none.resolve()).isNull();
9393
assertThat(none.resolve(String.class)).isEqualTo(String.class);
9494
assertThat(none.resolveGeneric(0)).isNull();
95-
assertThat(none.resolveGenerics().length).isEqualTo(0);
95+
assertThat(none.resolveGenerics()).isEmpty();
9696
assertThat(none.toString()).isEqualTo("?");
97-
assertThat(none.hasUnresolvableGenerics()).isEqualTo(false);
98-
assertThat(none.isAssignableFrom(ResolvableType.forClass(Object.class))).isEqualTo(false);
97+
assertThat(none.hasUnresolvableGenerics()).isFalse();
98+
assertThat(none.isAssignableFrom(ResolvableType.forClass(Object.class))).isFalse();
9999
}
100100

101101
@Test
@@ -148,9 +148,9 @@ void forRawClassAssignableFromTypeVariable() throws Exception {
148148

149149
@Test
150150
void forInstanceMustNotBeNull() throws Exception {
151-
assertThatIllegalArgumentException().isThrownBy(() ->
152-
ResolvableType.forInstance(null))
153-
.withMessageContaining("Instance must not be null");
151+
assertThatIllegalArgumentException()
152+
.isThrownBy(() -> ResolvableType.forInstance(null))
153+
.withMessage("Instance must not be null");
154154
}
155155

156156
@Test
@@ -201,9 +201,9 @@ void forPrivateField() throws Exception {
201201

202202
@Test
203203
void forFieldMustNotBeNull() throws Exception {
204-
assertThatIllegalArgumentException().isThrownBy(() ->
205-
ResolvableType.forField(null))
206-
.withMessageContaining("Field must not be null");
204+
assertThatIllegalArgumentException()
205+
.isThrownBy(() -> ResolvableType.forField(null))
206+
.withMessage("Field must not be null");
207207
}
208208

209209
@Test
@@ -215,9 +215,9 @@ void forConstructorParameter() throws Exception {
215215

216216
@Test
217217
void forConstructorParameterMustNotBeNull() throws Exception {
218-
assertThatIllegalArgumentException().isThrownBy(() ->
219-
ResolvableType.forConstructorParameter(null, 0))
220-
.withMessageContaining("Constructor must not be null");
218+
assertThatIllegalArgumentException()
219+
.isThrownBy(() -> ResolvableType.forConstructorParameter(null, 0))
220+
.withMessage("Constructor must not be null");
221221
}
222222

223223
@Test
@@ -229,9 +229,9 @@ void forMethodParameterByIndex() throws Exception {
229229

230230
@Test
231231
void forMethodParameterByIndexMustNotBeNull() throws Exception {
232-
assertThatIllegalArgumentException().isThrownBy(() ->
233-
ResolvableType.forMethodParameter(null, 0))
234-
.withMessageContaining("Method must not be null");
232+
assertThatIllegalArgumentException()
233+
.isThrownBy(() -> ResolvableType.forMethodParameter(null, 0))
234+
.withMessage("Method must not be null");
235235
}
236236

237237
@Test
@@ -269,9 +269,9 @@ void forMethodParameterWithNestingAndLevels() throws Exception {
269269

270270
@Test
271271
void forMethodParameterMustNotBeNull() throws Exception {
272-
assertThatIllegalArgumentException().isThrownBy(() ->
273-
ResolvableType.forMethodParameter(null))
274-
.withMessageContaining("MethodParameter must not be null");
272+
assertThatIllegalArgumentException()
273+
.isThrownBy(() -> ResolvableType.forMethodParameter(null))
274+
.withMessage("MethodParameter must not be null");
275275
}
276276

277277
@Test // SPR-16210
@@ -296,9 +296,9 @@ void forMethodReturn() throws Exception {
296296

297297
@Test
298298
void forMethodReturnMustNotBeNull() throws Exception {
299-
assertThatIllegalArgumentException().isThrownBy(() ->
300-
ResolvableType.forMethodReturnType(null))
301-
.withMessageContaining("Method must not be null");
299+
assertThatIllegalArgumentException()
300+
.isThrownBy(() -> ResolvableType.forMethodReturnType(null))
301+
.withMessage("Method must not be null");
302302
}
303303

304304
@Test
@@ -317,7 +317,7 @@ void parameterizedType() throws Exception {
317317
void arrayClassType() throws Exception {
318318
ResolvableType type = ResolvableType.forField(Fields.class.getField("arrayClassType"));
319319
assertThat(type.getType()).isInstanceOf(Class.class);
320-
assertThat(((Class) type.getType()).isArray()).isEqualTo(true);
320+
assertThat(((Class) type.getType()).isArray()).isTrue();
321321
}
322322

323323
@Test
@@ -343,23 +343,23 @@ void typeVariableType() throws Exception {
343343
void getComponentTypeForClassArray() throws Exception {
344344
Field field = Fields.class.getField("arrayClassType");
345345
ResolvableType type = ResolvableType.forField(field);
346-
assertThat(type.isArray()).isEqualTo(true);
346+
assertThat(type.isArray()).isTrue();
347347
assertThat(type.getComponentType().getType())
348348
.isEqualTo(((Class) field.getGenericType()).getComponentType());
349349
}
350350

351351
@Test
352352
void getComponentTypeForGenericArrayType() throws Exception {
353353
ResolvableType type = ResolvableType.forField(Fields.class.getField("genericArrayType"));
354-
assertThat(type.isArray()).isEqualTo(true);
354+
assertThat(type.isArray()).isTrue();
355355
assertThat(type.getComponentType().getType()).isEqualTo(
356356
((GenericArrayType) type.getType()).getGenericComponentType());
357357
}
358358

359359
@Test
360360
void getComponentTypeForVariableThatResolvesToGenericArray() throws Exception {
361361
ResolvableType type = ResolvableType.forClass(ListOfGenericArray.class).asCollection().getGeneric();
362-
assertThat(type.isArray()).isEqualTo(true);
362+
assertThat(type.isArray()).isTrue();
363363
assertThat(type.getType()).isInstanceOf(TypeVariable.class);
364364
assertThat(type.getComponentType().getType().toString()).isEqualTo(
365365
"java.util.List<java.lang.String>");
@@ -368,7 +368,7 @@ void getComponentTypeForVariableThatResolvesToGenericArray() throws Exception {
368368
@Test
369369
void getComponentTypeForNonArray() throws Exception {
370370
ResolvableType type = ResolvableType.forClass(String.class);
371-
assertThat(type.isArray()).isEqualTo(false);
371+
assertThat(type.isArray()).isFalse();
372372
assertThat(type.getComponentType()).isEqualTo(ResolvableType.NONE);
373373
}
374374

@@ -438,7 +438,7 @@ void getSuperType() throws Exception {
438438
@Test
439439
void getInterfaces() throws Exception {
440440
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
441-
assertThat(type.getInterfaces().length).isEqualTo(0);
441+
assertThat(type.getInterfaces()).isEmpty();
442442
SortedSet<String> interfaces = new TreeSet<>();
443443
for (ResolvableType interfaceType : type.getSuperType().getInterfaces()) {
444444
interfaces.add(interfaceType.toString());
@@ -529,8 +529,8 @@ void getGenericOutOfBounds() throws Exception {
529529
@Test
530530
void hasGenerics() throws Exception {
531531
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
532-
assertThat(type.hasGenerics()).isEqualTo(false);
533-
assertThat(type.asCollection().hasGenerics()).isEqualTo(true);
532+
assertThat(type.hasGenerics()).isFalse();
533+
assertThat(type.asCollection().hasGenerics()).isTrue();
534534
}
535535

536536
@Test
@@ -553,7 +553,7 @@ void getGenericsFromClass() throws Exception {
553553
void noGetGenerics() throws Exception {
554554
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
555555
ResolvableType[] generics = type.getGenerics();
556-
assertThat(generics.length).isEqualTo(0);
556+
assertThat(generics).isEmpty();
557557
}
558558

559559
@Test
@@ -602,31 +602,31 @@ void resolveGenericArrayFromGeneric() throws Exception {
602602
ResolvableType type = ResolvableType.forField(Fields.class.getField("stringArrayList"));
603603
ResolvableType generic = type.asCollection().getGeneric();
604604
assertThat(generic.getType().toString()).isEqualTo("E");
605-
assertThat(generic.isArray()).isEqualTo(true);
605+
assertThat(generic.isArray()).isTrue();
606606
assertThat(generic.resolve()).isEqualTo(String[].class);
607607
}
608608

609609
@Test
610610
void resolveVariableGenericArray() throws Exception {
611611
ResolvableType type = ResolvableType.forField(Fields.class.getField("variableTypeGenericArray"), TypedFields.class);
612612
assertThat(type.getType().toString()).isEqualTo("T[]");
613-
assertThat(type.isArray()).isEqualTo(true);
613+
assertThat(type.isArray()).isTrue();
614614
assertThat(type.resolve()).isEqualTo(String[].class);
615615
}
616616

617617
@Test
618618
void resolveVariableGenericArrayUnknown() throws Exception {
619619
ResolvableType type = ResolvableType.forField(Fields.class.getField("variableTypeGenericArray"));
620620
assertThat(type.getType().toString()).isEqualTo("T[]");
621-
assertThat(type.isArray()).isEqualTo(true);
621+
assertThat(type.isArray()).isTrue();
622622
assertThat(type.resolve()).isNull();
623623
}
624624

625625
@Test
626626
void resolveVariableGenericArrayUnknownWithFallback() throws Exception {
627627
ResolvableType type = ResolvableType.forField(Fields.class.getField("variableTypeGenericArray"));
628628
assertThat(type.getType().toString()).isEqualTo("T[]");
629-
assertThat(type.isArray()).isEqualTo(true);
629+
assertThat(type.isArray()).isTrue();
630630
assertThat(type.toClass()).isEqualTo(Object.class);
631631
}
632632

@@ -965,16 +965,16 @@ void resolveFromClassWithGenerics() throws Exception {
965965

966966
@Test
967967
void isAssignableFromMustNotBeNull() throws Exception {
968-
assertThatIllegalArgumentException().isThrownBy(() ->
969-
ResolvableType.forClass(Object.class).isAssignableFrom((ResolvableType) null))
970-
.withMessageContaining("Type must not be null");
968+
assertThatIllegalArgumentException()
969+
.isThrownBy(() -> ResolvableType.forClass(Object.class).isAssignableFrom((ResolvableType) null))
970+
.withMessage("ResolvableType must not be null");
971971
}
972972

973973
@Test
974974
void isAssignableFromForNone() throws Exception {
975975
ResolvableType objectType = ResolvableType.forClass(Object.class);
976-
assertThat(objectType.isAssignableFrom(ResolvableType.NONE)).isEqualTo(false);
977-
assertThat(ResolvableType.NONE.isAssignableFrom(objectType)).isEqualTo(false);
976+
assertThat(objectType.isAssignableFrom(ResolvableType.NONE)).isFalse();
977+
assertThat(ResolvableType.NONE.isAssignableFrom(objectType)).isFalse();
978978
}
979979

980980
@Test
@@ -1262,19 +1262,19 @@ void narrow() throws Exception {
12621262
@Test
12631263
void hasUnresolvableGenerics() throws Exception {
12641264
ResolvableType type = ResolvableType.forField(Fields.class.getField("stringList"));
1265-
assertThat(type.hasUnresolvableGenerics()).isEqualTo(false);
1265+
assertThat(type.hasUnresolvableGenerics()).isFalse();
12661266
}
12671267

12681268
@Test
12691269
void hasUnresolvableGenericsBasedOnOwnGenerics() throws Exception {
12701270
ResolvableType type = ResolvableType.forClass(List.class);
1271-
assertThat(type.hasUnresolvableGenerics()).isEqualTo(true);
1271+
assertThat(type.hasUnresolvableGenerics()).isTrue();
12721272
}
12731273

12741274
@Test
12751275
void hasUnresolvableGenericsWhenSelfNotResolvable() throws Exception {
12761276
ResolvableType type = ResolvableType.forClass(List.class).getGeneric();
1277-
assertThat(type.hasUnresolvableGenerics()).isEqualTo(false);
1277+
assertThat(type.hasUnresolvableGenerics()).isFalse();
12781278
}
12791279

12801280
@Test
@@ -1283,7 +1283,7 @@ void hasUnresolvableGenericsWhenImplementesRawInterface() throws Exception {
12831283
for (ResolvableType generic : type.getGenerics()) {
12841284
assertThat(generic.resolve()).isNotNull();
12851285
}
1286-
assertThat(type.hasUnresolvableGenerics()).isEqualTo(true);
1286+
assertThat(type.hasUnresolvableGenerics()).isTrue();
12871287
}
12881288

12891289
@Test
@@ -1292,7 +1292,7 @@ void hasUnresolvableGenericsWhenExtends() throws Exception {
12921292
for (ResolvableType generic : type.getGenerics()) {
12931293
assertThat(generic.resolve()).isNotNull();
12941294
}
1295-
assertThat(type.hasUnresolvableGenerics()).isEqualTo(true);
1295+
assertThat(type.hasUnresolvableGenerics()).isTrue();
12961296
}
12971297

12981298
@Test

0 commit comments

Comments
 (0)