blob: 64bfd011fed61125c63ab19395ca02f3dbb33835 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import java.lang.*;
import java.lang.AssertionError;
import java.lang.IllegalArgumentException;
public class AssertIsNotNull {
void bar(String s) {
if (<warning descr="Condition 's == null && trimIfNotNull(s) != null' is always 'false'">s == null && <warning descr="Condition 'trimIfNotNull(s) != null' is always 'false' when reached">trimIfNotNull(s) != null</warning></warning>) {
throw new AssertionError();
}
final Object o = call();
assertIsNotNull(o);
if(<warning descr="Condition 'o == null' is always 'false'">o == null</warning>) {}
}
@Contract("null -> fail")
static void assertIsNotNull(Object o) {
if (o == null) {
throw new IllegalArgumentException();
}
}
@Contract("null -> null; !null -> !null")
@Nullable static String trimIfNotNull(@Nullable String s) {
if (s == null) {
return null;
}
return s.trim();
}
Object call() {return new Object();}
@Contract(<warning descr="A contract clause must be in form arg1, ..., argN -> return-value">"a"</warning>)
void malformedContract() {}
@Contract(<warning descr="Method takes 2 parameters, while contract clause 0 expects 1">"null -> _"</warning>)
void wrongParameterCount(Object a, boolean b) {}
}
|