in quarkus/extensions/kogito-quarkus-workflow-extension-common/kogito-quarkus-workflow-common-deployment/src/main/java/org/kie/kogito/quarkus/workflow/deployment/JandexProtoGenerator.java [110:183]
protected ProtoMessage messageFromClass(Proto proto, Set<String> alreadyGenerated, ClassInfo clazz, String messageComment, String fieldComment) throws Exception {
if (!shouldGenerateProto(clazz)) {
LOGGER.info("Skipping generating jandex proto for class {}", clazz);
return null;
}
LOGGER.debug("Generating reflection proto for class {}", clazz);
String name = extractName(clazz).get();
ProtoMessage message = new ProtoMessage(name, clazz.name().prefix().toString());
for (FieldInfo pd : extractAllFields(clazz)) {
// ignore static and/or transient fields
if (Modifier.isStatic(pd.flags()) || Modifier.isTransient(pd.flags())) {
continue;
}
// By default, only index id field from Model generated class
String completeFieldComment =
"id".equals(pd.name()) && clazz.interfaceTypes().stream().anyMatch(t -> t.name().equals(modelClazz)) ? fieldComment.replace("Index.NO", "Index.YES") : fieldComment;
AnnotationInstance variableInfo = pd.annotation(variableInfoAnnotation);
if (variableInfo != null) {
completeFieldComment = fieldComment + "\n @VariableInfo(tags=\"" + variableInfo.value("tags").asString()
+ "\")";
}
String fieldTypeString = pd.type().name().toString();
DotName fieldType = pd.type().name();
String protoType;
if (isArray(pd)) {
fieldTypeString = ARRAY;
fieldType = pd.type().asArrayType().component().name();
protoType = protoType(fieldType.toString());
} else if (isCollection(pd)) {
fieldTypeString = COLLECTION;
List<Type> typeParameters = pd.type().kind() == Kind.CLASS ? emptyList() : pd.type().asParameterizedType().arguments();
if (typeParameters.isEmpty()) {
throw new IllegalArgumentException("Field " + pd.name() + " of class " + clazz.name().toString()
+ " uses collection without type information");
}
fieldType = typeParameters.get(0).name();
protoType = protoType(fieldType.toString());
} else {
protoType = protoType(fieldTypeString);
}
if (protoType == null) {
ClassInfo classInfo = index.getClassByName(fieldType);
if (classInfo == null) {
throw new IllegalStateException("Cannot find class info in jandex index for " + fieldType);
}
// recursive call to visit the type
Optional<String> optionalProtoType = internalGenerate(proto, alreadyGenerated, messageComment, fieldComment, classInfo);
if (!optionalProtoType.isPresent()) {
return message;
}
protoType = optionalProtoType.get();
}
ProtoField protoField = message.addField(computeCardinalityModifier(fieldTypeString), protoType, pd.name());
protoField.setComment(completeFieldComment);
if (KOGITO_SERIALIZABLE.equals(protoType)) {
protoField.setOption(format("[%s = \"%s\"]", KOGITO_JAVA_CLASS_OPTION, fieldTypeString.equals(ARRAY) ? pd.type().toString() : pd.type().name().toString()));
}
}
message.setComment(messageComment);
proto.addMessage(message);
return message;
}