Files
openide/java/java-impl/resources/intentionDescriptions/EditContractIntention/description.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

34 lines
1.7 KiB
HTML

<html><body>
This intention changes a library method contract.
A method contract has the following syntax:
<pre><code>
contract ::= (clause ';')* clause
clause ::= args '->' effect
args ::= ((arg ',')* arg )?
arg ::= value-constraint
value-constraint ::= '_' | 'null' | '!null' | 'false' | 'true'
effect ::= value-constraint | 'fail' | 'new' | 'this' | 'param' number
number ::= [1-9] [0-9]*
</code></pre>
The constraints denote the following:<br/>
<ul>
<li> <code>_</code>: any value
<li> <code>null</code>: null value
<li> <code>null!</code>: a value statically proved to be not-null
<li> <code>true</code>: true boolean value
<li> <code>false</code>: false boolean value
<li> <code>fail</code>: the method throws exception if the arguments satisfy argument constraints
<li> <code>new</code>: every time the method is executed, it returns a non-null new object that is distinct from other objects existing in the heap prior to method execution. If the method is pure, the new object is not stored in any field or array and will be lost if method return value is not used.
<li> <code>this</code>: the method returns non-null this reference
<li> <code>param1 (param2, param3, etc.)</code>: the method returns its first (second, third, etc.) argument
</ul>
Examples:<br/>
<ul>
<li> <code>@Contract("_, null -> null")</code>: method returns null if its second argument is null.
<li> <code>@Contract("_, null -> null; _, !null -> !null")</code>: method returns null if its second argument is null and not-null otherwise.
<li> <code>@Contract("true -> fail")</code>: a typical <code>assertFalse</code> method which throws an exception if <code>true</code> is passed to it.
</ul>
</body></html>