|
7 | 7 | import java.lang.annotation.Target; |
8 | 8 |
|
9 | 9 | /** |
10 | | - * Annotation to create state transitions in a method. The annotation has three arguments: from : the |
11 | | - * state in which the object needs to be for the method to be invoked correctly to : the state in |
12 | | - * which the object will be after the execution of the method msg : optional custom error message to display when refinement is violated |
13 | | - * e.g. @StateRefinement(from="open(this)", to="closed(this)") |
| 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> |
14 | 25 | * |
15 | | - * @author catarina gamboa |
| 26 | + * @see StateSet |
| 27 | + * @author Catarina Gamboa |
16 | 28 | */ |
17 | 29 | @Retention(RetentionPolicy.RUNTIME) |
18 | 30 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) |
19 | 31 | @Repeatable(StateRefinementMultiple.class) |
20 | 32 | public @interface StateRefinement { |
21 | | - public String from() default ""; |
22 | 33 |
|
23 | | - public String to() default ""; |
| 34 | + /** |
| 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> |
| 43 | + */ |
| 44 | + String from() default ""; |
24 | 45 |
|
25 | | - public String msg() default ""; |
| 46 | + /** |
| 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> |
| 55 | + */ |
| 56 | + String to() default ""; |
| 57 | + |
| 58 | + /** |
| 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> |
| 67 | + */ |
| 68 | + String msg() default ""; |
26 | 69 | } |
0 commit comments