-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractTreeSymbol.java
More file actions
33 lines (28 loc) · 1.1 KB
/
AbstractTreeSymbol.java
File metadata and controls
33 lines (28 loc) · 1.1 KB
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
import java.util.Set;
import java.util.HashSet;
import java.util.Objects;
public abstract class AbstractTreeSymbol implements TreeSymbol{
private final Type structure;
protected AbstractTreeSymbol(Type structure) {
this.structure = structure;
}
//Throws error if subexpression DNE or is not included in expectedTypes
//subexpressionDescription is included in error message
protected static final void validateSubexpression(Symbol subexpression,
Set<Type> expectedTypes, String subexpressionDescription) {
Objects.requireNonNull(subexpression);
if(! expectedTypes.contains(subexpression.getType())){
throw new IllegalArgumentException(subexpressionDescription);
}
}
//same method with slightly adjusted parameters
protected static final void validateSubexpression(Symbol subexpression,
Type expectedType, String subexpressionDescription) {
Set<Type> expectedTypes = new HashSet<>();
expectedTypes.add(expectedType);
validateSubexpression(subexpression, expectedTypes, subexpressionDescription);
}
public Type getStructure() {
return structure;
}
}