-
-
Notifications
You must be signed in to change notification settings - Fork 342
/
CtCase.java
118 lines (103 loc) · 3.52 KB
/
CtCase.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
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
/*
* SPDX-License-Identifier: (MIT OR CECILL-C)
*
* Copyright (C) 2006-2023 INRIA and contributors
*
* Spoon is available either under the terms of the MIT License (see LICENSE-MIT.txt) or the Cecill-C License (see LICENSE-CECILL-C.txt). You as the user are entitled to choose the terms under which to adopt Spoon.
*/
package spoon.reflect.code;
import org.jspecify.annotations.Nullable;
import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;
import spoon.reflect.path.CtRole;
import java.util.List;
import static spoon.reflect.path.CtRole.CASE_KIND;
import static spoon.reflect.path.CtRole.EXPRESSION;
/**
* This code element defines a case within a switch-case.
*
* Example: <pre>
* int x = 0;
* switch(x) {
* case 1: // <-- case statement
* System.out.println("foo");
* }</pre>
*
* @param <S>
* This type must be assignable from the switch type
* @see spoon.reflect.code.CtSwitch
*/
public interface CtCase<S> extends CtStatement, CtStatementList {
/**
* Gets the case expression.
* Use {@link #getCaseExpressions()} since Java 12
*/
@PropertyGetter(role = EXPRESSION)
CtExpression<S> getCaseExpression();
/**
* Sets the case expression. If set with null, the CtCase will represent a default label.
* Use {@link #setCaseExpressions(List)} since Java 12
*/
@PropertySetter(role = EXPRESSION)
<T extends CtCase<S>> T setCaseExpression(CtExpression<S> caseExpression);
/**
* Gets the case expressions.
* (Multiple case expressions are available as a preview feature since Java 12)
*/
@PropertyGetter(role = EXPRESSION)
List<CtExpression<S>> getCaseExpressions();
/**
* Sets the case expressions. If set with null or an empty list, the CtCase will represent a default label.
* (Multiple case expressions are available as a preview feature since Java 12)
*/
@PropertySetter(role = EXPRESSION)
<T extends CtCase<S>> T setCaseExpressions(List<CtExpression<S>> caseExpressions);
/**
* Adds case expression.
* (Multiple case expressions are available as a preview feature since Java 12)
*/
@PropertySetter(role = EXPRESSION)
<T extends CtCase<S>> T addCaseExpression(CtExpression<S> caseExpression);
/**
* Gets the kind of this case - colon (:) or arrow (->)
* (Arrow syntax is available as a preview feature since Java 12)
*/
@PropertyGetter(role = CASE_KIND)
CaseKind getCaseKind();
/**
* Sets the kind of this case - colon (:) or arrow (->)
* (Arrow syntax is available as a preview feature since Java 12)
*/
@PropertySetter(role = CASE_KIND)
<T extends CtCase<S>> T setCaseKind(CaseKind kind);
/**
* {@return whether this case includes a trailing {@code default}}
*/
@PropertyGetter(role = CtRole.DEFAULT_EXPRESSION)
boolean getIncludesDefault();
/**
* Sets whether this case includes a trailing {@code default}.
*
* @param includesDefault whether this case includes a {@code default}.
* @return this case.
*/
@PropertySetter(role = CtRole.DEFAULT_EXPRESSION)
CtCase<S> setIncludesDefault(boolean includesDefault);
/**
* {@return the guard of this case}
* This method returns {@code null} if no guard is present.
*/
@PropertyGetter(role = CtRole.CONDITION)
@Nullable
CtExpression<?> getGuard();
/**
* Sets the guarding expression for this case.
*
* @param guard the expression guarding this case. If {@code null}, no guard will be inserted in the code.
* @return this case.
*/
@PropertySetter(role = CtRole.CONDITION)
CtCase<S> setGuard(@Nullable CtExpression<?> guard);
@Override
CtCase<S> clone();
}