be-hase / protoc-gen-kotlin-ext

A protoc compiler plugin that generates useful extension code for Kotlin/JVM
MIT License
7 stars 0 forks source link

Compile error: Factory functions have the same name / namespace / package #13

Open westito opened 3 months ago

westito commented 3 months ago

The factory function generated under the same package name and the same name as the Builder so it is ambiguous for the compiler. In my case the compiler try to use the private constructor of the original java generated code.

There should be an option for package name prefix or factory function name postfix. For ex. DataClassDtoFactory(...)

Képernyőfotó 2024-06-11 - 11 21 56

By the way: This plugin saves my live! 😄 The original generator should be like this.

westito commented 3 months ago

Ah! I found the problem. I use option java_multiple_files = true; in proto file. When I turn it off, the problem goes. This is not really necessary for me so I leave it off, but you should mention this in docs, or handle by wrapping the factories in this case (in a *Factory outer class), so I could use DataFactory.DataClassDto for ex.

be-hase commented 2 months ago

@westito Thank you for all the reports, they are very helpful.

I don't quite understand the problem, so could you share a proto file that reproduces the issue? java_multiple_files = true; is working fine in my environment. https://github.com/be-hase/protoc-gen-kotlin-ext/blob/main/functional-test/src/main/proto/example/all_type.proto#L6