-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCorrectEnumUsage.java
More file actions
45 lines (36 loc) · 1.14 KB
/
CorrectEnumUsage.java
File metadata and controls
45 lines (36 loc) · 1.14 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
package testSuite;
import liquidjava.specification.StateRefinement;
import liquidjava.specification.StateSet;
@SuppressWarnings("unused")
@StateSet({"photoMode", "videoMode", "noMode"})
class CorrectEnumUsage {
enum Mode {
Photo, Video, Unknown
}
Mode mode;
@StateRefinement(to="noMode(this)")
public CorrectEnumUsage() {}
@StateRefinement(from="noMode(this) && mode == Mode.Photo", to="photoMode(this)")
@StateRefinement(from="noMode(this) && mode == Mode.Video", to="videoMode(this)")
public void setMode(Mode mode) {
this.mode = mode;
}
@StateRefinement(from="photoMode(this)", to="noMode(this)")
@StateRefinement(from="videoMode(this)", to="noMode(this)")
public void resetMode() {
this.mode = null;
}
@StateRefinement(from="photoMode(this)")
public void takePhoto() {}
@StateRefinement(from="videoMode(this)")
public void takeVideo() {}
public static void main(String[] args) {
// Correct
CorrectEnumUsage st = new CorrectEnumUsage();
st.setMode(Mode.Photo); // noMode -> photoMode
st.takePhoto();
st.resetMode(); // photoMode -> noMode
st.setMode(Mode.Video); // noMode -> videoMode
st.takeVideo();
}
}