mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java sealed types: functional interface can't be sealed (IDEA-243536)
GitOrigin-RevId: 7660808963e79d51b8d1507927d1095d119bcdb5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
05d909b4ab
commit
2dcab690d5
+9
-1
@@ -565,10 +565,18 @@ public class AnnotationsHighlightUtil {
|
||||
if (owner instanceof PsiModifierList) {
|
||||
final PsiElement parent = ((PsiModifierList)owner).getParent();
|
||||
if (parent instanceof PsiClass) {
|
||||
final String errorMessage = LambdaHighlightingUtil.checkInterfaceFunctional((PsiClass)parent, ((PsiClass)parent).getName() + " is not a functional interface");
|
||||
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();
|
||||
}
|
||||
|
||||
if (HighlightingFeature.SEALED_CLASSES.isSufficient(languageLevel) &&
|
||||
((PsiClass)parent).hasModifierProperty(PsiModifier.SEALED)) {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
|
||||
.range(annotation)
|
||||
.descriptionAndTooltip(JavaErrorBundle.message("functional.interface.must.not.be.sealed.error.description", PsiModifier.SEALED))
|
||||
.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ import com.intellij.psi.util.MethodSignature;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -37,7 +38,7 @@ public class LambdaHighlightingUtil {
|
||||
return checkInterfaceFunctional(psiClass, JavaErrorBundle.message("target.type.of.a.lambda.conversion.must.be.an.interface"));
|
||||
}
|
||||
|
||||
static String checkInterfaceFunctional(@NotNull PsiClass psiClass, @NotNull String interfaceNonFunctionalMessage) {
|
||||
static String checkInterfaceFunctional(@NotNull PsiClass psiClass, @NotNull @Nls String interfaceNonFunctionalMessage) {
|
||||
if (psiClass instanceof PsiTypeParameter) return null; //should be logged as cyclic inference
|
||||
final List<HierarchicalMethodSignature> signatures = LambdaUtil.findFunctionCandidates(psiClass);
|
||||
if (signatures == null) return interfaceNonFunctionalMessage;
|
||||
|
||||
@@ -464,3 +464,4 @@ class.cannot.be.inherited.with.different.arguments={0} cannot be inherited with
|
||||
bad.type.in.switch.expression=Bad type in switch expression: {0} cannot be converted to {1}
|
||||
switch.expression.cannot.be.void=Target type for switch expression cannot be void
|
||||
annotation.on.static.member.qualifying.type.family.name=Move type annotation
|
||||
functional.interface.must.not.be.sealed.error.description=Functional interface can''t be declared as ''{0}''
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<error descr="Functional interface can't be declared as 'sealed'">@FunctionalInterface</error>
|
||||
sealed interface I {
|
||||
void m();
|
||||
}
|
||||
+2
-3
@@ -18,9 +18,8 @@ public class LightSealedTypesHighlightingTest extends LightJavaCodeInsightFixtur
|
||||
return JAVA_15;
|
||||
}
|
||||
|
||||
public void testSealedTypesBasics() {
|
||||
doTest();
|
||||
}
|
||||
public void testSealedTypesBasics() { doTest(); }
|
||||
public void testSealedFunctionalInterface() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
|
||||
Reference in New Issue
Block a user