mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] don't replace lambda with method reference when qualifier is nullable (IDEA-278691)
GitOrigin-RevId: f514b690e9e2d007c124ce2b7179af39b6131f3f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b5a7d78514
commit
4972eabd8b
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace lambda with method reference" "false"
|
||||
class Example {
|
||||
private void m() { }
|
||||
|
||||
{
|
||||
Example e = null;
|
||||
Runnable unusedRunnable = () -> <caret>e.m();
|
||||
}
|
||||
|
||||
interface I {
|
||||
void n(Example e);
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -1,7 +1,9 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.Nullability;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightingFeature;
|
||||
import com.intellij.codeInspection.dataFlow.NullabilityUtil;
|
||||
import com.intellij.openapi.diagnostic.Attachment;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -30,7 +32,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class LambdaCanBeMethodReferenceInspection extends AbstractBaseJavaLocalInspectionTool {
|
||||
private static final Logger LOG = Logger.getInstance(LambdaCanBeMethodReferenceInspection.class);
|
||||
@@ -335,6 +336,10 @@ public class LambdaCanBeMethodReferenceInspection extends AbstractBaseJavaLocalI
|
||||
if (element instanceof PsiField && !((PsiField)element).hasModifierProperty(PsiModifier.FINAL)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (NullabilityUtil.getExpressionNullability((PsiExpression)expression, true) == Nullability.NULLABLE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user