Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jooby apt: generate source code #3444

Merged
merged 17 commits into from
Jun 7, 2024
Merged

jooby apt: generate source code #3444

merged 17 commits into from
Jun 7, 2024

Conversation

jknack
Copy link
Member

@jknack jknack commented Jun 6, 2024

  • Implement new source code generator annotation processor
  • Remove and delete ASM binary generator
  • Default controller names looks like: my.pkg.Controller_
  • There is a new extension MvcExtension
  • There is a new mvc method: mvc(new Controller_());
  • For now I'm keeping legacy mvc method support based on Service Locator pattern, but then are now deprecated and must be migrated to new mvc method.
  • TODO: update openAPI plugin to support the new mvc(new Controller()_) look up

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 added 14 commits June 2, 2024 16:46
- Add new annotation processor
- Simplify annotation processor a lot
- More clean and readable version
- Name generated router like `Controller` + `_`
- Use JavaPoet to generate code
- For now it generates binary and source code
- Sync code generator to new annotation processor ref #2968
- bind existing `mvc` to new annotation processor
- deprecate existing `mvc` methods
- ref #2968
 - fix tests add missing edge cases
- move classes to proper package: `apt`
- fix kotlin usage of generated code
- Classify annotation (minor refactor)
- add option for customize the generated file and class name: `jooby.routerPrefix` and `jooby.routerSuffix`
- add some basic javadoc
- add reserved method names while generated code
@jknack
Copy link
Member Author

jknack commented Jun 6, 2024

cc @agentgt @SentryMan

- fix null value options: routerPrefix/routerSuffix
@jknack jknack added this to the 3.2.0 milestone Jun 7, 2024
- more cleanup and minor esthetic fixes
@jknack jknack merged commit 7d28303 into 3.x Jun 7, 2024
5 checks passed
@jknack jknack deleted the 2968 branch June 10, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant