mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda -> method ref: reject anonymous class replacement (IDEA-124748)
This commit is contained in:
+2
-1
@@ -91,6 +91,8 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
PsiType functionalInterfaceType) {
|
||||
PsiCallExpression methodCall = extractMethodCallFromBlock(body);
|
||||
|
||||
if (methodCall instanceof PsiNewExpression && ((PsiNewExpression)methodCall).getAnonymousClass() != null) return null;
|
||||
|
||||
if (methodCall != null) {
|
||||
final PsiExpressionList argumentList = methodCall.getArgumentList();
|
||||
if (argumentList != null) {
|
||||
@@ -102,7 +104,6 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
if (psiMethod == null) {
|
||||
isConstructor = true;
|
||||
if (!(methodCall instanceof PsiNewExpression)) return null;
|
||||
if (((PsiNewExpression)methodCall).getAnonymousClass() != null) return null;
|
||||
final PsiJavaCodeReferenceElement classReference = ((PsiNewExpression)methodCall).getClassOrAnonymousClassReference();
|
||||
if (classReference == null) return null;
|
||||
containingClass = (PsiClass)classReference.resolve();
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace lambda with method reference" "false"
|
||||
class NonStaticInner3 {
|
||||
class Foo {
|
||||
public Foo() {
|
||||
}
|
||||
}
|
||||
|
||||
interface I1<X> {
|
||||
X m();
|
||||
}
|
||||
|
||||
{
|
||||
I1<Foo> b2 = () -> <caret>new Foo(){};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user