[kotlin] J2K: Add more test cases for ReplaceGuardClauseWithFunctionCallInspection postprocessing step

KTIJ-28575

GitOrigin-RevId: ec918e359953249a6f248d21a4cba38b90104cdd
This commit is contained in:
Eve Matthaey
2024-03-25 19:18:50 +00:00
committed by intellij-monorepo-bot
parent bf745baec6
commit 596e92645d
2 changed files with 112 additions and 4 deletions
@@ -1,8 +1,69 @@
// IGNORE_K2
public class Test {
void test(String s) {
if (s == null) {
void testRequire(String s1, boolean b1, boolean b2) {
if (s1 == null) {
throw new IllegalArgumentException("s should not be null");
}
if (!b1) {
throw new IllegalArgumentException();
} else {
System.out.println("never mind");
}
// comment above b2
if (b2) {
throw new IllegalArgumentException();
}
if (!b1 && b2) throw new IllegalArgumentException();
else {
System.out.println(1);
System.out.println(2);
}
if (s1.length() < 3) {
throw new IllegalArgumentException();
} else if (s1.length() == 4) {
System.out.println(1);
} else {
System.out.println(2);
}
}
void testCheck(boolean b, String notNullString) {
if (b) throw new IllegalStateException();
// comment above notNullString
if (notNullString == null) {
throw new IllegalStateException()
}
}
void testDoubles(double x, double y) {
if (!(x < y)) {
throw new IllegalStateException()
}
if (y < 2*x) {
throw new IllegalStateException()
}
}
void doNotTouch(boolean b, String s1) {
try {
System.out.println("hello!");
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw new IllegalStateException(e);
}
}
if (b) {
throw new IndexOutOfBoundsException();
}
if (s1.length() < 5) {
System.out.println("Some other side effect");
throw new IllegalStateException("oops");
}
}
}
@@ -1,5 +1,52 @@
class Test {
fun test(s: String?) {
requireNotNull(s) { "s should not be null" }
fun testRequire(s1: String?, b1: Boolean, b2: Boolean) {
requireNotNull(s1) { "s should not be null" }
require(b1)
println("never mind")
// comment above b2
require(!b2)
require(!(!b1 && b2))
println(1)
println(2)
require(s1.length >= 3)
if (s1.length == 4) {
println(1)
} else {
println(2)
}
}
fun testCheck(b: Boolean, notNullString: String?) {
check(!b)
// comment above notNullString
checkNotNull(notNullString)
}
fun testDoubles(x: Double, y: Double) {
check((x < y))
check(!(y < 2 * x))
}
fun doNotTouch(b: Boolean, s1: String) {
try {
println("hello!")
} catch (e: Exception) {
if (e is RuntimeException) {
throw IllegalStateException(e)
}
}
if (b) {
throw IndexOutOfBoundsException()
}
if (s1.length < 5) {
println("Some other side effect")
throw IllegalStateException("oops")
}
}
}