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: reference/external-refinements.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,10 +11,10 @@ External refinements let you attach a LiquidJava model to an existing class that
11
11
Use `@ExternalRefinementsFor` to describe the behavior of a library type in a separate interface. This lets you keep using the original library API in ordinary Java code while LiquidJava checks the extra specification in the background.
Copy file name to clipboardExpand all lines: reference/index.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,27 +4,27 @@ nav_order: 2
4
4
has_children: true
5
5
has_toc: false
6
6
permalink: /reference/
7
-
description: Browse the LiquidJava reference for refinements, typestates, aliases, ghost variables, and external refinements.
7
+
description: Browse the LiquidJava reference for refinements, aliases, state refinements, ghost variables, and external refinements.
8
8
cards:
9
9
- title: Refinements
10
10
url: /reference/refinements/
11
-
description: Review refinement syntax, annotation forms, and the main rules used during verification.
11
+
description: Learn about how to use refinements to specify constraints on variables, fields, parameters, and return values.
12
12
- title: Refinement Aliases
13
13
url: /reference/refinement-aliases/
14
-
description: Reuse common predicates with aliases to keep contracts shorter and easier to maintain.
15
-
- title: Typestates
16
-
url: /reference/typestates/
17
-
description: Model protocol-oriented object states and valid method transitions.
14
+
description: Learn how to reuse common refinement predicates with aliases to keep contracts shorter and easier to maintain.
15
+
- title: State Refinements
16
+
url: /reference/state-refinements/
17
+
description: Learn how to model protocol-oriented object states and valid method transitions.
18
18
- title: Ghost Variables
19
19
url: /reference/ghost-variables/
20
-
description: Track logical state that helps express and verify richer object invariants.
20
+
description: Learn how to track logical state that helps express and verify richer object invariants.
21
21
- title: External Refinements
22
22
url: /reference/external-refinements/
23
-
description: Attach contracts to code you cannot or do not want to annotate directly.
23
+
description: Learn how to refine external libraries that cannot be annotated directly.
24
24
---
25
25
26
26
# LiquidJava Reference
27
27
28
-
LiquidJava extends Java with logical refinements and object protocol specifications. This section covers the core annotation model.
28
+
LiquidJava extends Java with logical predicates and object protocol specifications. This section covers the core concepts and features of the LiquidJava type system.
Copy file name to clipboardExpand all lines: reference/refinements.md
+6-38Lines changed: 6 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,12 @@ nav_order: 1
6
6
7
7
# Refinements
8
8
9
-
Liquid types extend a language with logical predicates over basic types. They let you restrict the values a variable, parameter, field, or return value can have, which helps catch bugs before the program runs.
9
+
In LiquidJava, refinements allow us to express restrictions as logical predicates over basic types. They let us restrict the values a variable, field, parameter, or return value can have, which helps catch bugs before the program runs.
10
10
11
-
In LiquidJava, refinements are written with `@Refinement`. The predicate must be a boolean expression that refers to the refined value either by its declared name or by `_`.
12
-
13
-
These constraints are useful for preventing errors such as array index out-of-bounds or division by zero at compile time.
14
-
15
-
## Variables, Fields, Parameters, and Returns
11
+
These are written as strings in the `@Refinement` annotation. The predicate must be a boolean expression that refers to the refined value either by its declared name or by `_`.
16
12
17
13
```java
18
-
importliquidjava.specification.Refinement;
14
+
importliquidjava.specification.*;
19
15
20
16
publicclassRefinementExamples {
21
17
@Refinement("x > 0") // x must be greater than 0
@@ -24,42 +20,14 @@ public class RefinementExamples {
24
20
@Refinement("0 <= _ && _ <= 100") // y must be between 0 and 100
25
21
int y;
26
22
27
-
@Refinement(value="z % 2 == 0 ? z >= 0 : z < 0",
28
-
msg="z must be positive if even, negative if odd")
23
+
@Refinement("z % 2 == 0 ? z >= 0 : z < 0") // z must be positive if even, negative if odd
29
24
int z;
30
25
31
-
@Refinement("_ >= 0")
32
-
intabsDiv(inta, @Refinement(value="b != 0", msg="cannot divide by zero") intb) {
26
+
@Refinement("_ >= 0")// the return value must be non-negative
27
+
intabsDiv(inta, @Refinement("b != 0") intb) {// b must be non-zero
33
28
int res = a / b;
34
29
return res >=0? res :-res;
35
30
}
36
31
}
37
32
```
38
33
39
-
A refinement can be attached to:
40
-
41
-
- local variables and fields
42
-
- method parameters
43
-
- method return values
44
-
45
-
## Writing Predicates
46
-
47
-
Predicates can:
48
-
49
-
- use the declared variable name directly, such as `x > 0`
50
-
- use `_` as a placeholder for the refined value
51
-
- combine arithmetic, comparisons, conjunctions, disjunctions, and conditional expressions
52
-
- include a custom `msg` to make verification failures easier to understand
53
-
54
-
## Typical Uses
55
-
56
-
- Non-zero divisors
57
-
- Positive counters
58
-
- Bounded percentages
59
-
- Numeric relationships between parameters and return values
60
-
61
-
## What Happens on Failure
62
-
63
-
When LiquidJava cannot prove a refinement, it reports a verification error at compile time instead of letting the incorrect use reach runtime.
64
-
65
-
Continue with [Refinement Aliases]({{ '/reference/refinement-aliases/' | relative_url }}) when you want reusable predicate building blocks.
Copy file name to clipboardExpand all lines: reference/state-refinements.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
---
2
-
title: Typestates
2
+
title: State Refinements
3
3
parent: Reference
4
4
nav_order: 3
5
5
---
6
6
7
-
# Typestates
7
+
# State Refinements
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.
0 commit comments