TrivialFunctionalExpressionUsage bugfixes & refactoring

Fixes IDEA-176019 Trivial functional expression: do not inline if parameter produces side effect and evaluated not once
Fixes EA-103938 (invalid PSI was used if inlining replaced the whole method)
Fixes inlining of functional expression
This commit is contained in:
Tagir Valeev
2017-07-18 17:39:34 +07:00
parent 86977a23ec
commit 5c33eecb2e
8 changed files with 205 additions and 69 deletions
@@ -0,0 +1,10 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Consumer;
import java.util.function.Predicate;
public class Main {
void test() {
((Predicate<String>) String::isEmpty).test("abc");
}
}
@@ -0,0 +1,12 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.IntBinaryOperator;
public class Main {
void test() {
int z = 0;
int x = z += 2;
z += 3;
int res = x;
}
}
@@ -0,0 +1,9 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.IntBinaryOperator;
public class Main {
void test() {
int res = 5;
}
}
@@ -0,0 +1,10 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Consumer;
import java.util.function.Predicate;
public class Main {
void test() {
((Consumer<Predicate<String>>) (x -> x.test("abc"))).ac<caret>cept(String::isEmpty);
}
}
@@ -0,0 +1,9 @@
// "Replace method call on lambda with lambda body" "false"
import java.util.function.IntUnaryOperator;
public class Main {
void test() {
((IntUnaryOperator)x -> x+=5).app<caret>lyAsInt(10);
}
}
@@ -0,0 +1,10 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.IntBinaryOperator;
public class Main {
void test() {
int z = 0;
int res = ((IntBinaryOperator)(x, y) -> x).applyAs<caret>Int(z+=2, z+=3);
}
}
@@ -0,0 +1,9 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.IntBinaryOperator;
public class Main {
void test() {
int res = ((IntBinaryOperator)(x, y) -> x).appl<caret>yAsInt(5, 6);
}
}