Skip to content

Commit 5fbd01f

Browse files
committed
Polish
1 parent d2d54c8 commit 5fbd01f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
import java.util.Map;
2424
import java.util.Objects;
2525
import java.util.Set;
26+
import java.util.StringJoiner;
2627
import java.util.function.Consumer;
2728
import java.util.stream.Collectors;
2829
import java.util.stream.Stream;
2930

31+
import org.springframework.lang.Nullable;
3032
import org.springframework.util.Assert;
3133

3234
/**
@@ -39,6 +41,7 @@ public final class TypeHint {
3941

4042
private final TypeReference type;
4143

44+
@Nullable
4245
private final TypeReference reachableType;
4346

4447
private final Set<FieldHint> fields;
@@ -83,6 +86,7 @@ public TypeReference getType() {
8386
* {@code null} if this hint should always been applied.
8487
* @return the reachable type, if any
8588
*/
89+
@Nullable
8690
public TypeReference getReachableType() {
8791
return this.reachableType;
8892
}
@@ -119,6 +123,12 @@ public Set<MemberCategory> getMemberCategories() {
119123
return this.memberCategories;
120124
}
121125

126+
@Override
127+
public String toString() {
128+
return new StringJoiner(", ", TypeHint.class.getSimpleName() + "[", "]")
129+
.add("type=" + this.type)
130+
.toString();
131+
}
122132

123133
/**
124134
* Builder for {@link TypeHint}.
@@ -127,6 +137,7 @@ public static class Builder {
127137

128138
private final TypeReference type;
129139

140+
@Nullable
130141
private TypeReference reachableType;
131142

132143
private final Map<String, FieldHint.Builder> fields = new HashMap<>();

spring-core/src/test/java/org/springframework/aot/hint/TypeHintTests.java

Lines changed: 7 additions & 1 deletion
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.
@@ -137,4 +137,10 @@ void createWithMemberCategory() {
137137
assertThat(hint.getMemberCategories()).containsOnly(MemberCategory.DECLARED_FIELDS);
138138
}
139139

140+
@Test
141+
void typeHintHasAppropriateToString() {
142+
TypeHint hint = TypeHint.of(TypeReference.of(String.class)).build();
143+
assertThat(hint).hasToString("TypeHint[type=java.lang.String]");
144+
}
145+
140146
}

0 commit comments

Comments
 (0)