jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.7k stars 199 forks source link

jooby apt: generate source code #3444

Closed jknack closed 4 months ago

jknack commented 4 months ago

Example:

package tests;

import io.jooby.Context;
import io.jooby.Extension;
import io.jooby.Jooby;
import io.jooby.MvcExtension;
import io.jooby.MvcFactory;
import io.jooby.annotation.Generated;
import jakarta.inject.Provider;
import java.lang.Class;
import java.lang.Exception;
import java.lang.String;
import java.util.function.Function;

@Generated("tests.CustomRouterName")
public class CustomRouterName_ implements MvcExtension, MvcFactory {
  protected final Function<Context, CustomRouterName> provider;

  public CustomRouterName_(CustomRouterName instance) {
    this.provider = ctx -> instance;
  }

  public CustomRouterName_(Provider<CustomRouterName> supplier) {
    this.provider = ctx -> supplier.get();
  }

  public CustomRouterName_(Class<CustomRouterName> type) {
    this.provider = ctx -> ctx.require(CustomRouterName.class);
  }

  public CustomRouterName_() {
    this(new CustomRouterName());
  }

  public void install(Jooby app) throws Exception {
    /** See {@link CustomRouterName#hello(java.lang.String) */
    app.get("/hello", this::hello)
       .setReturnType(java.lang.String.class)
       .setMvcMethod(CustomRouterName.class.getMethod("hello", java.lang.String.class));

  }

  public String hello(Context ctx) throws Exception {
    return this.provider.apply(ctx).hello(ctx.query("name").valueOrNull());
  }

  public boolean supports(Class type) {
    return type == CustomRouterName.class;
  }

  public Extension create(Provider provider) {
    return new CustomRouterName_(provider);
  }
}
jknack commented 4 months ago

cc @agentgt @SentryMan