Skip to content

Commit 160c6cc

Browse files
committed
Improve Javadocs
1 parent 0fd494d commit 160c6cc

File tree

14 files changed

+216
-80
lines changed

14 files changed

+216
-80
lines changed

liquidjava-api/src/main/java/liquidjava/specification/ExternalRefinementsFor.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,37 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation to refine a class or interface of an external library
10-
* e.g. `@ExternalRefinementsFor("java.lang.Math")`
9+
* Annotation to refine a class or interface of an external library.
10+
* <p>
11+
* This annotation allows you to specify refinements and state transitions for classes from external libraries
12+
* that you cannot directly annotate. The refinements apply to all instances of the specified class.
13+
* <p>
14+
* <strong>Example:</strong>
15+
* <pre>
16+
* {@code
17+
* @ExternalRefinementsFor("java.lang.Math")
18+
* public interface MathRefinements {
19+
* @Refinement("_ >= 0")
20+
* public double sqrt(double x);
21+
* }
22+
* }
23+
* </pre>
1124
*
12-
* @author catarina gamboa
25+
* @author Catarina Gamboa
1326
*/
1427
@Retention(RetentionPolicy.RUNTIME)
1528
@Target({ElementType.TYPE})
1629
public @interface ExternalRefinementsFor {
1730

1831
/**
19-
* The fully qualified name of the class or interface for which the refinements are being defined
32+
* The fully qualified name of the class or interface for which the refinements are being defined.
33+
* <p>
34+
* <strong>Example:</strong>
35+
* <pre>
36+
* {@code
37+
* @ExternalRefinementsFor("java.lang.Math")
38+
* }
39+
* </pre>
2040
*/
21-
public String value();
41+
String value();
2242
}

liquidjava-api/src/main/java/liquidjava/specification/Ghost.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,37 @@
77
import java.lang.annotation.Target;
88

99
/**
10-
* Annotation to create a ghost variable for a class or interface
11-
* e.g. `@Ghost("int size")`
10+
* Annotation to create a ghost variable for a class or interface.
11+
* <p>
12+
* Ghost variables that only exist during the verification and can be used in refinements and state refinements.
13+
* They are not part of the actual implementation but help specify behavior and invariants.
14+
* <p>
15+
* <strong>Example:</strong>
16+
* <pre>
17+
* {@code
18+
* @Ghost("int size")
19+
* public class MyStack {
20+
* // ...
21+
* }
22+
* }
23+
* </pre>
1224
*
13-
* @author catarina gamboa
25+
* @author Catarina Gamboa
1426
*/
1527
@Retention(RetentionPolicy.RUNTIME)
1628
@Target({ElementType.TYPE})
1729
@Repeatable(GhostMultiple.class)
1830
public @interface Ghost {
1931

2032
/**
21-
* The type and name of the ghost variable
33+
* The type and name of the ghost variable.
34+
* <p>
35+
* <strong>Example:</strong>
36+
* <pre>
37+
* {@code
38+
* @Ghost("int size")
39+
* }
40+
* </pre>
2241
*/
23-
public String value();
42+
String value();
2443
}

liquidjava-api/src/main/java/liquidjava/specification/GhostMultiple.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation to allow the creation of multiple `@Ghost` annotations in a class or interface
10-
* e.g. `@GhostMultiple({@Ghost("int size"), @Ghost("boolean isEmpty")})`
9+
* Annotation to allow the creation of multiple ghost variables.
1110
*
12-
* @author catarina gamboa
11+
* @author Catarina Gamboa
1312
*/
1413
@Retention(RetentionPolicy.RUNTIME)
1514
@Target({ElementType.TYPE})
1615
public @interface GhostMultiple {
17-
18-
/**
19-
* The array of `@Ghost` annotations to be created
20-
*/
2116
Ghost[] value();
2217
}

liquidjava-api/src/main/java/liquidjava/specification/Refinement.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,50 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation to add a refinement to variables, class fields, method's parameters and method's return values
10-
* e.g. `@Refinement("x > 0") int x;`
9+
* Annotation to add a refinement to variables, class fields, method's parameters and method's return values.
10+
* <p>
11+
* Refinements are logical predicates that must hold for the annotated element.
12+
* <p>
13+
* <strong>Example:</strong>
14+
* <pre>
15+
* {@code
16+
* @Refinement("x > 0")
17+
* int x;
18+
*
19+
* @Refinement("_ >= 0")
20+
* public int getSize() {
21+
* // ...
22+
* }
23+
* }
24+
* </pre>
1125
*
12-
* @author catarina gamboa
26+
* @author Catarina Gamboa
1327
*/
1428
@Retention(RetentionPolicy.RUNTIME)
1529
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.PARAMETER, ElementType.TYPE})
1630
public @interface Refinement {
1731

1832
/**
19-
* The refinement string
33+
* The refinement string that defines a logical predicate that must hold for the annotated element.
34+
* <p>
35+
* <strong>Example:</strong>
36+
* <pre>
37+
* {@code
38+
* @Refinement("x > 0")
39+
* }
40+
* </pre>
2041
*/
21-
public String value();
42+
String value();
2243

2344
/**
24-
* An optional message to be included in the error message when the refinement is violated
45+
* Custom error message to be shown when the refinement is violated (optional).
46+
* <p>
47+
* <strong>Example:</strong>
48+
* <pre>
49+
* {@code
50+
* @Refinement(value = "x > 0", msg = "x must be positive")
51+
* }
52+
* </pre>
2553
*/
26-
public String msg() default "";
54+
String msg() default "";
2755
}

liquidjava-api/src/main/java/liquidjava/specification/RefinementAlias.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,39 @@
77
import java.lang.annotation.Target;
88

99
/**
10-
* Annotation to create a refinement alias
11-
* e.g. `@RefinementAlias("Nat(int x) { x > 0 }")`
10+
* Annotation to create a refinement alias to be reused in refinements.
11+
* <p>
12+
* Refinement aliases can be used to define reusable refinement predicates with parameters.
13+
* They help reduce duplication and improve readability of complex refinement specifications.
14+
* <p>
15+
* <strong>Example:</strong>
16+
* <pre>
17+
* {@code
18+
* @RefinementAlias("Nat(int x) { x > 0 }")
19+
* public class MyClass {
20+
* @Refinement("Nat(_)")
21+
* int value;
22+
* }
23+
* }
24+
* </pre>
1225
*
13-
* @author catarina gamboa
26+
* @see Refinement
27+
* @author Catarina Gamboa
1428
*/
1529
@Retention(RetentionPolicy.RUNTIME)
1630
@Target({ElementType.TYPE})
1731
@Repeatable(RefinementAliasMultiple.class)
1832
public @interface RefinementAlias {
1933

2034
/**
21-
* The refinement alias string, which includes the name of the alias, its parameters and the refinement itself
35+
* The refinement alias string, which includes the name of the alias, its parameters and the refinement itself.
36+
* <p>
37+
* <strong>Example:</strong>
38+
* <pre>
39+
* {@code
40+
* @RefinementAlias("Nat(int x) { x > 0 }")
41+
* }
42+
* </pre>
2243
*/
23-
public String value();
44+
String value();
2445
}

liquidjava-api/src/main/java/liquidjava/specification/RefinementAliasMultiple.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation to create multiple refinement aliases
10-
* e.g. `@RefinementAliasMultiple({@RefinementAlias("Nat(int x) { x > 0 }"), @RefinementAlias("Pos(int x) { x >= 0 }")})`
9+
* Annotation to create multiple refinement aliases.
1110
*
12-
* @author catarina gamboa
11+
* @author Catarina Gamboa
1312
*/
1413
@Retention(RetentionPolicy.RUNTIME)
1514
@Target({ElementType.TYPE})
1615
public @interface RefinementAliasMultiple {
17-
18-
/**
19-
* The array of `@RefinementAlias` annotations to be created
20-
*/
2116
RefinementAlias[] value();
2217
}

liquidjava-api/src/main/java/liquidjava/specification/RefinementPredicate.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,40 @@
77
import java.lang.annotation.Target;
88

99
/**
10-
* Annotation that allows the creation of ghosts or refinement aliases
11-
* e.g. `@RefinementPredicate("ghost int size")`, `@RefinementPredicate("type Nat(int x) { x > 0 }")`
12-
*
13-
* @author catarina gamboa
10+
* Annotation that allows the creation of ghost variables or refinement aliases within method or constructor scope.
11+
* <p>
12+
* This annotation enables the declaration of ghosts and refinement aliases.
13+
* <p>
14+
* <strong>Example:</strong>
15+
* <pre>
16+
* {@code
17+
* @RefinementPredicate("ghost int size")
18+
* @RefinementPredicate("type Nat(int x) { x > 0 }")
19+
* public void process() {
20+
* // ...
21+
* }
22+
* }
23+
* </pre>
24+
*
25+
* @see Ghost
26+
* @see RefinementAlias
27+
* @author Catarina Gamboa
1428
*/
1529
@Retention(RetentionPolicy.RUNTIME)
1630
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
1731
@Repeatable(RefinementPredicateMultiple.class)
1832
public @interface RefinementPredicate {
1933

2034
/**
21-
* The refinement predicate string, which can define a ghost variable or a refinement alias
35+
* The refinement predicate string, which can define a ghost variable or a refinement alias.
36+
* <p>
37+
* <strong>Example:</strong>
38+
* <pre>
39+
* {@code
40+
* @RefinementPredicate("ghost int size")
41+
* @RefinementPredicate("type Nat(int x) { x > 0 }")
42+
* }
43+
* </pre>
2244
*/
23-
public String value();
45+
String value();
2446
}

liquidjava-api/src/main/java/liquidjava/specification/RefinementPredicateMultiple.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation to allow the creation of multiple `@RefinementPredicate` annotations
10-
* e.g. `@RefinementPredicateMultiple({`@RefinementPredicate("ghost int size")`, `@RefinementPredicate("type Nat(int x) { x > 0 }")`})`
9+
* Annotation to allow the creation of multiple refinement predicates.
1110
*
12-
* @author catarina gamboa
11+
* @author Catarina Gamboa
1312
*/
1413
@Retention(RetentionPolicy.RUNTIME)
1514
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
1615
public @interface RefinementPredicateMultiple {
17-
18-
/**
19-
* The array of `@RefinementPredicate` annotations to be created
20-
*/
2116
RefinementPredicate[] value();
2217
}

liquidjava-api/src/main/java/liquidjava/specification/StateRefinement.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,63 @@
77
import java.lang.annotation.Target;
88

99
/**
10-
* Annotation to create state transitions in a method
11-
* e.g. `@StateRefinement(from="open(this)", to="closed(this)", msg="The object needs to be open before closing")`
10+
* Annotation to create state transitions in a method using states defined in state sets.
11+
* <p>
12+
* This annotation specifies the required precondition state and the resulting
13+
* postcondition state when a method or constructor is invoked.
14+
* Constructors can only specify the postcondition state since they create a new object.
15+
* <p>
16+
* <strong>Example:</strong>
17+
* <pre>
18+
* {@code
19+
* @StateRefinement(from="open(this)", to="closed(this)", msg="The object needs to be open before closing")
20+
* public void close() {
21+
* // ...
22+
* }
23+
* }
24+
* </pre>
1225
*
13-
* @author catarina gamboa
26+
* @see StateSet
27+
* @author Catarina Gamboa
1428
*/
1529
@Retention(RetentionPolicy.RUNTIME)
1630
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
1731
@Repeatable(StateRefinementMultiple.class)
1832
public @interface StateRefinement {
1933

2034
/**
21-
* The state in which the object needs to be before calling the method
35+
* The logical pre-condition that defines the state in which the object needs to be before calling the method (optional)
36+
* <p>
37+
* <strong>Example:</strong>
38+
* <pre>
39+
* {@code
40+
* @StateRefinement(from="open(this)")
41+
* }
42+
* </pre>
2243
*/
23-
public String from() default "";
44+
String from() default "";
2445

2546
/**
26-
* The state in which the object will be after calling the method
47+
* The logical post-condition that defines the state in which the object will be after calling the method (optional)
48+
* <p>
49+
* <strong>Example:</strong>
50+
* <pre>
51+
* {@code
52+
* @StateRefinement(from="open(this)", to="closed(this)")
53+
* }
54+
* </pre>
2755
*/
28-
public String to() default "";
56+
String to() default "";
2957

3058
/**
31-
* Optional custom error message to be included in the error message when the `from` is violated
59+
* Custom error message to be shown when the {@code from} pre-condition is violated (optional)
60+
* <p>
61+
* <strong>Example:</strong>
62+
* <pre>
63+
* {@code
64+
* @StateRefinement(from="open(this)", to="closed(this)", msg="The object needs to be open before closing")
65+
* }
66+
* </pre>
3267
*/
33-
public String msg() default "";
68+
String msg() default "";
3469
}

liquidjava-api/src/main/java/liquidjava/specification/StateRefinementMultiple.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation to allow the creation of multiple `@StateRefinement` annotations
10-
* e.g. `@StateRefinementMultiple({@StateRefinement(from="open(this)", to="closed(this)"), @StateRefinement(from="closed(this)", to="open(this)")})`
9+
* Annotation to allow the creation of multiple state transitions.
1110
*
12-
* @author catarina gamboa
11+
* @author Catarina Gamboa
1312
*/
1413
@Retention(RetentionPolicy.RUNTIME)
1514
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
1615
public @interface StateRefinementMultiple {
17-
18-
/**
19-
* The array of `@StateRefinement` annotations to be created
20-
*/
2116
StateRefinement[] value();
2217
}

0 commit comments

Comments
 (0)