Skip to content

Commit

Permalink
add-enum-type-support
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Sep 15, 2023
1 parent 41c872c commit aa1506d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -101,6 +102,11 @@ private void processTypeAnnotations() {
this.annotations = elementUtils.getAllAnnotationMirrors(modelElt).stream().map(annotationValueInfoFactory::processAnnotation).collect(Collectors.toList());
}

@Override
public List<AnnotationValueInfo> getAnnotations() {
return annotations;
}

/**
* @return the type of this enum model
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -31,12 +28,17 @@ public ProtoFileGen() {

@Override
public Collection<Class<? extends Annotation>> 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
Expand Down

0 comments on commit aa1506d

Please sign in to comment.