Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/EscapeAnalysis.java
Tagir Valeev e3e0174973 Inline lambdas from locals that used only once (IDEA-224757)
GitOrigin-RevId: 28030561c5d5a8bd53b944981522ceedb45f1e0e
2019-11-21 03:44:39 +00:00

74 lines
1.4 KiB
Java

class EscapeAnalysis {
void testSimple() {
int[] x = new int[] {0};
sideEffect();
if(<warning descr="Condition 'x[0] == 1' is always 'false'">x[0] == 1</warning>) {
System.out.println("Impossible");
}
}
void testEscaped() {
int[] x = new int[] {0};
sideEffect(x);
if(x[0] == 1) {
System.out.println("Who knows?");
}
}
void testEscapedAfterLoop() {
int[] x;
for (int i = 0; i < 10; i++) {
x = new int[] {0};
sideEffect();
if(<warning descr="Condition 'x[0] == 1' is always 'false'">x[0] == 1</warning>) {
System.out.println("Impossible");
}
sideEffect(x);
if(x[0] == 1) {
System.out.println("Who knows?");
}
}
}
native void sideEffect();
native void sideEffect(int[] array);
void testLambda() {
int[] x = new int[] {0};
Runnable r = () -> x[0] = 1;
r.run();
if(<warning descr="Condition 'x[0] == 1' is always 'true'">x[0] == 1</warning>) {
System.out.println("ok");
}
}
void testLambda2() {
int[] x = new int[] {0};
Runnable r = () -> x[0] = 1;
r.run();
r.run();
if(x[0] == 1) {
System.out.println("ok");
}
}
class X {
X() {run();}
void run() {};
}
void testClass() {
int[] x = new int[] {0};
new X() {
void run() {
x[0] = Math.random() > 0.5 ? 1 : 0;
}
};
if(x[0] == 1) {
System.out.println("possible");
}
}
}