IDEA-160898 Inspection to convert several commonly-used lambdas to method references

This commit is contained in:
Tagir Valeev
2016-09-08 12:23:37 +07:00
parent f0c23baa29
commit 8015562c2d
25 changed files with 232 additions and 47 deletions

View File

@@ -0,0 +1,8 @@
// "Replace lambda with method reference" "true"
import java.util.function.Function;
class Bar extends Random {
public void test(Object obj) {
Function<Object, String> fn = String.class::cast;
}
}

View File

@@ -0,0 +1,8 @@
// "Replace lambda with method reference" "true"
import java.util.function.Predicate;
class Bar extends Random {
public void test(Object obj) {
Predicate<Object> pred = String.class::isInstance;
}
}

View File

@@ -0,0 +1,9 @@
// "Replace lambda with method reference" "true"
import java.util.Objects;
import java.util.function.Predicate;
class Bar extends Random {
public void test(Object obj) {
Predicate<Object> pred = Objects::nonNull;
}
}

View File

@@ -0,0 +1,8 @@
// "Replace lambda with method reference" "true"
import java.util.function.Function;
class Bar extends Random {
public void test(Object obj) {
Function<Object, String> fn = s -> (String)<caret>s;
}
}

View File

@@ -0,0 +1,8 @@
// "Replace lambda with method reference" "false"
import java.util.function.Function;
class Bar extends Random {
public void test(Object obj) {
Function<Object, List<String>> fn = s -> (List<String>)<caret>s;
}
}

View File

@@ -0,0 +1,8 @@
// "Replace lambda with method reference" "false"
import java.util.function.ToIntFunction;
class Bar extends Random {
public void test(Object obj) {
ToIntFunction<Object> fn = s -> (int)<caret>s;
}
}

View File

@@ -0,0 +1,8 @@
// "Replace lambda with method reference" "true"
import java.util.function.Predicate;
class Bar extends Random {
public void test(Object obj) {
Predicate<Object> pred = s -> s instanceof <caret>String;
}
}

View File

@@ -0,0 +1,8 @@
// "Replace lambda with method reference" "true"
import java.util.function.Predicate;
class Bar extends Random {
public void test(Object obj) {
Predicate<Object> pred = s -> s != <caret>null;
}
}

View File

@@ -0,0 +1,8 @@
// "Replace lambda with method reference" "false"
import java.util.function.Predicate;
class Bar extends Random {
public void test(Object obj) {
Predicate<Object> pred = s -> obj != <caret>null;
}
}