[java-highlighting] IDEA-216255 Provide fix for the "Foo is not a functional interface" error and the like

GitOrigin-RevId: 9658873f49ff547a4f9c424e87a202e3546e0993
This commit is contained in:
Andrey.Cherkasov
2021-03-03 19:25:14 +03:00
committed by intellij-monorepo-bot
parent a82219bc5a
commit 3753fdc967
8 changed files with 39 additions and 2 deletions

View File

@@ -595,14 +595,19 @@ public final class AnnotationsHighlightUtil {
if (parent instanceof PsiClass) {
final String errorMessage = LambdaHighlightingUtil.checkInterfaceFunctional((PsiClass)parent, JavaErrorBundle.message("not.a.functional.interface", ((PsiClass)parent).getName()));
if (errorMessage != null) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(annotation).descriptionAndTooltip(errorMessage).create();
HighlightInfo info =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(annotation).descriptionAndTooltip(errorMessage).create();
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createDeleteFix(annotation));
return info;
}
if (((PsiClass)parent).hasModifierProperty(PsiModifier.SEALED)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(annotation)
.descriptionAndTooltip(JavaErrorBundle.message("functional.interface.must.not.be.sealed.error.description", PsiModifier.SEALED))
.create();
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createDeleteFix(annotation));
return info;
}
}
}

View File

@@ -0,0 +1,5 @@
// "Remove annotation" "true"
interface Test {
void foo();
void bar();
}

View File

@@ -0,0 +1,2 @@
// "Remove annotation" "true"
public interface Test {}

View File

@@ -0,0 +1,6 @@
// "Remove annotation" "true"
@FunctionalInterface<caret>
interface Test {
void foo();
void bar();
}

View File

@@ -0,0 +1,3 @@
// "Remove annotation" "true"
@FunctionalInterface<caret>
public interface Test {}

View File

@@ -0,0 +1,3 @@
// "Remove annotation" "true"
@FunctionalInterface<caret>
class Test {}

View File

@@ -0,0 +1,11 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
public class RemoveFunctionalInterfaceAnnotationTest extends LightQuickFixParameterizedTestCase {
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/removeFunctionalInterfaceAnnotation";
}
}