IDEA-166636 A bunch of bugs in TrivialFunctionalExpressionUsageInspection (Method call can be simplified)

This commit is contained in:
Tagir Valeev
2017-01-16 12:52:08 +07:00
parent c8c81860e0
commit 4aaa6a4cc2
19 changed files with 270 additions and 93 deletions
@@ -0,0 +1,17 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Function;
public class Test {
public static void main(String[] args) {
/* comment1 */
System.out.println(/* output x */"a"+/* who-hoo */ "x");
// comment2
System.out.println("hello");
/*in return */
String s = "foo" + //inline
"bar";
}
}
@@ -0,0 +1,10 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Predicate;
public class Test {
public static void main(String[] args) {
System.out.println("hello");
Collections.singleton("abc").contains("ab");
}
}
@@ -0,0 +1,12 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Supplier;
public class Test {
public static void main(String[] args) {
Supplier<String> s = () -> {
System.out.println("hello");
return "foo";
};
}
}
@@ -0,0 +1,14 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.*;
import java.util.function.*;
public class Test {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
if(list.isEmpty()) {
System.out.println("foo");
list.add("foo");
}
}
}
@@ -2,5 +2,6 @@
import java.util.function.Supplier;
class Test {
String s = "";
// comment
String s = "";
}
@@ -0,0 +1,11 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Function;
public class Test {
public static void main(String[] args) {
/* bar */
/* who-hoo */
String s = "foo";
}
}
@@ -0,0 +1,10 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Function;
public class Test {
public static void main(String[] args) {
/* bar */
String s = ("a" +/* who-hoo */ "x") + "foo";
}
}
@@ -0,0 +1,18 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Function;
public class Test {
public static void main(String[] args) {
String s = ((Function<String, String>) ((x) -> {
/* comment1 */
System.out.println(/* output x */x);
// comment2
System.out.println("hello");
return /*in return */ "foo" + //inline
"bar";
})).<caret>apply("a"+/* who-hoo */ "x");
}
}
@@ -0,0 +1,12 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Predicate;
public class Test {
public static void main(String[] args) {
((Predicate<String>) ((x) -> {
System.out.println("hello");
return Collections.singleton("abc").contains(x);
})).<caret>test("ab");
}
}
@@ -0,0 +1,12 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Supplier;
public class Test {
public static void main(String[] args) {
Supplier<String> s = () -> ((Supplier<String>)() -> {
System.out.println("hello");
return "foo";
}).<caret>get();
}
}
@@ -0,0 +1,15 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.*;
import java.util.function.*;
public class Test {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
if(list.isEmpty())
((Consumer<String>) x -> {
System.out.println(x);
list.add(x);
}).<caret>accept("foo");
}
}
@@ -0,0 +1,14 @@
// "Replace method call on lambda with lambda body" "false"
import java.util.function.Predicate;
public class Test {
public static void main(String[] args) {
((Predicate<String>)((x) -> {
if (x.length() > 0) {
return x.startsWith("a");
}
throw new IllegalArgumentException();
})).<caret>test("ab");
}
}
@@ -0,0 +1,14 @@
// "Replace method call on lambda with lambda body" "false"
import java.util.function.Predicate;
public class Test {
public static void main(String[] args) {
while(((Predicate<String>) ((x) -> {
System.out.println("hello");
return Collections.singleton("abc").contains(x);
})).<caret>test("ab")) {
System.out.println("hello");
}
}
}
@@ -3,6 +3,7 @@ import java.util.function.Supplier;
class Test {
String s = ((Supplier<String>) () -> {
// comment
return "";
}).g<caret>et();
}
@@ -0,0 +1,9 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Function;
public class Test {
public static void main(String[] args) {
String s = ((Function<String, String>)((x) -> /* bar */ "foo")).a<caret>pply("a" +/* who-hoo */ "x");
}
}
@@ -0,0 +1,9 @@
// "Replace method call on lambda with lambda body" "true"
import java.util.function.Function;
public class Test {
public static void main(String[] args) {
String s = ((Function<String, String>)((x) -> /* bar */ x + "foo")).a<caret>pply("a" +/* who-hoo */ "x");
}
}