diff --git a/platform/annotations/common/src/org/jetbrains/annotations/Contract.java b/platform/annotations/common/src/org/jetbrains/annotations/Contract.java index 3bbaadaaf4c7..efbed42c7df1 100644 --- a/platform/annotations/common/src/org/jetbrains/annotations/Contract.java +++ b/platform/annotations/common/src/org/jetbrains/annotations/Contract.java @@ -23,12 +23,13 @@ import java.util.concurrent.atomic.AtomicBoolean; * Note that this annotation just describes how the code works and doesn't add any functionality by means of code generation.
*
* Method contract has the following syntax:
- * contract ::= (clause ';')* clause
- * clause ::= args '->' effect
- * args ::= ((arg ',')* arg )?
- * arg ::= value-constraint
- * value-constraint ::= '_' | 'null' | '!null' | 'false' | 'true'
- * effect ::= value-constraint | 'fail'
+ *
{@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:
*
- * {@code @Contract("_, null -> null")} - method returns null if its second argument is null
- * {@code @Contract("_, null -> null; _, !null -> !null")} - method returns null if its second argument is null and not-null otherwise
- * {@code @Contract("true -> fail")} - a typical assertFalse method which throws an exception if {@code true} is passed to it
+ * {@code @Contract("_, null -> null")} - the method returns null if its second argument is null
+ * {@code @Contract("_, null -> null; _, !null -> !null")} - the method returns null if its second argument is null and not-null otherwise
+ * {@code @Contract("true -> fail")} - a typical {@code assertFalse} method which throws an exception if {@code true} is passed to it
+ * {@code @Contract("_ -> this")} - the method always returns its qualifier (e.g. {@link StringBuilder#append(String)}).
+ * {@code @Contract("null -> fail; _ -> param1")} - the method throws an exception if the first argument is null,
+ * otherwise it returns the first argument (e.g. {@code Objects.requireNonNull}).
+ * {@code @Contract("!null, _ -> param1; null, !null -> param2; null, null -> fail")} - the method returns the first non-null argument,
+ * or throws an exception if both arguments are null (e.g. {@code Objects.requireNonNullElse} in Java 9).
*
*/
@Documented