You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concepts/state-refinements.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,9 @@ nav_order: 3
8
8
9
9
Beyond basic refinements, LiquidJava supports object state modeling through typestates. This lets you describe when a method can or cannot be called based on the state of the object.
10
10
11
-
The possible states of a class are declared with `@StateSet`, and the state transitions are described with `@StateRefinement(from = "...", to = "...")`:
12
-
-`from` describes the **precondition** - the object state in which the method can be invoked
13
-
-`to` describes the **postcondition** - the state the object will have after the method is called
11
+
The possible states of a class are declared with `@StateSet`, and the state transitions are described with `@StateRefinement(from="...", to="...")`.
12
+
-The `from` describes the **precondition** - the object state in which the method can be invoked
13
+
-The `to` describes the **postcondition** - the state the object will have after the method is called
14
14
15
15
```java
16
16
importliquidjava.specification.*;
@@ -55,7 +55,7 @@ public class Buffer {
55
55
}
56
56
```
57
57
58
-
If no `to` transition is written, LiquidJava defaults the constructor to the first state listed in the corresponding `@StateSet`.
58
+
If no `to` transition is declared, LiquidJava defaults the constructor to the first state listed in the corresponding `@StateSet`.
59
59
60
60
Constructors must always be present for typestate checking to work correctly, because they are the point where the initial state values are assigned. Otherwise, the initial values are not set and the verifier won't be able to track the state of the object across method calls, which can lead to unexpected type errors.
61
61
@@ -88,4 +88,4 @@ public class Device {
88
88
89
89
Each state set is exclusive: at any moment, the object can only be in one state from that specific set. In the example above, the object cannot be both `open` and `closed`, and it cannot be both `clean` and `dirty`.
90
90
91
-
When a transition affects multiple orthogonal states, the states must be combined with `&&` in the `from` and `to` annotations. In the example above, the `use` method transitions from `open && clean` to `open && dirty`, and the `close` method transitions from `open && clean` to `closed && clean`.
91
+
When using more than one state set, the states must be combined with `&&` in the `from` and `to` annotations, as shown in the example above. This is because the object must always be in exactly one state from each set, so we need to specify the full state of the object in the preconditions and postconditions.
0 commit comments