-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisSample.java
45 lines (35 loc) · 1009 Bytes
/
DisSample.java
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
38
39
40
41
42
43
44
45
package dev.alephpt.Dis;
import java.util.HashMap;
import java.util.Map;
class DisSample {
private DisEnum enumd;
private final Map<String, Object> fields = new HashMap<>();
DisSample(DisEnum enumd) {
this.enumd = enumd;
}
Object get(Token name) {
if (fields.containsKey(name.lexeme)) {
return fields.get(name.lexeme);
}
if (name.literal instanceof Integer) {
String elementName = enumd.findElementName((Integer)name.literal);
if (elementName != null) {
return elementName;
}
}
Integer element = enumd.findElement(name.lexeme);
if (element != null) {
return element;
}
throw new RuntimeError(name, "Undefined Enum element '" + name.lexeme + "'.");
}
void set(Token name, Object value) {
fields.put(name.lexeme, value);
}
@Override
public String toString() {
if (enumd.name != null) { return "<" + enumd.name + " instance>"; }
DisC.error(null, "instance name is null");
return null;
}
}