Skip to content

Commit

Permalink
[KOGITO-9861] Fixing compilation issues with nested and arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Oct 5, 2023
1 parent 454122e commit 15294c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,16 +47,31 @@ public Collection<WorkflowHandlerGeneratedFile> generateHandlerClasses(KogitoBui
protected abstract Stream<WorkflowHandlerGeneratedFile> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 15294c3

Please sign in to comment.