From 15294c3716d8abada82fb0db1902c28c09f9c802 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Tue, 3 Oct 2023 19:12:52 +0200 Subject: [PATCH] [KOGITO-9861] Fixing compilation issues with nested and arrays --- ...lassAnnotatedWorkflowHandlerGenerator.java | 24 +++++++++++++++---- .../WorkflowOpenApiHandlerGenerator.java | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/ClassAnnotatedWorkflowHandlerGenerator.java b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/ClassAnnotatedWorkflowHandlerGenerator.java index 32fce36910e..95d117f8859 100644 --- a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/ClassAnnotatedWorkflowHandlerGenerator.java +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/ClassAnnotatedWorkflowHandlerGenerator.java @@ -30,6 +30,7 @@ import org.kie.kogito.codegen.api.context.KogitoBuildContext; import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.type.ClassOrInterfaceType; import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; import static com.github.javaparser.StaticJavaParser.parseType; @@ -46,16 +47,31 @@ public Collection generateHandlerClasses(KogitoBui protected abstract Stream generateHandler(KogitoBuildContext context, AnnotationInstance a); protected final com.github.javaparser.ast.type.Type fromClass(Type param) { + return fromClass(param, true); + } + + protected final com.github.javaparser.ast.type.Type fromClass(Type param, boolean includeGeneric) { switch (param.kind()) { case CLASS: - return parseClassOrInterfaceType(param.asClassType().name().toString()); + return parseClassOrInterfaceType(fromDotName(param.asClassType().name())); case PRIMITIVE: - return parseType(param.asPrimitiveType().name().toString()); + return parseType(fromDotName(param.asPrimitiveType().name())); case PARAMETERIZED_TYPE: - return parseClassOrInterfaceType(param.asParameterizedType().name().toString()) - .setTypeArguments(NodeList.nodeList(param.asParameterizedType().arguments().stream().map(this::fromClass).collect(Collectors.toList()))); + ClassOrInterfaceType result = parseClassOrInterfaceType(fromDotName(param.asParameterizedType().name())); + if (includeGeneric) { + result.setTypeArguments(NodeList.nodeList(param.asParameterizedType().arguments().stream().map(this::fromClass).collect(Collectors.toList()))); + } + return result; default: throw new UnsupportedOperationException("Kind " + param.kind() + " is not supported"); } } + + private String fromDotName(DotName dotName) { + String result = dotName.toString(); + if (dotName.isInner()) { + result = result.replace('$', '.'); + } + return result; + } } diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/openapi/WorkflowOpenApiHandlerGenerator.java b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/openapi/WorkflowOpenApiHandlerGenerator.java index 36c97d8d732..f502b34a834 100644 --- a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/openapi/WorkflowOpenApiHandlerGenerator.java +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/openapi/WorkflowOpenApiHandlerGenerator.java @@ -109,7 +109,7 @@ private WorkflowHandlerGeneratedFile generateHandler(KogitoBuildContext context, if (annotation != null) { methodCallExpr.addArgument(new CastExpr(fromClass(param), new MethodCallExpr(parameters, "remove").addArgument(new StringLiteralExpr(annotation.value().asString())))); } else { - methodCallExpr.addArgument(new MethodCallExpr("buildBody").addArgument(parameters).addArgument(new ClassExpr(fromClass(param)))); + methodCallExpr.addArgument(new MethodCallExpr("buildBody").addArgument(parameters).addArgument(new ClassExpr(fromClass(param, false)))); } } clazz.addMethod("getRestClass", Keyword.PROTECTED).setType(parseClassOrInterfaceType(Class.class.getCanonicalName()).setTypeArguments(classNameType))