Skip to content

Commit

Permalink
jooby-apt: generate kotlin source code ref #3449
Browse files Browse the repository at this point in the history
-  fix void routes on kotlin generator
  • Loading branch information
jknack committed Jun 18, 2024
1 parent 8b3062b commit 48d4930
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
42 changes: 21 additions & 21 deletions modules/jooby-apt/src/main/java/io/jooby/internal/apt/MvcRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public List<String> generateHandlerCall(boolean kt) {
}
var throwsException = !method.getThrownTypes().isEmpty();
var returnTypeString = type(kt, getReturnType().toString());
var ctx = "ctx";
if (kt) {
if (throwsException) {
buffer.add(statement("@Throws(Exception::class)"));
Expand Down Expand Up @@ -197,45 +196,46 @@ public List<String> generateHandlerCall(boolean kt) {
throwsException ? "throws Exception {" : "{"));
}
if (returnType.isVoid()) {
if (kt) {
buffer.add(
statement(
indent(2),
"ctx.setResponseCode(if (ctx.getRoute().getMethod().equals(",
string("DELETE"),
")) io.jooby.StatusCode.NO_CONTENT else io.jooby.StatusCode.OK)"));
} else {
buffer.add(
statement(
indent(2),
"ctx.setResponseCode(ctx.getRoute().getMethod().equals(",
string("DELETE"),
") ? io.jooby.StatusCode.NO_CONTENT: io.jooby.StatusCode.OK)",
semicolon(false)));
}
buffer.add(
statement(
indent(2),
"ctx.setResponseCode(",
ctx,
".getRoute().getMethod().equals(",
string("DELETE"),
") ?" + " io.jooby.StatusCode.NO_CONTENT: io.jooby.StatusCode.OK)",
semicolon(kt)));
buffer.add(
statement(
indent(2),
"this.factory.apply(",
ctx,
").",
"this.factory.apply(ctx).",
this.method.getSimpleName(),
paramList.toString(),
semicolon(kt)));
buffer.add(statement("return ", ctx, ".getResponseCode()", semicolon(kt)));
buffer.add(statement(indent(2), "return ctx.getResponseCode()", semicolon(kt)));
} else if (returnType.is("io.jooby.StatusCode")) {
buffer.add(
statement(
indent(2),
isSuspendFun() ? "val" : "var",
" statusCode = this.factory.apply(",
ctx,
").",
" statusCode = this.factory.apply(ctx).",
this.method.getSimpleName(),
paramList.toString(),
semicolon(kt)));
buffer.add(statement(indent(2), ctx, ".setResponseCode(statusCode)", semicolon(kt)));
buffer.add(statement(indent(2), "ctx.setResponseCode(statusCode)", semicolon(kt)));
buffer.add(statement(indent(2), "return statusCode", semicolon(kt)));
} else {
buffer.add(
statement(
indent(2),
"return this.factory.apply(",
ctx,
").",
"return this.factory.apply(ctx).",
this.method.getSimpleName(),
paramList.toString(),
semicolon(kt)));
Expand Down
6 changes: 1 addition & 5 deletions modules/jooby-apt/src/test/java/tests/CustomRouterName.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
*/
package tests;

import java.util.concurrent.CompletableFuture;

import io.jooby.annotation.GET;
import io.jooby.annotation.QueryParam;

public class CustomRouterName {

@GET("/hello")
public CompletableFuture<String> hello(@QueryParam String name) {
return null;
}
public void hello(@QueryParam String name) {}
}

0 comments on commit 48d4930

Please sign in to comment.