org.jetbrains.annotations
Annotation Type Contract


@Documented
@Retention(value=CLASS)
@Target(value=METHOD)
public @interface Contract

Specifies some aspects of the method behavior depending on the arguments. 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.

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'

The constraints 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


Optional Element Summary
 boolean pure
          Specifies if this method is pure, i.e.
 String value
          Contains the contract clauses describing causal relations between call arguments and the returned value
 

value

public abstract String value
Contains the contract clauses describing causal relations between call arguments and the returned value

Default:
""

pure

public abstract boolean pure
Specifies if this method is pure, i.e. has no visible side effects. This may be used for more precise data flow analysis, and to check that the method's return value is actually used in the call place.

Default:
false


Copyright © 2013. All rights reserved.