Skip to content

Commit e99d9aa

Browse files
committed
Update Reference Section
1 parent 3a063db commit e99d9aa

7 files changed

Lines changed: 22 additions & 54 deletions

File tree

reference/external-refinements.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ External refinements let you attach a LiquidJava model to an existing class that
1111
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.
1212

1313
```java
14-
import liquidjava.specification.ExternalRefinementsFor;
15-
import liquidjava.specification.StateRefinement;
14+
import liquidjava.specification.*;
1615

1716
@ExternalRefinementsFor("java.net.Socket")
17+
@StateSet({"unconnected, bound, connected, closed"})
1818
public interface SocketRefinements {
1919
@StateRefinement(to = "unconnected(this)")
2020
public void Socket();

reference/ghost-variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface StackRefinements<E> {
2121
public void Stack();
2222

2323
@StateRefinement(to = "size(this) == size(old(this)) + 1")
24-
public boolean push(E elem);
24+
public E push(E elem);
2525

2626
@StateRefinement(from = "size(this) > 0",
2727
to = "size(this) == size(old(this)) - 1",

reference/index.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ nav_order: 2
44
has_children: true
55
has_toc: false
66
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.
88
cards:
99
- title: Refinements
1010
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.
1212
- title: Refinement Aliases
1313
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.
1818
- title: Ghost Variables
1919
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.
2121
- title: External Refinements
2222
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.
2424
---
2525

2626
# LiquidJava Reference
2727

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.
2929

3030
{% include card_grid.html cards=page.cards %}

reference/refinement-aliases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ Aliases are a good fit for constraints such as:
3535
- value classes such as positive or non-negative integers
3636
- project-wide concepts that appear in many files
3737

38-
For object protocols, move on to [Typestates]({{ '/reference/typestates/' | relative_url }}).
38+
For object protocols, move on to [State Refinements]({{ '/reference/state-refinements/' | relative_url }}).

reference/refinements.md

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ nav_order: 1
66

77
# Refinements
88

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.
1010

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 `_`.
1612

1713
```java
18-
import liquidjava.specification.Refinement;
14+
import liquidjava.specification.*;
1915

2016
public class RefinementExamples {
2117
@Refinement("x > 0") // x must be greater than 0
@@ -24,42 +20,14 @@ public class RefinementExamples {
2420
@Refinement("0 <= _ && _ <= 100") // y must be between 0 and 100
2521
int y;
2622

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
2924
int z;
3025

31-
@Refinement("_ >= 0")
32-
int absDiv(int a, @Refinement(value = "b != 0", msg = "cannot divide by zero") int b) {
26+
@Refinement("_ >= 0") // the return value must be non-negative
27+
int absDiv(int a, @Refinement("b != 0") int b) { // b must be non-zero
3328
int res = a / b;
3429
return res >= 0 ? res : -res;
3530
}
3631
}
3732
```
3833

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.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Typestates
2+
title: State Refinements
33
parent: Reference
44
nav_order: 3
55
---
66

7-
# Typestates
7+
# State Refinements
88

99
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.
1010

tooling/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mvn exec:java -pl liquidjava-verifier \
3535
## Example Outcomes
3636

3737
- A correct file should pass verification.
38-
- A file that violates a refinement or typestate should produce an error that points to the failed contract.
38+
- A file that violates a refinement should produce an error that points to the failed contract.
3939

4040
## When to Use the CLI
4141

0 commit comments

Comments
 (0)