From aa1506df511f6632069c91b0be49cf5fb7ac3596 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Fri, 15 Sep 2023 14:19:59 +0200 Subject: [PATCH] add-enum-type-support --- .../main/java/io/vertx/codegen/EnumModel.java | 8 +++++++- .../vertx/test/codegen/converter/EnumType.java | 2 ++ .../protobuf/generator/ProtoFileGen.java | 18 ++++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/vertx-codegen-processor/src/main/java/io/vertx/codegen/EnumModel.java b/vertx-codegen-processor/src/main/java/io/vertx/codegen/EnumModel.java index f14657580..ac7bb1c04 100644 --- a/vertx-codegen-processor/src/main/java/io/vertx/codegen/EnumModel.java +++ b/vertx-codegen-processor/src/main/java/io/vertx/codegen/EnumModel.java @@ -58,11 +58,12 @@ public boolean process() { if (modelElt.getKind() != ElementKind.ENUM) { throw new GenException(modelElt, "@VertxGen can only be used with interfaces or enums" + modelElt.asType().toString()); } + processTypeAnnotations(); doc = docFactory.createDoc(modelElt); if (doc != null) { doc.getBlockTags().stream().filter(tag -> tag.getName().equals("deprecated")).findFirst().ifPresent(tag -> deprecatedDesc = new Text(Helper.normalizeWhitespaces(tag.getValue())).map(Token.tagMapper(elementUtils, typeUtils, modelElt)) - ); + ); } type = (EnumTypeInfo) typeMirrorFactory.create(modelElt.asType()); Helper.checkUnderModule(this, "@VertxGen"); @@ -101,6 +102,11 @@ private void processTypeAnnotations() { this.annotations = elementUtils.getAllAnnotationMirrors(modelElt).stream().map(annotationValueInfoFactory::processAnnotation).collect(Collectors.toList()); } + @Override + public List getAnnotations() { + return annotations; + } + /** * @return the type of this enum model */ diff --git a/vertx-codegen-protobuf/src/converters/java/io/vertx/test/codegen/converter/EnumType.java b/vertx-codegen-protobuf/src/converters/java/io/vertx/test/codegen/converter/EnumType.java index 6964446d9..5eb6863eb 100644 --- a/vertx-codegen-protobuf/src/converters/java/io/vertx/test/codegen/converter/EnumType.java +++ b/vertx-codegen-protobuf/src/converters/java/io/vertx/test/codegen/converter/EnumType.java @@ -1,8 +1,10 @@ package io.vertx.test.codegen.converter; import io.vertx.codegen.annotations.VertxGen; +import io.vertx.codegen.protobuf.annotations.ProtobufGen; @VertxGen +@ProtobufGen public enum EnumType { A, B, diff --git a/vertx-codegen-protobuf/src/main/java/io/vertx/codegen/protobuf/generator/ProtoFileGen.java b/vertx-codegen-protobuf/src/main/java/io/vertx/codegen/protobuf/generator/ProtoFileGen.java index 9ed21e0fb..899a01868 100644 --- a/vertx-codegen-protobuf/src/main/java/io/vertx/codegen/protobuf/generator/ProtoFileGen.java +++ b/vertx-codegen-protobuf/src/main/java/io/vertx/codegen/protobuf/generator/ProtoFileGen.java @@ -1,14 +1,11 @@ package io.vertx.codegen.protobuf.generator; -import io.vertx.codegen.DataObjectModel; -import io.vertx.codegen.EnumModel; -import io.vertx.codegen.EnumValueInfo; -import io.vertx.codegen.Generator; -import io.vertx.codegen.Model; -import io.vertx.codegen.PropertyInfo; +import io.vertx.codegen.*; import io.vertx.codegen.annotations.DataObject; import io.vertx.codegen.annotations.ModuleGen; +import io.vertx.codegen.annotations.VertxGen; import io.vertx.codegen.protobuf.annotations.JsonProtoEncoding; +import io.vertx.codegen.protobuf.annotations.ProtobufGen; import io.vertx.codegen.type.ClassKind; import java.io.PrintWriter; @@ -31,12 +28,17 @@ public ProtoFileGen() { @Override public Collection> annotations() { - return Arrays.asList(DataObject.class, ModuleGen.class); + return Arrays.asList(ProtobufGen.class); } @Override public String filename(Model model) { - return "resources/dataobjects.proto"; + System.out.println("INSPECTING " + model.getAnnotations()); + if ((model instanceof DataObjectModel || model instanceof EnumModel) && model.getAnnotations().stream().anyMatch(ann -> ann.getName().equals(ProtobufGen.class.getName()))) { + System.out.println("TRIGGERED"); + return "resources/dataobjects.proto"; + } + return null; } @Override