Class ProtoGenerator
java.lang.Object
io.github.anupambasak.gradle.plugins.pojo2proto.ProtoGenerator
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classGeneration settings.static final classA generated message wrapping a repeated field, used where protobuf does not allowrepeated: as a map value (Map<String, List<MyPojo>>) or as the element of another list (List<List<MyPojo>>). -
Constructor Summary
ConstructorsConstructorDescriptionProtoGenerator(boolean prefixEnumNames) ProtoGenerator(ProtoGenerator.Options options) -
Method Summary
Modifier and TypeMethodDescriptiongenerateEnum(com.github.javaparser.ast.body.EnumDeclaration enumDeclaration) generateEnums(List<com.github.javaparser.ast.body.EnumDeclaration> enumDeclarations) generateHeader(String packageName, Set<String> imports) generateMessage(com.github.javaparser.ast.CompilationUnit cu, List<com.github.javaparser.ast.body.EnumDeclaration> enumDeclarations) generateMessages(List<com.github.javaparser.ast.CompilationUnit> cus, List<com.github.javaparser.ast.body.EnumDeclaration> enumDeclarations) generateMessageWithNestedEnums(com.github.javaparser.ast.CompilationUnit cu, List<com.github.javaparser.ast.body.EnumDeclaration> nestedEnums, List<com.github.javaparser.ast.body.EnumDeclaration> allEnums) getImports(com.github.javaparser.ast.CompilationUnit cu, List<com.github.javaparser.ast.body.EnumDeclaration> enumDeclarations) The wrapper messages to generate as top-level messages (their own files in multi-file mode).protoFile(com.github.javaparser.ast.body.TypeDeclaration<?> type) Path of the .proto file declaring a top-level type, relative to the destination directory.protoName(com.github.javaparser.ast.body.TypeDeclaration<?> type) The proto name of a top-level type: its Java name (unlessregisterTypes(List)renamed it) followed by the configured name suffix.protoPackage(com.github.javaparser.ast.Node node) The proto package a type (or the types of a compilation unit) is generated in: withProtoGenerator.Options.usePojoPackages, its Java package followed byProtoGenerator.Options.javaPackageSuffix(com.x.dtos -> com.x.dtos.proto; none for classes in the default package), so that it equals the generatedjava_package.All proto names of the registered top-level types.registerTypes(List<com.github.javaparser.ast.CompilationUnit> cus) Registers every top-level type that will be generated and assigns its proto name.
-
Constructor Details
-
ProtoGenerator
public ProtoGenerator() -
ProtoGenerator
public ProtoGenerator(boolean prefixEnumNames) -
ProtoGenerator
-
-
Method Details
-
registerTypes
Registers every top-level type that will be generated and assigns its proto name.All generated types share one proto package, and generated file names and Java classes clash on case-insensitive file systems (Windows, macOS). So when two types have names that differ only in case (
FareDetailDTO/FareDetailDto) or are equal (Statusin two packages), each of them is renamed by prefixing its Java package's last segment in PascalCase (com.x.pricing.FareDetailDTO -> PricingFareDetailDTO). More segments are used if that is still ambiguous. Types without a clash keep their name. References, imports and file names follow the new names.- Returns:
- renamed types, fully qualified Java name to proto name
-
protoName
The proto name of a top-level type: its Java name (unlessregisterTypes(List)renamed it) followed by the configured name suffix. -
protoPackage
The proto package a type (or the types of a compilation unit) is generated in: withProtoGenerator.Options.usePojoPackages, its Java package followed byProtoGenerator.Options.javaPackageSuffix(com.x.dtos -> com.x.dtos.proto; none for classes in the default package), so that it equals the generatedjava_package. Otherwise theProtoGenerator.Options.sharedPackage. -
protoFile
Path of the .proto file declaring a top-level type, relative to the destination directory. It is also the path used to import it:Address.proto, orcom/x/dtos/proto/Address.protowith usePojoPackages (and javaPackageSuffix".proto"). -
registeredProtoNames
-
generateHeader
-
generateMessages
-
generateMessage
-
generateMessageWithNestedEnums
-
generateEnums
-
generateEnum
-
getImports
-
getTopLevelWrappers
The wrapper messages to generate as top-level messages (their own files in multi-file mode). -
generateWrapperMessage
-