blob: ed2aaf06de5680e8c15d0ea51b5619947a874074 (
plain)
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
|
package org.zwobble.couscous.ast;
import org.zwobble.couscous.ast.visitors.ExpressionNodeMapper;
import org.zwobble.couscous.values.*;
import java.util.function.Function;
import static org.zwobble.couscous.values.PrimitiveValues.value;
public class LiteralNode implements ExpressionNode {
public static LiteralNode literal(PrimitiveValue value) {
return new LiteralNode(value, value.getType());
}
public static LiteralNode literal(String value) {
return new LiteralNode(value(value), StringValue.REF);
}
public static LiteralNode literal(int value) {
return new LiteralNode(value(value), IntegerValue.REF);
}
public static LiteralNode literal(boolean value) {
return new LiteralNode(value(value), BooleanValue.REF);
}
public static LiteralNode literal(TypeName type) {
return new LiteralNode(value(type), ObjectValues.CLASS);
}
public static LiteralNode of(PrimitiveValue value, TypeName type) {
return new LiteralNode(value, type);
}
private final PrimitiveValue value;
private final TypeName type;
private LiteralNode(PrimitiveValue value, TypeName type) {
this.value = value;
this.type = type;
}
public TypeName getType() {
return type;
}
public PrimitiveValue getValue() {
return value;
}
@Override
public <T> T accept(ExpressionNodeMapper<T> visitor) {
return visitor.visit(this);
}
@Override
public ExpressionNode replaceExpressions(Function<ExpressionNode, ExpressionNode> replace) {
return this;
}
@Override
public String toString() {
return "LiteralNode(value=" + value + ", type=" + type + ")";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
LiteralNode other = (LiteralNode) obj;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
}
|