mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
abstract overrides abstract: ignore if also overrides default and resolves ambiguity (IDEA-140376)
This commit is contained in:
+9
-3
@@ -115,22 +115,28 @@ public class AbstractMethodOverridesAbstractMethodInspection extends BaseInspect
|
||||
if (!method.hasModifierProperty(PsiModifier.ABSTRACT) && !containingClass.isInterface()) {
|
||||
return;
|
||||
}
|
||||
boolean overrideDefault = false;
|
||||
boolean accept = false;
|
||||
final PsiMethod[] superMethods = method.findSuperMethods();
|
||||
for (final PsiMethod superMethod : superMethods) {
|
||||
overrideDefault |= superMethod.hasModifierProperty(PsiModifier.DEFAULT);
|
||||
if (!isAbstract(superMethod)) {
|
||||
continue;
|
||||
}
|
||||
if (!methodsHaveSameReturnTypes(method, superMethod) || !haveSameExceptionSignatures(method, superMethod)) {
|
||||
continue;
|
||||
if (overrideDefault) {
|
||||
return;
|
||||
}
|
||||
accept |= methodsHaveSameReturnTypes(method, superMethod) && haveSameExceptionSignatures(method, superMethod);
|
||||
|
||||
if (ignoreJavaDoc && !haveSameJavaDoc(method, superMethod)) {
|
||||
return;
|
||||
}
|
||||
if (ignoreAnnotations && !methodsHaveSameAnnotations(method, superMethod)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (accept && !overrideDefault) {
|
||||
registerMethodError(method);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
@@ -62,6 +62,23 @@ class SuperclassSubst {
|
||||
}
|
||||
|
||||
class Java8DefaultMethods {
|
||||
|
||||
interface A {
|
||||
String method();
|
||||
}
|
||||
|
||||
interface B {
|
||||
default String method() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//without override would inherit abstract & default - red code
|
||||
interface C extends A, B {
|
||||
@Override
|
||||
String method();
|
||||
}
|
||||
|
||||
interface Super
|
||||
{
|
||||
default void method()
|
||||
|
||||
+11
@@ -1,5 +1,9 @@
|
||||
package com.siyeh.ig.inheritance;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
|
||||
public class AbstractMethodOverridesAbstractMethodInspectionTest extends IGInspectionTestCase {
|
||||
@@ -10,4 +14,11 @@ public class AbstractMethodOverridesAbstractMethodInspectionTest extends IGInspe
|
||||
tool.ignoreJavaDoc = true;
|
||||
doTest("com/siyeh/igtest/inheritance/abstract_method_overrides_abstract_method", tool);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getTestProjectSdk() {
|
||||
Sdk sdk = IdeaTestUtil.getMockJdk17();
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.HIGHEST);
|
||||
return sdk;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user