-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiteral.java
More file actions
160 lines (126 loc) · 3.12 KB
/
Copy pathLiteral.java
File metadata and controls
160 lines (126 loc) · 3.12 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package jtree.nodes;
import static lombok.AccessLevel.*;
import java.util.Objects;
import java.util.function.Consumer;
import org.apache.commons.text.StringEscapeUtils;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
@EqualsAndHashCode
@Getter @Setter
public class Literal extends Node implements Expression {
@Setter(NONE)
protected Object value;
@Getter(NONE) @Setter(NONE)
protected @NonNull String stringRep;
public Literal(int value, @NonNull String stringRep) {
this.value = value;
this.stringRep = stringRep;
}
public Literal(long value, @NonNull String stringRep) {
this.value = value;
this.stringRep = stringRep;
}
public Literal(float value, @NonNull String stringRep) {
this.value = value;
this.stringRep = stringRep;
}
public Literal(double value, @NonNull String stringRep) {
this.value = value;
this.stringRep = stringRep;
}
public Literal(char value, @NonNull String stringRep) {
this.value = value;
this.stringRep = stringRep;
}
public Literal(@NonNull String value, @NonNull String stringRep) {
this.value = value;
this.stringRep = stringRep;
}
public Literal(int value) {
setValue(value);
}
public Literal(long value) {
setValue(value);
}
public Literal(float value) {
setValue(value);
}
public Literal(double value) {
setValue(value);
}
public Literal(boolean value) {
setValue(value);
}
public Literal(char value) {
setValue(value);
}
public Literal() {
setValue((Void)null);
}
public Literal(String value) {
setValue(value);
}
protected Literal(Object value, String stringRep) {
this.value = value;
this.stringRep = stringRep;
}
@Override
public Precedence precedence() {
return Precedence.PRIMARY;
}
@Override
public Literal clone() {
return new Literal(value, stringRep);
}
public void setValue(int value) {
this.value = value;
this.stringRep = Objects.toString(value);
}
public void setValue(long value) {
this.value = value;
this.stringRep = value + "L";
}
public void setValue(float value) {
this.value = value;
this.stringRep = value + "f";
}
public void setValue(double value) {
this.value = value;
this.stringRep = Objects.toString(value);
}
public void setValue(boolean value) {
this.value = value;
this.stringRep = Objects.toString(value);
}
public void setValue(char value) {
this.value = value;
String valueStr = Objects.toString(value);
if(valueStr.equals("'")) {
this.stringRep = "'\\''";
} else {
this.stringRep = "'" + StringEscapeUtils.escapeJava(valueStr) + "'";
}
}
public void setValue(@NonNull String value) {
this.value = value;
this.stringRep = '"' + StringEscapeUtils.escapeJava(value) + '"';
}
public void setValue(Void value) {
this.value = value;
this.stringRep = "null";
}
@Override
public String toCode() {
return stringRep;
}
@Override
public String toString() {
return "Literal(" + toCode() + ")";
}
@Override
public <N extends INode> void accept(TreeVisitor visitor, Node parent, Consumer<N> replacer) {
visitor.visitLiteral(this, parent, cast(replacer));
}
}