Skip to content

Commit cee3554

Browse files
committed
Move SyntaxTreeNode to minijava.ast for future refactoring.
Also Add equals and hashCode for tests.
1 parent 3e0aad8 commit cee3554

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package pgdp.minijava;
1+
package pgdp.minijava.ast;
22

3-
import java.util.ArrayList;
4-
import java.util.Arrays;
5-
import java.util.Iterator;
6-
import java.util.NoSuchElementException;
3+
import java.util.*;
74

85
public class SyntaxTreeNode implements Iterable<SyntaxTreeNode>{
6+
// TODO: Replace generic class with FactoryPattern
7+
// -> move emitter logic to nodes
8+
99
private SyntaxTreeNode[] children;
1010
private final String value;
1111
private final Type type;
@@ -42,6 +42,23 @@ public Type getType() {
4242
return type;
4343
}
4444

45+
@Override
46+
public boolean equals(Object o) {
47+
if (this == o) {
48+
return true;
49+
}
50+
if (o == null || getClass() != o.getClass()) {
51+
return false;
52+
}
53+
SyntaxTreeNode that = (SyntaxTreeNode) o;
54+
return Arrays.equals(children, that.children) && Objects.equals(value, that.value) && type == that.type;
55+
}
56+
57+
@Override
58+
public int hashCode() {
59+
return Objects.hash(value, type);
60+
}
61+
4562
@Override
4663
public String toString() {
4764
StringBuilder out = new StringBuilder();

0 commit comments

Comments
 (0)