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

Codegen imports unused classes #492

Closed
jklingsporn opened this issue Feb 11, 2022 · 5 comments · Fixed by #521
Closed

Codegen imports unused classes #492

jklingsporn opened this issue Feb 11, 2022 · 5 comments · Fixed by #521

Comments

@jklingsporn
Copy link

While I was playing around with the generator, I figured out that for all generated classes the same mandatory imports are generated - no matter what:

public void generate(ClassModel model, PrintWriter writer) {
writer.println("import " + Map.class.getName() + ";");
writer.println("import " + Collectors.class.getName() + ";");
writer.println("import " + Multi.class.getName() + ";");
writer.println("import " + Uni.class.getName() + ";");
writer.println("import " + Consumer.class.getName() + ";");
writer.println("import " + Subscriber.class.getName() + ";");
writer.println("import " + Publisher.class.getName() + ";");
writer.println("import " + TypeArg.class.getName() + ";");
writer.println("import " + Fluent.class.getName() + ";");
writer.println("import " + CheckReturnValue.class.getName() + ";");

Unfortunately, I have an interface called Publisher which I annotated with @VertxGen and it clashes with org.reactivestreams.Publisher - even if it is not used in the generated class.

Any ideas of how to fix this (besides renaming my Interface)?

@cescoffier
Copy link
Contributor

We would need to use the full name for the Reactive Streams Publisher class and remove it from the import list.

@jponge jponge added this to the 2.19.0 milestone Feb 11, 2022
@jponge jponge modified the milestones: 2.19.0, 2.20.0 Mar 10, 2022
@cescoffier cescoffier removed this from the 2.20.0 milestone Mar 25, 2022
@zero88
Copy link

zero88 commented Apr 12, 2022

Another relating issue is:
import redundant classes/interfaces that are declared in origin class but are in package level access => complied failed

@cescoffier
Copy link
Contributor

Can you give an example of that?

@zero88
Copy link

zero88 commented Apr 12, 2022

Origin class JooqxBuilder. SQLExecutorBuilder is the internal interface (package level)

import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

import io.github.zero88.jooqx.datatype.DataTypeMapperRegistry;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Vertx;
import io.vertx.sqlclient.Pool;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.Tuple;

/**
 * Represents a builder that constructs {@link Jooqx}
 *
 * @since 2.0.0
 */
@VertxGen
public interface JooqxBuilder extends SQLExecutorBuilder {

Generated class

import java.util.Map;
import java.util.stream.Collectors;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import java.util.function.Consumer;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Publisher;
import io.smallrye.mutiny.vertx.TypeArg;
import io.vertx.codegen.annotations.Fluent;
import io.smallrye.common.annotation.CheckReturnValue;
import io.github.zero88.jooqx.SQLExecutorBuilder;
import io.github.zero88.jooqx.datatype.DataTypeMapperRegistry;
import org.jooq.DSLContext;
import io.github.zero88.jooqx.SQLErrorConverter;

/**
 * Represents a builder that construct {@link io.github.zero88.jooqx.mutiny.Jooqx}
 *
 * <p/>
 * NOTE: This class has been automatically generated from the {@link io.github.zero88.jooqx.JooqxBuilder original} non Mutiny-ified interface using Vert.x codegen.
 */

@io.smallrye.mutiny.vertx.MutinyGen(io.github.zero88.jooqx.JooqxBuilder.class)
public class JooqxBuilder {

This issue does not happen with vertx-rx3 and vertx-rx2

zero88 added a commit to zero88/jooqx that referenced this issue Apr 12, 2022
Need to change some package interface to public smallrye/smallrye-mutiny-vertx-bindings#492 (comment)
zero88 added a commit to zero88/jooqx that referenced this issue Apr 12, 2022
Need to change some package interface to public smallrye/smallrye-mutiny-vertx-bindings#492 (comment)
@cescoffier
Copy link
Contributor

I will fix the Publisher issue, but the visibility issue is more complex. I've to see what the other generators are doing, but yes, for now, it's a Mutiny generator limitation (do not forget that this generator is very different from the RX ones and does a lot more).

Can you open a new issue with to address the visibility issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants