IDEA-123839: abstract&default combination

This commit is contained in:
Anna Kozlova
2014-04-11 17:02:36 +02:00
parent 75f267c222
commit 0d66941866
4 changed files with 20 additions and 6 deletions

View File

@@ -424,17 +424,17 @@ public class GenericsHighlightUtil {
@NotNull PsiIdentifier classIdentifier) {
for (HierarchicalMethodSignature methodSignature : signaturesWithSupers) {
final PsiMethod method = methodSignature.getMethod();
if (method.hasModifierProperty(PsiModifier.DEFAULT)) {
final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
if (method.hasModifierProperty(PsiModifier.DEFAULT) || isAbstract) {
final PsiClass containingClass = method.getContainingClass();
List<HierarchicalMethodSignature> superSignatures = methodSignature.getSuperSignatures();
if (!superSignatures.isEmpty()) {
for (HierarchicalMethodSignature signature : superSignatures) {
final PsiMethod superMethod = signature.getMethod();
final PsiClass superContainingClass = superMethod.getContainingClass();
if (containingClass != null && superContainingClass != null && !InheritanceUtil
.isInheritorOrSelf(containingClass, superContainingClass, true)) {
if (containingClass != null && superContainingClass != null && !InheritanceUtil.isInheritorOrSelf(containingClass, superContainingClass, true)) {
final boolean isDefault = superMethod.hasModifierProperty(PsiModifier.DEFAULT);
if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT) && !isDefault) {
if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT) && !isDefault && !isAbstract) {
final String message = JavaErrorMessages.message(
aClass instanceof PsiEnumConstantInitializer ? "enum.constant.should.implement.method" : "class.must.be.abstract",
HighlightUtil.formatClass(superContainingClass),
@@ -445,7 +445,7 @@ public class GenericsHighlightUtil {
.create();
}
if (isDefault || superMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
if (isDefault || !isAbstract && superMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
final String message = isDefault
? " inherits unrelated defaults for "
: " inherits abstract and default for ";

View File

@@ -0,0 +1,13 @@
import java.util.Iterator;
interface A4 {
default Iterator iterator() {
return null;
}
}
interface A5 {
Iterator iterator();
}
abstract class <error descr="B inherits unrelated defaults for iterator() from types A5 and A4">B</error> implements A5, A4 {}

View File

@@ -12,7 +12,7 @@ interface SecondParent {
class <error descr="Class 'SecondParent' must either be declared abstract or implement abstract method 'doSomething()' in 'SecondParent'">FirstSon</error> implements FirstParent, SecondParent {}
<error descr="Class 'SecondSon' must either be declared abstract or implement abstract method 'doSomething()' in 'SecondParent'">class SecondSon implements SecondParent, FirstParent</error> {}
<error descr="Class 'SecondSon' must either be declared abstract or implement abstract method 'doSomething()' in 'SecondParent'">class <error descr="SecondSon inherits unrelated defaults for doSomething() from types SecondParent and FirstParent">SecondSon</error> implements SecondParent, FirstParent</error> {}
interface A {
default int foo() {

View File

@@ -38,6 +38,7 @@ public class Interface8MethodsHighlightingTest extends LightCodeInsightFixtureTe
public void testStaticMethods() { doTest(false, false); }
public void testFinalStaticDefaultMethods() { doTest(false, false); }
public void testIDEA122720() { doTest(false, false); }
public void testIDEA123839() { doTest(false, false); }
public void testDefaultSupersInStaticContext() {
doTest(false, false);
}