add value to ast node
This commit is contained in:
@ -7,10 +7,17 @@ import java.util.List;
|
|||||||
public class Node {
|
public class Node {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private String value;
|
||||||
private final List<Node> children = new ArrayList<>();
|
private final List<Node> children = new ArrayList<>();
|
||||||
|
|
||||||
public Node(String name) {
|
public Node(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.value = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node(String name, String value) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChild(Node node) {
|
public void addChild(Node node) {
|
||||||
@ -25,6 +32,10 @@ public class Node {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj instanceof Node) {
|
if (obj instanceof Node) {
|
||||||
@ -51,6 +62,10 @@ public class Node {
|
|||||||
private void print(StringBuilder buffer, String prefix, String childrenPrefix) {
|
private void print(StringBuilder buffer, String prefix, String childrenPrefix) {
|
||||||
buffer.append(prefix);
|
buffer.append(prefix);
|
||||||
buffer.append(this.name);
|
buffer.append(this.name);
|
||||||
|
if (!this.value.isBlank()) {
|
||||||
|
buffer.append(": ");
|
||||||
|
buffer.append(this.value);
|
||||||
|
}
|
||||||
buffer.append('\n');
|
buffer.append('\n');
|
||||||
|
|
||||||
for (Iterator<Node> it = this.children.listIterator(); it.hasNext(); ) {
|
for (Iterator<Node> it = this.children.listIterator(); it.hasNext(); ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user