mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
34 lines
1.7 KiB
HTML
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>
|