mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
invalid @FunctionalInterface severity change warning -> error (IDEA-120162)
This commit is contained in:
+1
-1
@@ -579,7 +579,7 @@ public class AnnotationsHighlightUtil {
|
||||
public static HighlightInfo checkFunctionalInterface(@NotNull PsiAnnotation annotation, @NotNull LanguageLevel languageLevel) {
|
||||
final String errorMessage = LambdaUtil.checkFunctionalInterface(annotation, languageLevel);
|
||||
if (errorMessage != null) {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.WARNING).range(annotation).descriptionAndTooltip(errorMessage).create();
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(annotation).descriptionAndTooltip(errorMessage).create();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ public class LambdaHighlightingUtil {
|
||||
if (signatures == null) return interfaceNonFunctionalMessage;
|
||||
if (signatures.isEmpty()) return "No target method found";
|
||||
if (signatures.size() == 1) {
|
||||
final MethodSignature functionalMethod = signatures.get(0);
|
||||
if (functionalMethod.getTypeParameters().length > 0) return "Target method is generic";
|
||||
return null;
|
||||
}
|
||||
return "Multiple non-overriding abstract methods found";
|
||||
@@ -106,6 +104,12 @@ public class LambdaHighlightingUtil {
|
||||
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(GenericsUtil.eliminateWildcards(functionalInterfaceType));
|
||||
final PsiClass aClass = resolveResult.getElement();
|
||||
if (aClass != null) {
|
||||
if (aClass instanceof PsiTypeParameter) return null; //should be logged as cyclic inference
|
||||
final List<MethodSignature> signatures = LambdaUtil.findFunctionCandidates(aClass);
|
||||
if (signatures != null && signatures.size() == 1) {
|
||||
final MethodSignature functionalMethod = signatures.get(0);
|
||||
if (functionalMethod.getTypeParameters().length > 0) return "Target method is generic";
|
||||
}
|
||||
if (checkReturnTypeApplicable(resolveResult, aClass)) {
|
||||
return "No instance of type " + functionalInterfaceType.getPresentableText() + " exists so that lambda expression can be type-checked";
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
<warning descr="Multiple non-overriding abstract methods found">@FunctionalInterface</warning>
|
||||
<error descr="Multiple non-overriding abstract methods found">@FunctionalInterface</error>
|
||||
interface Test {
|
||||
void foo();
|
||||
void bar();
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class FunctionalInterfaceTest extends LightDaemonAnalyzerTestCase {
|
||||
final PsiClass psiClass = getJavaFacade().findClass("Foo", GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull("Class Foo not found", psiClass);
|
||||
|
||||
final String errorMessage = LambdaHighlightingUtil.checkInterfaceFunctional(psiClass);
|
||||
final String errorMessage = LambdaHighlightingUtil.checkInterfaceFunctional(getJavaFacade().getElementFactory().createType(psiClass));
|
||||
assertEquals(expectedErrorMessage, errorMessage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user