mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
ensure anonymous is not converted to lambda/method ref if it contains inner classes or class initializers
(cherry picked from commit 32afe318e3bacd714f3e0b49d8f904402b17a9c2)
This commit is contained in:
@@ -20,12 +20,10 @@ import com.intellij.codeInsight.ChangeContextUtil;
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.LambdaHighlightingUtil;
|
||||
import com.intellij.codeInsight.intention.HighPriorityAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
@@ -194,7 +192,10 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
|
||||
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(aClass.getBaseClassType());
|
||||
if (interfaceMethod != null && (acceptParameterizedFunctionTypes || !interfaceMethod.hasTypeParameters())) {
|
||||
final PsiMethod[] methods = aClass.getMethods();
|
||||
if (methods.length == 1 && aClass.getFields().length == 0) {
|
||||
if (methods.length == 1 &&
|
||||
aClass.getFields().length == 0 &&
|
||||
aClass.getInnerClasses().length == 0 &&
|
||||
aClass.getInitializers().length == 0) {
|
||||
final PsiMethod method = methods[0];
|
||||
return method.getBody() != null &&
|
||||
!hasForbiddenRefsInsideBody(method, aClass) &&
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// "Replace with lambda" "false"
|
||||
import java.util.*;
|
||||
class Test2 {
|
||||
|
||||
interface I<X> {
|
||||
X foo(List<X> list);
|
||||
}
|
||||
|
||||
static <T> I<T> bar(I<T> i){return i;}
|
||||
|
||||
{
|
||||
bar(new I<Stri<caret>ng>() {
|
||||
{
|
||||
System.out.println("hi!");
|
||||
}
|
||||
@Override
|
||||
public String foo(List<String> list) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// "Replace with lambda" "false"
|
||||
import java.util.*;
|
||||
class Test2 {
|
||||
|
||||
interface I<X> {
|
||||
X foo(List<X> list);
|
||||
}
|
||||
|
||||
static <T> I<T> bar(I<T> i){return i;}
|
||||
|
||||
{
|
||||
bar(new I<Stri<caret>ng>() {
|
||||
class UF {}
|
||||
@Override
|
||||
public String foo(List<String> list) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package com.intellij.codeInsight.daemon.quickFix;
|
||||
import com.intellij.codeInspection.AnonymousCanBeLambdaInspection;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user