require typed construction of CommandTemplate

This commit is contained in:
Jonathan Shook
2021-06-24 11:27:00 -05:00
parent d0371ecc16
commit 5415f0b138
3 changed files with 11 additions and 10 deletions

View File

@@ -60,14 +60,14 @@ public class CommandTemplate {
* is non-null, then it taken as a line-oriented value and parsed according to default {@link ParamsParser} behavior. * is non-null, then it taken as a line-oriented value and parsed according to default {@link ParamsParser} behavior.
* However, the provided parsers (if any) are used first in order to match alternate forms of syntax. * However, the provided parsers (if any) are used first in order to match alternate forms of syntax.
* *
* See {@link CommandTemplate#CommandTemplate(String, Object, Map, Map, List)} for full details on the provided * See {@link CommandTemplate#CommandTemplate(String, String, Map, Map, List)} for full details on the provided
* parsers. * parsers.
* *
* @param optpl An OpTemplate * @param optpl An OpTemplate
* @param parsers A list of parser functions * @param parsers A list of parser functions
*/ */
public CommandTemplate(OpTemplate optpl, List<Function<String, Map<String, String>>> parsers) { public CommandTemplate(OpTemplate optpl, List<Function<String, Map<String, String>>> parsers) {
this(optpl.getName(), optpl.getOp(), optpl.getParamsAsValueType(String.class), optpl.getBindings(), parsers); this(optpl.getName(), optpl.getStmt().orElseThrow(), optpl.getParamsAsValueType(String.class), optpl.getBindings(), parsers);
} }
/** /**
@@ -94,7 +94,7 @@ public class CommandTemplate {
*/ */
public CommandTemplate( public CommandTemplate(
String name, String name,
Object op, String op,
Map<String, String> params, Map<String, String> params,
Map<String, String> bindings, Map<String, String> bindings,
List<Function<String, Map<String, String>>> optionalParsers List<Function<String, Map<String, String>>> optionalParsers
@@ -108,8 +108,9 @@ public class CommandTemplate {
// If none of the supplemental parsers work, the default params parser is used // If none of the supplemental parsers work, the default params parser is used
String oneline; String oneline;
if (op instanceof CharSequence) { if (op instanceof CharSequence) {
oneline = op.toString(); oneline = op;
} else { } else {
throw new BasicError("Unable to create a oneline version of the CommandTemplate with op type of " + op.getClass().getSimpleName()); throw new BasicError("Unable to create a oneline version of the CommandTemplate with op type of " + op.getClass().getSimpleName());
} }

View File

@@ -16,8 +16,8 @@ public class CommandTemplateTest {
StmtsDocList stmtsDocs = StatementsLoader.loadString("" + StmtsDocList stmtsDocs = StatementsLoader.loadString("" +
"statements:\n" + "statements:\n" +
" - s1: test1=foo test2=bar"); " - s1: test1=foo test2=bar");
OpTemplate stmtDef = stmtsDocs.getStmts().get(0); OpTemplate optpl = stmtsDocs.getStmts().get(0);
CommandTemplate ct = new CommandTemplate(stmtDef); CommandTemplate ct = new CommandTemplate(optpl);
assertThat(ct.isStatic()).isTrue(); assertThat(ct.isStatic()).isTrue();
} }
@@ -29,8 +29,8 @@ public class CommandTemplateTest {
" - s1: test1=foo test2={bar}\n" + " - s1: test1=foo test2={bar}\n" +
" bindings:\n" + " bindings:\n" +
" bar: NumberNameToString();\n"); " bar: NumberNameToString();\n");
OpTemplate stmtDef = stmtsDocs.getStmts().get(0); OpTemplate optpl = stmtsDocs.getStmts().get(0);
CommandTemplate ct = new CommandTemplate(stmtDef); CommandTemplate ct = new CommandTemplate(optpl);
String format = gson.toJson(ct); String format = gson.toJson(ct);
System.out.println(format); System.out.println(format);

View File

@@ -27,7 +27,7 @@ public class VirtData {
} }
List<BindPoint> bindPoints = new ArrayList<>(); List<BindPoint> bindPoints = new ArrayList<>();
for (int i = 0; i < namesAndSpecs.length; i += 2) { for (int i = 0; i < namesAndSpecs.length; i += 2) {
bindPoints.add(new BindPoint(namesAndSpecs[i],namesAndSpecs[i+1])); bindPoints.add(new BindPoint(namesAndSpecs[i],namesAndSpecs[i+1], BindPoint.Type.definition));
} }
return getTemplate(config, bindPoints); return getTemplate(config, bindPoints);
} }
@@ -169,7 +169,7 @@ public class VirtData {
T actualTestValue = mapper.get().get(1L); T actualTestValue = mapper.get().get(1L);
if (!ClassUtils.isAssignable(actualTestValue.getClass(),clazz,true)) { if (!ClassUtils.isAssignable(actualTestValue.getClass(),clazz,true)) {
throw new RuntimeException("The flow specifier '" + flowSpec + "' successfully created a function, but the test value" + throw new RuntimeException("The flow specifier '" + flowSpec + "' successfully created a function, but the test value" +
"(" + String.valueOf(actualTestValue) + ") of type [" + actualTestValue.getClass() + "] produced by it was not " + "(" + actualTestValue + ") of type [" + actualTestValue.getClass() + "] produced by it was not " +
"assignable to the type '" + clazz.getCanonicalName() + "' which was explicitly set" + "assignable to the type '" + clazz.getCanonicalName() + "' which was explicitly set" +
" at the API level."); " at the API level.");
} }