blob: 6bd7870b107d9378ebc77be703f15deaacc2d23f (
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
|
package org.zwobble.couscous.ast.sugar;
import com.google.common.collect.Iterables;
import org.zwobble.couscous.ast.ExpressionNode;
import org.zwobble.couscous.ast.Node;
import org.zwobble.couscous.ast.NodeTypes;
import org.zwobble.couscous.ast.StatementNode;
import org.zwobble.couscous.ast.visitors.NodeTransformer;
import org.zwobble.couscous.util.ExtraIterables;
import java.util.List;
import java.util.Optional;
public class SwitchCaseNode implements Node {
public static SwitchCaseNode switchCase(ExpressionNode value, List<StatementNode> statements) {
return switchCase(Optional.of(value), statements);
}
public static SwitchCaseNode switchCase(List<StatementNode> statements) {
return switchCase(Optional.empty(), statements);
}
public static SwitchCaseNode switchCase(Optional<ExpressionNode> value, List<StatementNode> statements) {
return new SwitchCaseNode(value, statements);
}
private final Optional<ExpressionNode> value;
private final List<StatementNode> statements;
public SwitchCaseNode(Optional<ExpressionNode> value, List<StatementNode> statements) {
this.value = value;
this.statements = statements;
}
public boolean isDefault() {
return !value.isPresent();
}
public Optional<ExpressionNode> getValue() {
return value;
}
public List<StatementNode> getStatements() {
return statements;
}
@Override
public int type() {
return NodeTypes.SWITCH_CASE;
}
@Override
public Iterable<? extends Node> childNodes() {
return Iterables.concat(
ExtraIterables.iterable(value),
statements
);
}
@Override
public SwitchCaseNode transformSubtree(NodeTransformer transformer) {
return new SwitchCaseNode(
value.map(transformer::transformExpression),
transformer.transformStatements(statements)
);
}
}
|