IDEA-162574 False positive 'Lambda can be replaced with method reference'

This commit is contained in:
Tagir Valeev
2016-10-18 12:53:15 +07:00
parent d807cd3b24
commit ee1bd69c2e
5 changed files with 35 additions and 2 deletions

View File

@@ -298,8 +298,9 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
return null;
}
PsiType type = typeElement.getType();
if (type instanceof PsiPrimitiveType)
return null;
if (type instanceof PsiPrimitiveType) return null;
type = type.getDeepComponentType();
if (type instanceof PsiClassType && (((PsiClassType)type).resolve() instanceof PsiTypeParameter)) return null;
return expression;
}
}

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, int[]> fn = int[].class::cast;
}
}

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, int[]> fn = s -> (int[])<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 <T> test(Object obj) {
Function<Object, T> fn = s -> (T)<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 <T> test(Object obj) {
Function<Object, T[]> fn = s -> (T[])<caret>s;
}
}