blob: 1423e9774af91329991568ea9400e505d593a283 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.template;
import com.yahoo.vespa.hosted.node.admin.task.util.text.Cursor;
import com.yahoo.vespa.hosted.node.admin.task.util.text.CursorRange;
/**
* Represents a template variable section
*
* @see Template
* @author hakonhall
*/
class VariableSection extends Section {
private final String name;
private final Cursor nameOffset;
VariableSection(CursorRange range, String name, Cursor nameOffset) {
super("variable", range);
this.name = name;
this.nameOffset = nameOffset;
}
String name() { return name; }
Cursor nameOffset() { return new Cursor(nameOffset); }
@Override
void appendTo(StringBuilder buffer) {
String value = template().getVariableValue(name)
.orElseThrow(() -> new TemplateNameNotSetException(name, nameOffset));
buffer.append(value);
}
@Override
void appendCopyTo(SectionList sectionList) {
sectionList.appendVariableSection(name, nameOffset, range().end());
}
}
|