-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimitiveType.java
More file actions
71 lines (56 loc) · 1.68 KB
/
Copy pathPrimitiveType.java
File metadata and controls
71 lines (56 loc) · 1.68 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package jtree.nodes;
import static java.util.Collections.*;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.NonNull;
@EqualsAndHashCode
@Getter @Setter
public class PrimitiveType extends Type {
public static final Name BOOLEAN = new Name("boolean"),
BYTE = new Name("byte"),
SHORT = new Name("short"),
CHAR = new Name("char"),
INT = new Name("int"),
LONG = new Name("long"),
FLOAT = new Name("float"),
DOUBLE = new Name("double");
public static final Set<Name> VALUES = Set.of(BOOLEAN, BYTE, SHORT, CHAR, INT, LONG, FLOAT, DOUBLE);
protected @NonNull Name name;
public PrimitiveType(String name) {
this(new Name(name));
}
public PrimitiveType(Name name) {
this(name, emptyList());
}
public PrimitiveType(String name, List<Annotation> annotations) {
this(new Name(name), annotations);
}
public PrimitiveType(Name name, List<Annotation> annotations) {
super(annotations);
setName(name);
}
@Override
public PrimitiveType clone() {
return new PrimitiveType(getName(), clone(getAnnotations()));
}
@Override
public String toCode() {
return annotationString(false) + getName();
}
public void setName(@NonNull Name name) {
if(!VALUES.contains(name)) {
throw new IllegalArgumentException("'" + name + "' is not a primitive type");
}
this.name = name;
}
@Override
public <N extends INode> void accept(TreeVisitor visitor, Node parent, Consumer<N> replacer) {
if(visitor.visitPrimitiveType(this, parent, cast(replacer))) {
getName().accept(visitor, this, this::setName);
}
}
}