Skip to content

Commit 7cbc0a9

Browse files
committed
mvc: kotlin: generate controller don't support Nested generics return type #3488
- fix #3488 - fix generate kotlin nested generics
1 parent 86f5c8e commit 7cbc0a9

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

modules/jooby-apt/src/main/java/io/jooby/internal/apt/CodeBlock.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public static String type(boolean kt, CharSequence value) {
6161
// java.util.List => List
6262
from = "java.util.".length();
6363
}
64-
yield result.substring(from, end) + generics(true, result, arg);
64+
yield result.substring(from, end) + ktGenerics(result, arg);
6565
}
6666
};
6767
}
6868
return result;
6969
}
7070

71-
private static String generics(boolean kt, String type, int i) {
71+
private static String ktGenerics(String type, int i) {
7272
if (i == -1) {
7373
return "";
7474
}
@@ -78,7 +78,7 @@ private static String generics(boolean kt, String type, int i) {
7878
for (int j = i + 1; j < type.length(); j++) {
7979
char ch = type.charAt(j);
8080
if (ch == '>' || ch == ',') {
81-
buffer.append(type(kt, arg));
81+
buffer.append(type(true, arg));
8282
buffer.append(ch);
8383
if (ch == ',') {
8484
buffer.append(' ');
@@ -88,6 +88,9 @@ private static String generics(boolean kt, String type, int i) {
8888
arg.append(ch);
8989
}
9090
}
91+
if (!arg.isEmpty()) {
92+
buffer.append(type(true, arg));
93+
}
9194
return buffer.toString();
9295
}
9396
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package tests.i3488;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
import io.jooby.internal.apt.CodeBlock;
13+
14+
public class Issue3488 {
15+
16+
@Test
17+
public void shouldGenerateKtGenerics() {
18+
assertEquals(
19+
"pgk.Results<List<pgk.UserInfo>>",
20+
CodeBlock.type(true, "pgk.Results<java.util.List<pgk.UserInfo>>"));
21+
}
22+
}

0 commit comments

Comments
 (0)