From 72e7f1552b8af1e877ecb3541568d91c1b634dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Wed, 6 Nov 2024 12:00:08 +0100 Subject: [PATCH] Refine `@Contract` Javadoc This commit refines `@Contract` Javadoc to mention this and new return values. Closes gh-33849 --- .../org/springframework/lang/Contract.java | 55 ++++++++++++------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/lang/Contract.java b/spring-core/src/main/java/org/springframework/lang/Contract.java index 6125b10fd83b..eff30e21e6fe 100644 --- a/spring-core/src/main/java/org/springframework/lang/Contract.java +++ b/spring-core/src/main/java/org/springframework/lang/Contract.java @@ -32,34 +32,47 @@ * been introduce in the {@code org.springframework.lang} package to avoid requiring * an extra dependency, while still following the same semantics. * - *

Method contract has the following syntax:
- * contract ::= (clause ';')* clause
- * clause ::= args '->' effect
- * args ::= ((arg ',')* arg )?
- * arg ::= value-constraint
- * value-constraint ::= 'any' | 'null' | '!null' | 'false' | 'true'
- * effect ::= value-constraint | 'fail' + *

Method contract has the following syntax: + *

{@code
+ *  contract ::= (clause ';')* clause
+ *  clause ::= args '->' effect
+ *  args ::= ((arg ',')* arg )?
+ *  arg ::= value-constraint
+ *  value-constraint ::= '_' | 'null' | '!null' | 'false' | 'true'
+ *  effect ::= value-constraint | 'fail' | 'this' | 'new' | 'param'}
* - * The constraints denote the following:
+ *

The constraints denote the following: *

+ * + *

The additional return values denote the following: + *

+ * *

Examples: - * @Contract("_, null -> null") - method returns null if its second - * argument is null
- * @Contract("_, null -> null; _, !null -> !null") - method returns - * null if its second argument is null and not-null otherwise
- * @Contract("true -> fail") - a typical assertFalse method which - * throws an exception if true is passed to it
+ *

* * @author Sebastien Deleuze * @since 6.2 + * @see org.jetbrains.annotations.Contract * @see * NullAway custom contract annotations */