Browse Source

Polish `@Contract` Javadoc

pull/33827/head
Sébastien Deleuze 1 year ago
parent
commit
da8925131e
  1. 36
      spring-core/src/main/java/org/springframework/lang/Contract.java

36
spring-core/src/main/java/org/springframework/lang/Contract.java

@ -23,11 +23,14 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* Inspired from {@code org.jetbrains.annotations.Contract}, this variant has been introduce in the * <p>Specifies some aspects of the method behavior depending on the arguments.
* {@code org.springframework.lang} package to avoid requiring an extra dependency, while still following the same semantics. * Can be used by tools for advanced data flow analysis. Note that this annotation
* just describes how the code works and doesn't add any functionality by means of
* code generation.
* *
* <p>Specifies some aspects of the method behavior depending on the arguments. Can be used by tools for advanced data flow analysis. * <p>Inspired from {@code org.jetbrains.annotations.Contract}, this variant has
* Note that this annotation just describes how the code works and doesn't add any functionality by means of code generation. * been introduce in the {@code org.springframework.lang} package to avoid requiring
* an extra dependency, while still following the same semantics.
* *
* <p>Method contract has the following syntax:<br/> * <p>Method contract has the following syntax:<br/>
* contract ::= (clause ';')* clause<br/> * contract ::= (clause ';')* clause<br/>
@ -39,21 +42,26 @@ import java.lang.annotation.Target;
* *
* The constraints denote the following:<br/> * The constraints denote the following:<br/>
* <ul> * <ul>
* <li> _ - any value * <li> <code>_</code> - any value</li>
* <li> null - null value * <li> <code>null</code> - null value</li>
* <li> !null - a value statically proved to be not-null * <li> <code>!null</code> - a value statically proved to be not-null</li>
* <li> true - true boolean value * <li> <code>true</code> - true boolean value</li>
* <li> false - false boolean value * <li> <code>false</code> - false boolean value</li>
* <li> fail - the method throws an exception, if the arguments satisfy argument constraints * <li> <code>fail</code> - the method throws an exception, if the arguments satisfy argument
* constraints</li>
* </ul> * </ul>
* <p>Examples: * <p>Examples:
* <code>@Contract("_, null -> null")</code> - method returns null if its second argument is null<br/> * <code>@Contract("_, null -> null")</code> - method returns null if its second
* <code>@Contract("_, null -> null; _, !null -> !null")</code> - method returns null if its second argument is null and not-null otherwise<br/> * argument is null<br/>
* <code>@Contract("true -> fail")</code> - a typical assertFalse method which throws an exception if <code>true</code> is passed to it<br/> * <code>@Contract("_, null -> null; _, !null -> !null")</code> - method returns
* null if its second argument is null and not-null otherwise<br/>
* <code>@Contract("true -> fail")</code> - a typical assertFalse method which
* throws an exception if <code>true</code> is passed to it<br/>
* *
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 6.2 * @since 6.2
* @see <a href="https://github.com/uber/NullAway/wiki/Configuration#custom-contract-annotations">NullAway custom contract annotations</a> * @see <a href="https://github.com/uber/NullAway/wiki/Configuration#custom-contract-annotations">
* NullAway custom contract annotations</a>
*/ */
@Documented @Documented
@Retention(RetentionPolicy.CLASS) @Retention(RetentionPolicy.CLASS)

Loading…
Cancel
Save