diff options
Diffstat (limited to 'java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy')
-rw-r--r-- | java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy index 89762efe5dd2..c3bb014d8342 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy @@ -27,7 +27,7 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase { def c = inferContract(""" String smth(String s) { if (s == null) return null; - return s.substring(1); + return smth(); } """) assert c == 'null -> null' @@ -310,6 +310,55 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase { assert c == [] } + public void "test skip empty declarations"() { + def c = inferContracts(""" + final Object foo(Object bar) { + Object o = 2; + if (bar == null) return null; + return new String("abc"); + } + """) + assert c == ['null -> null', '!null -> !null'] + } + + public void "test go inside do-while"() { + def c = inferContracts(""" + final Object foo(Object bar) { + do { + if (bar == null) return null; + bar = smth(bar); + } while (smthElse()); + return new String("abc"); + } + """) + assert c == ['null -> null'] + } + + public void "test go inside try"() { + def c = inferContracts(""" + final Object foo(Object bar) { + try { + if (bar == null) return null; + bar = smth(bar); + } finally {} + return new String("abc"); + } + """) + assert c == ['null -> null'] + } + + public void "test use invoked method notnull"() { + def c = inferContracts(""" + final Object foo(Object bar) { + if (bar == null) return null; + return doo(); + } + + @org.jetbrains.annotations.NotNull Object doo() {} + """) + assert c == ['null -> null', '!null -> !null'] + } + private String inferContract(String method) { return assertOneElement(inferContracts(method)) } |