diff --git a/spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java b/spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java index 8c62db8ff6..ff7a195654 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java @@ -23,10 +23,12 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.StringJoiner; import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -39,6 +41,7 @@ public final class TypeHint { private final TypeReference type; + @Nullable private final TypeReference reachableType; private final Set fields; @@ -83,6 +86,7 @@ public final class TypeHint { * {@code null} if this hint should always been applied. * @return the reachable type, if any */ + @Nullable public TypeReference getReachableType() { return this.reachableType; } @@ -119,6 +123,12 @@ public final class TypeHint { return this.memberCategories; } + @Override + public String toString() { + return new StringJoiner(", ", TypeHint.class.getSimpleName() + "[", "]") + .add("type=" + this.type) + .toString(); + } /** * Builder for {@link TypeHint}. @@ -127,6 +137,7 @@ public final class TypeHint { private final TypeReference type; + @Nullable private TypeReference reachableType; private final Map fields = new HashMap<>(); diff --git a/spring-core/src/test/java/org/springframework/aot/hint/TypeHintTests.java b/spring-core/src/test/java/org/springframework/aot/hint/TypeHintTests.java index 89b1ad0582..d6922c26bd 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/TypeHintTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/TypeHintTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -137,4 +137,10 @@ class TypeHintTests { assertThat(hint.getMemberCategories()).containsOnly(MemberCategory.DECLARED_FIELDS); } + @Test + void typeHintHasAppropriateToString() { + TypeHint hint = TypeHint.of(TypeReference.of(String.class)).build(); + assertThat(hint).hasToString("TypeHint[type=java.lang.String]"); + } + }