Skip to content

Commit

Permalink
feat: update DSL to support shorthand for finish #1628
Browse files Browse the repository at this point in the history
  • Loading branch information
jgomer2001 committed Jun 29, 2022
1 parent ca32bd5 commit 71e4652
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,27 @@ public Object callAction(Object instance, String className, String methodName, O

//Search for a method/constructor matching name and arity

if (noInst && methodName.equals("new")) {
Constructor constr = Stream.of(actionCls.getConstructors()).filter(c -> pr.test(c, false))
.findFirst().orElse(null);
if (constr == null) {
String msg = String.format("Unable to find a constructor with arity %d in class %s",
arity, className);
logger.error(msg);
throw new InstantiationException(msg);
}
if (noInst) {
if (methodName.equals("new")) {
Constructor constr = Stream.of(actionCls.getConstructors()).filter(c -> pr.test(c, false))
.findFirst().orElse(null);
if (constr == null) {
String msg = String.format("Unable to find a constructor with arity %d in class %s",
arity, className);
logger.error(msg);
throw new InstantiationException(msg);
}

logger.debug("Constructor found");
Object[] args = getArgsForCall(constr, arity, rhinoArgs);
logger.debug("Constructor found");
Object[] args = getArgsForCall(constr, arity, rhinoArgs);

logger.debug("Creating an instance");
return constr.newInstance(args);
logger.debug("Creating an instance");
return constr.newInstance(args);

} else if (methodName.equals("class")) {
logger.debug("Returning class object");
return actionCls;
}
}

Method javaMethod = Stream.of(actionCls.getDeclaredMethods())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ keypair: ALPHANUM WS? ':' WS? expression ;

rfac: preassign? RFAC WS (STRING | variable) NL;

finish: FINISH WS (BOOL | variable) WS? NL ;
finish: FINISH WS (BOOL | STRING | variable) WS? NL ;

choice: MATCH WS simple_expr WS TO WS? INDENT option+ DEDENT elseblock? ;

Expand Down
6 changes: 4 additions & 2 deletions agama/transpiler/src/main/resources/JSGenerator.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ _flowCall(_it, _basePath, <@util_url_overrides node=.node.overrides/>, <@util_ar
</#macro>

<#macro finish>
<#if .node.variable?size = 0>
<#if .node.variable?size gt 0>
_it = ${.node.variable}
<#elseif .node.BOOL?size gt 0>
_it = ${.node.BOOL}
<#else>
_it = ${.node.variable}
_it = ${.node.STRING}
</#if>
return _finish(_it)
</#macro>
Expand Down
4 changes: 3 additions & 1 deletion agama/transpiler/src/main/resources/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ function _finish(val) {

let javaish = _javaish(val)

if (_isBool(val, javaish))
if (_isString(val, javaish))
return { success: true, data: { userId: val } }
else if (_isBool(val, javaish))
return { success: val }
else if (_isObject(val, javaish) && _isBool(val.success))
return val
Expand Down

0 comments on commit 71e4652

Please sign in to comment.