martinweiler commented on code in PR #7204:
URL: https://github.com/apache/incubator-kie/pull/7204#discussion_r4317404131
##########
kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessResourceGenerator.java:
##########
@@ -335,50 +342,120 @@ protected void
generateSignalsEndpoints(TemplatedGenerator.Builder templateBuild
setterMethod.setName(setterMethod.getNameAsString().replace("$SetModelMethodName$",
StringUtils.ucFirst(name)));
}
- template.addMethod(SIGNAL_METHOD_PREFFIX +
signalName, Keyword.PUBLIC)
+ MethodDeclaration processMethod = template
+ .addMethod(SIGNAL_METHOD_PREFFIX +
signalName, Keyword.PUBLIC)
.setType(signalProcessDeclarationClone.getType())
.setParameters(signalProcessDeclarationClone.getParameters())
.setBody(signalProcessBody)
.setAnnotations(signalProcessDeclarationClone.getAnnotations());
+ if (signalType != null) {
+
processMethod.findAll(ClassOrInterfaceType.class)
+ .forEach(t ->
t.setName(t.getNameAsString().replace("$signalType$", signalType)));
+ }
+
processMethod.findAll(StringLiteralExpr.class).forEach(vv -> {
+ String interpolated = vv.getValue()
+ .replace("$signalName$",
signalName)
+ .replace("$signalPath$",
sanitizeName(signalName));
+ vv.setString(interpolated);
+ });
});
// Create endpoint to signal process instances
- MethodDeclaration
signalInstanceDeclarationClone = signalInstanceDeclaration.clone();
- BlockStmt signalInstanceBody =
signalInstanceDeclarationClone.getBody()
- .orElseThrow(() -> new
RuntimeException("signalInstanceDeclaration doesn't have body"));
-
- if (signalType == null) {
- signalInstanceBody.findAll(NameExpr.class,
nameExpr -> "data".equals(nameExpr.getNameAsString())).forEach(name ->
name.replace(new NullLiteralExpr()));
- }
-
- template.addMethod(SIGNAL_METHOD_PREFFIX +
index.getAndIncrement(), Keyword.PUBLIC)
-
.setType(signalInstanceDeclarationClone.getType())
- // Remove data parameter ( payload )
if signalType is null
- .setParameters(signalType == null ?
NodeList.nodeList(signalInstanceDeclarationClone.getParameter(0)) :
signalInstanceDeclaration.getParameters())
- .setBody(signalInstanceBody)
-
.setAnnotations(signalInstanceDeclarationClone.getAnnotations());
-
- if (signalType != null) {
-
template.findAll(ClassOrInterfaceType.class).forEach(name -> {
- String identifier =
name.getNameAsString();
-
name.setName(identifier.replace("$signalType$", signalType));
- });
- }
-
-
template.findAll(StringLiteralExpr.class).forEach(vv -> {
- String s = vv.getValue();
- String interpolated =
s.replace("$signalName$", signalName);
- interpolated =
interpolated.replace("$signalPath$", sanitizeName(signalName));
- vv.setString(interpolated);
- });
+ addSignalInstanceEndpoint(
+ template,
+ signalInstanceDeclaration,
+ SIGNAL_METHOD_PREFFIX +
index.getAndIncrement(),
+ signalName,
+ signalType,
+ sanitizeName(signalName));
});
+ if (hasDynamicSignals) {
+ generateDynamicSignalEndpoint(template,
signalInstanceDeclaration);
Review Comment:
Can't we use `addSignalInstanceEndpoint` here as well? The goal should be to
have a single method that can then be called in line 364 and here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]