diff options
author | Håkon Hallingstad <hakon@yahooinc.com> | 2022-01-10 09:49:06 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@yahooinc.com> | 2022-01-10 09:49:06 +0100 |
commit | 7863aa3a9c5b13a4b420eeaab3c28144202200c6 (patch) | |
tree | a3e392866b6a3227ecb527a39b8850e005aaf434 /node-admin | |
parent | 51397e3dbb55225bb31391f3263545347a2bcecd (diff) |
Rename list to subform
Diffstat (limited to 'node-admin')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Form.java | 22 | ||||
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/FormBuilder.java | 12 | ||||
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/SubformSection.java (renamed from node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/ListSection.java) | 6 | ||||
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Template.java | 13 | ||||
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java | 8 | ||||
-rw-r--r-- | node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateFileTest.java | 20 | ||||
-rw-r--r-- | node-admin/src/test/resources/template1.tmp | 6 | ||||
-rw-r--r-- | node-admin/src/test/resources/template2.tmp | 4 | ||||
-rw-r--r-- | node-admin/src/test/resources/template3.tmp | 2 |
9 files changed, 40 insertions, 53 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Form.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Form.java index 1bbb9ff3639..00e2e87fc5a 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Form.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Form.java @@ -18,15 +18,15 @@ public class Form extends Section { private final List<Section> sections; private final Map<String, String> variables; - private final Map<String, ListSection> lists; + private final Map<String, SubformSection> subforms; Form(Form parent, CursorRange range, List<Section> sections, Map<String, String> variables, - Map<String, ListSection> lists) { + Map<String, SubformSection> subforms) { super(range); this.parent = parent; this.sections = List.copyOf(sections); this.variables = variables; // Mutable and referenced by the variable sections - this.lists = Map.copyOf(lists); + this.subforms = Map.copyOf(subforms); } /** Set the value of a variable expression, e.g. %{=color}. */ @@ -48,21 +48,9 @@ public class Form extends Section { return set(name, value); } - /** - * Append a list element form. A list section is declared as follows: - * - * <pre> - * %{list name}... - * %{end} - * </pre> - * - * <p>The body between %{list name} and %{end} is instantiated as a form, and appended after - * any previously added forms.</p> - * - * @return the added form - */ + /** Add an instance of a subform section after any previously added (for the given name) */ public Form add(String name) { - var section = lists.get(name); + var section = subforms.get(name); if (section == null) { throw new NoSuchNameTemplateException(this, name); } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/FormBuilder.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/FormBuilder.java index 179af5028b4..d0274d7777a 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/FormBuilder.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/FormBuilder.java @@ -16,7 +16,7 @@ import java.util.function.Consumer; class FormBuilder { private final List<Section> sections = new ArrayList<>(); private final Map<String, String> variables = new HashMap<>(); - private final Map<String, ListSection> lists = new HashMap<>(); + private final Map<String, SubformSection> subforms = new HashMap<>(); private final Form parent; private final CursorRange range; @@ -42,16 +42,16 @@ class FormBuilder { return this; } - FormBuilder addListSection(CursorRange range, String name, Template body) { + FormBuilder addSubformSection(CursorRange range, String name, Template body) { checkNameIsAvailable(name, range); - var section = new ListSection(range, name, body); + var section = new SubformSection(range, name, body); sections.add(section); - lists.put(section.name(), section); + subforms.put(section.name(), section); return this; } private Form build() { - var form = new Form(parent, range, sections, variables, lists); + var form = new Form(parent, range, sections, variables, subforms); sections.forEach(section -> section.setForm(form)); return form; } @@ -63,6 +63,6 @@ class FormBuilder { } private boolean nameIsDefined(String name) { - return variables.containsKey(name) || lists.containsKey(name); + return variables.containsKey(name) || subforms.containsKey(name); } } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/ListSection.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/SubformSection.java index 7971bb002b6..360a37964b2 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/ListSection.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/SubformSection.java @@ -7,17 +7,17 @@ import java.util.ArrayList; import java.util.List; /** - * Represents a template list section + * Represents a template subform section * * @see Template * @author hakonhall */ -class ListSection extends Section { +class SubformSection extends Section { private final Template body; private final String name; private final List<Form> elements = new ArrayList<>(); - ListSection(CursorRange range, String name, Template body) { + SubformSection(CursorRange range, String name, Template body) { super(range); this.name = name; this.body = body; diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Template.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Template.java index a603ee586c5..75055c216c6 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Template.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/Template.java @@ -16,10 +16,10 @@ import java.util.function.Consumer; * * <pre> * template: section* - * section: literal | variable | list + * section: literal | variable | subform * literal: plain text not containing %{ * variable: %{=identifier} - * list: %{list identifier}template%{end} + * subform: %{form identifier}template%{end} * identifier: a valid Java identifier * </pre> * @@ -29,10 +29,9 @@ import java.util.function.Consumer; * <p>To use the template, <b>Instantiate</b> it to get a form ({@link #instantiate()}), fill it (e.g. * {@link Form#set(String, String) Form.set()}), and render the String ({@link Form#render()}).</p> * - * <p>A form (like a template) has direct sections, and indirect sections in the body of direct list + * <p>A form (like a template) has direct sections, and indirect sections in the body of direct subforms * sections (recursively). The variables that can be set for a form, are the variables defined in - * either direct or indirect variable sections. Forms can only be added to direct list section in - * a form ({@link Form#add(String)}).</p> + * either direct or indirect variable sections.</p> * * @see Form * @see TemplateParser @@ -74,10 +73,10 @@ public class Template { sections.add(formBuilder -> formBuilder.addVariableSection(range, name, nameOffset)); } - void appendListSection(String name, Cursor nameCursor, Cursor end, Template body) { + void appendSubformSection(String name, Cursor nameCursor, Cursor end, Template body) { CursorRange range = verifyAndUpdateEnd(end); verifyNewName(name, nameCursor); - sections.add(formBuilder -> formBuilder.addListSection(range, name, body)); + sections.add(formBuilder -> formBuilder.addSubformSection(range, name, body)); } private CursorRange range() { return new CursorRange(start, end); } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java index ae0d6464b06..48bc4d737e2 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java @@ -78,8 +78,8 @@ class TemplateParser { throw new BadTemplateException(startOfType, "Extraneous 'end'"); parseEndDirective(); return false; - case "list": - parseListSection(); + case "form": + parseSubformSection(); break; default: throw new BadTemplateException(startOfType, "Unknown section '" + type + "'"); @@ -100,7 +100,7 @@ class TemplateParser { parseEndDelimiter(true); } - private void parseListSection() { + private void parseSubformSection() { skipRequiredWhitespaces(); var startOfName = new Cursor(current); String name = parseId(); @@ -109,7 +109,7 @@ class TemplateParser { TemplateParser bodyParser = parse(descriptor, current, FormEndsIn.END); current.set(bodyParser.current); - template.appendListSection(name, startOfName, current, bodyParser.template()); + template.appendSubformSection(name, startOfName, current, bodyParser.template()); } private void skipRequiredWhitespaces() { diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateFileTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateFileTest.java index db3e487910a..c316d4efe86 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateFileTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateFileTest.java @@ -20,10 +20,10 @@ class TemplateFileTest { } @Test - void verifySimpleListSection() { + void verifySimpleSubformSection() { Form form = getForm("template1.tmp"); form.set("varname", "varvalue") - .add("listname") + .add("formname") .set("varname", "different varvalue") .set("varname2", "varvalue2"); assertEquals("variable section 'varvalue'\n" + @@ -34,14 +34,14 @@ class TemplateFileTest { } @Test - void verifyNestedListSection() { + void verifyNestedSubformSection() { Form form = getForm("template2.tmp"); - Form A0 = form.add("listA"); - Form A0B0 = A0.add("listB"); - Form A0B1 = A0.add("listB"); + Form A0 = form.add("formA"); + Form A0B0 = A0.add("formB"); + Form A0B1 = A0.add("formB"); - Form A1 = form.add("listA"); - Form A1B0 = A1.add("listB"); + Form A1 = form.add("formA"); + Form A1B0 = A1.add("formB"); assertEquals("body A\n" + "body B\n" + "body B\n" + @@ -69,9 +69,9 @@ class TemplateFileTest { @Test void verifyNewlineRemoval() { - Form form = makeForm("a%{list a}\n" + + Form form = makeForm("a%{form a}\n" + "b%{end}\n" + - "c%{list c|}\n" + + "c%{form c|}\n" + "d%{end|}\n" + "e\n"); form.add("a"); diff --git a/node-admin/src/test/resources/template1.tmp b/node-admin/src/test/resources/template1.tmp index 62b629520bf..99df2a71f4d 100644 --- a/node-admin/src/test/resources/template1.tmp +++ b/node-admin/src/test/resources/template1.tmp @@ -1,9 +1,9 @@ variable section '%{=varname}' -%{list listname|} +%{form formname|} same variable section '%{=varname}' different variable section '%{=varname2}' -%{list innerlistname|} -inner list text +%{form innerformname|} +inner form text %{end|} between ends %{end|} diff --git a/node-admin/src/test/resources/template2.tmp b/node-admin/src/test/resources/template2.tmp index 4a6be865d18..d4b387cc653 100644 --- a/node-admin/src/test/resources/template2.tmp +++ b/node-admin/src/test/resources/template2.tmp @@ -1,4 +1,4 @@ -%{list listA|}body A -%{list listB|}body B +%{form formA|}body A +%{form formB|}body B %{end|} %{end|} diff --git a/node-admin/src/test/resources/template3.tmp b/node-admin/src/test/resources/template3.tmp index 372dfa62193..f0f08558220 100644 --- a/node-admin/src/test/resources/template3.tmp +++ b/node-admin/src/test/resources/template3.tmp @@ -1,6 +1,6 @@ %{=varname} %{=varname} -%{list l|} +%{form l|} inner %{=varname} %{=innerVarSetAtTop} %{end|} |