Skip to content

Fix generated code when a service has the name of an imported type - #355

Open
zZHorizonZz wants to merge 1 commit into
eclipse-vertx:mainfrom
zZHorizonZz:fix-generated-service-name-clash
Open

Fix generated code when a service has the name of an imported type#355
zZHorizonZz wants to merge 1 commit into
eclipse-vertx:mainfrom
zZHorizonZz:fix-generated-service-name-clash

Conversation

@zZHorizonZz

@zZHorizonZz zZHorizonZz commented Sep 4, 2026

Copy link
Copy Markdown
Member

Motivation:

The generator gives the contract interface the name of the service. A service with the name Service thus gets a contract interface Service. The generated ServiceService class imports io.vertx.grpc.server.Service. In Java, an import hides a type of the same name in the same package. Thus the class implements the wrong Service, and the code does not compile. This occurs for each service that has the name of a type that the templates import. Future is another example.

Changes:

  • Each template declares its own type with prefixedServiceName.
  • Each template refers to the other generated types with the full names in contractFqn, clientFqn, serviceFqn and outerFqn. These fields did not contain full names before.
  • The fields grpcClientFqn, grpcServiceFqn and grpcIoFqn are removed. Each of them spelled only its own declaration.
  • The contract template has no imports. It declares the bare service name, thus an import of the same name is a compile error. The template gives the full names of the two types that it uses.
  • The other templates lose their unused imports. io.vertx.grpc.server.Service in the service template is the import of the report.

Closes #351

Motivation:

A .proto service named `Service` generates a contract interface `Service`
alongside a `ServiceService` class that imports io.vertx.grpc.server.Service.
The single type import shadows the same package contract, so the generated
class implements the wrong `Service` and does not compile. The same happens
for any service named after a type the templates import.

Changes:

The templates now declare their own type from prefixedServiceName and refer
to the other generated types with the package qualified names held by the
contractFqn/clientFqn/serviceFqn/outerFqn fields, which were not qualified
before despite their name. grpcClientFqn/grpcServiceFqn/grpcIoFqn only ever
spelled their own declaration and are gone.

Qualifying is not enough for the contract template since it declares the bare
service name: an import of the same simple name is a compile error there. It
has no imports anymore and qualifies the two types it uses. Dead imports are
removed from the other templates as well, io.vertx.grpc.server.Service in the
service template being the one reported.

Closes eclipse-vertx#351
@zZHorizonZz
zZHorizonZz force-pushed the fix-generated-service-name-clash branch from aa0d5be to f1d3107 Compare September 4, 2026 15:49
@zZHorizonZz
zZHorizonZz requested a review from vietj September 4, 2026 17:12
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 this pull request may close these issues.

[code-gen] Service called Service in .proto generates class with import problems

1 participant