Repository navigation
Expand file tree
/
Copy pathCorrectStateHintGuards.java
More file actions
109 lines (83 loc) · 2.73 KB
/
Copy pathCorrectStateHintGuards.java
File metadata and controls
109 lines (83 loc) · 2.73 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
package testSuite;
import liquidjava.specification.StateRefinement;
import liquidjava.specification.StateSet;
// The programs of ErrorStateHintGuards and ErrorStateHintArgumentConditions with their hints followed
public class CorrectStateHintGuards {
static void negated() {
FixedChannel c = FixedChannel.make();
if (!c.isClosed())
c.send();
}
static void withParameter() {
FixedLock l = new FixedLock();
if (l.tryLock(10))
l.unlock();
}
static void checkAllowed() {
FixedWriter w = new FixedWriter();
if (w.canWrite())
w.write();
}
static void twoParameters() {
FixedRange r = new FixedRange();
r.set(1, 2);
r.scan();
}
static void thenAnotherCall() {
FixedChain chain = new FixedChain();
chain.pick(1);
chain.next();
chain.done();
}
}
@StateSet({"open", "closed"})
class FixedChannel {
@StateRefinement(to = "open(this)")
public FixedChannel() {}
@StateRefinement(to = "return ? closed(this) : open(this)")
public boolean isClosed() { return false; }
@StateRefinement(from = "open(this)", to = "closed(this)")
public void close() {}
@StateRefinement(from = "open(this)")
public void send() {}
static FixedChannel make() { return new FixedChannel(); }
}
@StateSet({"unlocked", "locked"})
class FixedLock {
@StateRefinement(to = "unlocked(this)")
public FixedLock() {}
@StateRefinement(from = "unlocked(this)", to = "return ? locked(this) : unlocked(this)")
public boolean tryLock(long timeout) { return true; }
@StateRefinement(from = "locked(this)", to = "unlocked(this)")
public void unlock() {}
}
@StateSet({"start", "accept"})
class FixedWriter {
@StateRefinement(to = "start(this)")
public FixedWriter() {}
@StateRefinement(from = "start(this)", to = "return ? accept(this) : start(this)")
public boolean canWrite() { return true; }
@StateRefinement(from = "accept(this)")
public void write() {}
static FixedWriter make() { return new FixedWriter(); }
}
@StateSet({"low", "high"})
class FixedRange {
@StateRefinement(to = "low(this)")
public FixedRange() {}
@StateRefinement(to = "lo < hi ? high(this) : low(this)")
public void set(int lo, int hi) {}
@StateRefinement(from = "high(this)")
public void scan() {}
}
@StateSet({"a", "b", "c"})
class FixedChain {
@StateRefinement(to = "a(this)")
public FixedChain() {}
@StateRefinement(from = "a(this)", to = "k == 1 ? b(this) : a(this)")
public void pick(int k) {}
@StateRefinement(from = "b(this)", to = "c(this)")
public void next() {}
@StateRefinement(from = "c(this)")
public void done() {}
}