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: README.md
+2-10Lines changed: 2 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,17 +50,9 @@ Notice that the method `divide` now requires the parameter `b` to be non-zero. I
50
50
51
51
To follow along with this tutorial, make sure you have the following prerequisites installed:
52
52
53
-
- Java 20+, the JDK for compiling and running Java programs
54
-
- Maven 3.6+, for building and dependency management
55
53
- Visual Studio Code, for editing the code and using the LiquidJava extension
56
54
-[Java Extension Pack by Red Hat](vscode:extension/redhat.java), which provides Java support in VS Code
57
55
58
-
Then, build the project using Maven:
59
-
60
-
```bash
61
-
mvn clean install
62
-
```
63
-
64
56
Next, install the [LiquidJava VS Code extension](vscode:extension/AlcidesFonseca.liquid-java). This extension provides the LiquidJava typechecker with real-time error reporting and syntax highlighting for the refinements, which we will use throughout this tutorial.
65
57
66
58
**Important:** Currently, only one error is reported at a time, so an error might not be reported if another one is present! In each part of the tutorial, make sure to fix all errors before moving on to the next one.
@@ -101,7 +93,7 @@ With this alias, we can replace all occurrences of `@Refinement("_ >= 0")` with
101
93
102
94
Now, let's explore how to use **state refinements** to specify and verify properties about the state of an object. Open [ExampleStateRefinements.java](./src/main/java/com/tutorial/part2/ExampleStateRefinements.java). Here, we specify that this object can only be in two states: `a` or `b`. Then, in the constructor, we specify that the initial state is `a`, through the `@StateRefinement` annotation. This annotation allows us to specify in which state the object should be before the method is called (`from`), and in which state it will be after the method execution (`to`). In the constructor, since it's the first method to be called, we can only specify the `to` state.
103
95
104
-
This object has two methods, also called `a` and `b`. From the state refinements, we can see that the method `a` can only be called when the object is in state `a` transiting to state `b`. Similarly, the method `b` can only be called when the object is in state `b`, transiting to state `a`. This means that we cannot call the same method twice in a row, since it would violate the protocol established by the state refinements. Try uncommenting line 22 to observe the error.
96
+
This object has two methods, `toB` and `toA`. From the state refinements, we can see that the method `toB` can only be called when the object is in state `a` transiting to state `b`. Similarly, the method `toA` can only be called when the object is in state `b`, transiting to state `a`. This means that we cannot call the same method twice in a row, since it would violate the protocol established by the state refinements. Try uncommenting line 22 to observe the error.
105
97
106
98
#### Exercise
107
99
@@ -116,7 +108,7 @@ Now, open [ExampleSocketUsage.java](./src/main/java/com/tutorial/part3/ExampleSo
116
108
117
109
#### Exercise
118
110
119
-
Now, let's refine another external class. Open [MathRefinements.java](./src/main/java/com/tutorial/part3/exercise/MathRefinements.java). Your task is to replace the `"true"` refinements with the appropriate ones to refine the `java.lang.Math` class. We want to ensure that the `abs` method returns a non-negative value, the `max` method returns the larger of the two arguments, and the `min` method returns the smaller one. To check your implementation, uncomment the code in [MathRefinementsTest.java](./src/main/java/com/tutorial/part3/exercise/MathRefinementsTest.java), which should have no errors after you complete the refinements.
111
+
Now, let's refine another external class. Open [MathRefinements.java](./src/main/java/com/tutorial/part3/exercise/MathRefinements.java). Your task is to replace the `"true"` refinements with the appropriate ones to refine the `java.lang.Math` class. We want to ensure that the `max` method returns the larger of the two arguments and the `min` method returns the smaller one. To check your implementation, uncomment the code in [MathRefinementsTest.java](./src/main/java/com/tutorial/part3/exercise/MathRefinementsTest.java), which should have no errors after you complete the refinements.
0 commit comments