Skip to content

Commit 100ce96

Browse files
committed
Use TypeReference consistently in hints writer
Closes gh-28606
1 parent 405e592 commit 100ce96

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

spring-core/src/main/java/org/springframework/aot/nativex/ProxyHintsWriter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.springframework.aot.hint.JdkProxyHint;
2323
import org.springframework.aot.hint.ProxyHints;
24-
import org.springframework.aot.hint.TypeReference;
2524

2625
/**
2726
* Write {@link JdkProxyHint}s contained in a {@link ProxyHints} to the JSON
@@ -46,8 +45,7 @@ public void write(BasicJsonWriter writer, ProxyHints hints) {
4645
private Map<String, Object> toAttributes(JdkProxyHint hint) {
4746
Map<String, Object> attributes = new LinkedHashMap<>();
4847
handleCondition(attributes, hint);
49-
attributes.put("interfaces", hint.getProxiedInterfaces().stream()
50-
.map(TypeReference::getCanonicalName).toList());
48+
attributes.put("interfaces", hint.getProxiedInterfaces());
5149
return attributes;
5250
}
5351

spring-core/src/main/java/org/springframework/aot/nativex/ReflectionHintsWriter.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.springframework.aot.hint.MemberCategory;
3030
import org.springframework.aot.hint.ReflectionHints;
3131
import org.springframework.aot.hint.TypeHint;
32-
import org.springframework.aot.hint.TypeReference;
3332
import org.springframework.lang.Nullable;
3433

3534
/**
@@ -96,7 +95,7 @@ private void handleExecutables(Map<String, Object> attributes, List<ExecutableHi
9695
private Map<String, Object> toAttributes(ExecutableHint hint) {
9796
Map<String, Object> attributes = new LinkedHashMap<>();
9897
attributes.put("name", hint.getName());
99-
attributes.put("parameterTypes", hint.getParameterTypes().stream().map(TypeReference::getCanonicalName).toList());
98+
attributes.put("parameterTypes", hint.getParameterTypes());
10099
return attributes;
101100
}
102101

@@ -105,14 +104,21 @@ private void handleCategories(Map<String, Object> attributes, Set<MemberCategory
105104
switch (category) {
106105
case PUBLIC_FIELDS -> attributes.put("allPublicFields", true);
107106
case DECLARED_FIELDS -> attributes.put("allDeclaredFields", true);
108-
case INTROSPECT_PUBLIC_CONSTRUCTORS -> attributes.put("queryAllPublicConstructors", true);
109-
case INTROSPECT_DECLARED_CONSTRUCTORS -> attributes.put("queryAllDeclaredConstructors", true);
110-
case INVOKE_PUBLIC_CONSTRUCTORS -> attributes.put("allPublicConstructors", true);
111-
case INVOKE_DECLARED_CONSTRUCTORS -> attributes.put("allDeclaredConstructors", true);
112-
case INTROSPECT_PUBLIC_METHODS -> attributes.put("queryAllPublicMethods", true);
113-
case INTROSPECT_DECLARED_METHODS -> attributes.put("queryAllDeclaredMethods", true);
107+
case INTROSPECT_PUBLIC_CONSTRUCTORS ->
108+
attributes.put("queryAllPublicConstructors", true);
109+
case INTROSPECT_DECLARED_CONSTRUCTORS ->
110+
attributes.put("queryAllDeclaredConstructors", true);
111+
case INVOKE_PUBLIC_CONSTRUCTORS ->
112+
attributes.put("allPublicConstructors", true);
113+
case INVOKE_DECLARED_CONSTRUCTORS ->
114+
attributes.put("allDeclaredConstructors", true);
115+
case INTROSPECT_PUBLIC_METHODS ->
116+
attributes.put("queryAllPublicMethods", true);
117+
case INTROSPECT_DECLARED_METHODS ->
118+
attributes.put("queryAllDeclaredMethods", true);
114119
case INVOKE_PUBLIC_METHODS -> attributes.put("allPublicMethods", true);
115-
case INVOKE_DECLARED_METHODS -> attributes.put("allDeclaredMethods", true);
120+
case INVOKE_DECLARED_METHODS ->
121+
attributes.put("allDeclaredMethods", true);
116122
case PUBLIC_CLASSES -> attributes.put("allPublicClasses", true);
117123
case DECLARED_CLASSES -> attributes.put("allDeclaredClasses", true);
118124
}

spring-core/src/test/java/org/springframework/aot/nativex/ProxyHintsWriterTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ void shouldWriteMultipleEntries() throws JSONException {
6363
]""", hints);
6464
}
6565

66+
@Test
67+
void shouldWriteInnerClass() throws JSONException {
68+
ProxyHints hints = new ProxyHints();
69+
hints.registerJdkProxy(Inner.class);
70+
assertEquals("""
71+
[
72+
{ "interfaces": [ "org.springframework.aot.nativex.ProxyHintsWriterTests$Inner" ] }
73+
]""", hints);
74+
}
75+
6676
@Test
6777
void shouldWriteCondition() throws JSONException {
6878
ProxyHints hints = new ProxyHints();
@@ -81,4 +91,8 @@ private void assertEquals(String expectedString, ProxyHints hints) throws JSONEx
8191
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.NON_EXTENSIBLE);
8292
}
8393

94+
interface Inner {
95+
96+
}
97+
8498
}

spring-core/src/test/java/org/springframework/aot/nativex/ReflectionHintsWriterTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,27 @@ void methods() throws JSONException {
158158
""", hints);
159159
}
160160

161+
@Test
162+
void methodWithInnerClassParameter() throws JSONException {
163+
ReflectionHints hints = new ReflectionHints();
164+
hints.registerType(Integer.class, builder -> builder.withMethod("test", List.of(TypeReference.of(Inner.class)),
165+
b -> b.withMode(ExecutableMode.INVOKE)));
166+
167+
assertEquals("""
168+
[
169+
{
170+
"name": "java.lang.Integer",
171+
"methods": [
172+
{
173+
"name": "test",
174+
"parameterTypes": ["org.springframework.aot.nativex.ReflectionHintsWriterTests$Inner"]
175+
}
176+
]
177+
}
178+
]
179+
""", hints);
180+
}
181+
161182
@Test
162183
void methodAndQueriedMethods() throws JSONException {
163184
ReflectionHints hints = new ReflectionHints();
@@ -194,4 +215,9 @@ private void assertEquals(String expectedString, ReflectionHints hints) throws J
194215
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.NON_EXTENSIBLE);
195216
}
196217

218+
219+
static class Inner {
220+
221+
}
222+
197223
}

0 commit comments

Comments
 (0)