IDEA-115789 an interface inheriting a default method and an abstract method

This commit is contained in:
anna
2013-11-04 15:52:44 +01:00
parent 9ae4eced85
commit 4a725b52b3
2 changed files with 35 additions and 10 deletions

View File

@@ -510,20 +510,32 @@ public class GenericsHighlightUtil {
final PsiClass superContainingClass = superMethod.getContainingClass();
if (containingClass != null && superContainingClass != null && !InheritanceUtil
.isInheritorOrSelf(containingClass, superContainingClass, true)) {
if (superMethod.hasModifierProperty(PsiModifier.DEFAULT)) {
final String inheritUnrelatedDefaultsMessage = HighlightUtil.formatClass(aClass) + " inherits unrelated defaults for " +
JavaHighlightUtil.formatMethod(method) + " from types " + HighlightUtil.formatClass(containingClass) +
" and " + HighlightUtil.formatClass(superContainingClass);
return HighlightInfo
.newHighlightInfo(HighlightInfoType.ERROR).range(classIdentifier).descriptionAndTooltip(inheritUnrelatedDefaultsMessage).create();
}
if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
final boolean isDefault = superMethod.hasModifierProperty(PsiModifier.DEFAULT);
if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT) && !isDefault) {
final String message = JavaErrorMessages.message(
aClass instanceof PsiEnumConstantInitializer ? "enum.constant.should.implement.method" : "class.must.be.abstract",
HighlightUtil.formatClass(superContainingClass),
JavaHighlightUtil.formatMethod(superMethod),
HighlightUtil.formatClass(superContainingClass, false));
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(classIdentifier).descriptionAndTooltip(message).create();
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(classIdentifier).descriptionAndTooltip(message)
.create();
}
if (isDefault || superMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
final String message = isDefault
? " inherits unrelated defaults for "
: " inherits abstract and default for ";
final String inheritUnrelatedDefaultsMessage = HighlightUtil.formatClass(aClass) +
message +
JavaHighlightUtil.formatMethod(method) +
" from types " +
HighlightUtil.formatClass(containingClass) +
" and " +
HighlightUtil.formatClass(superContainingClass);
return HighlightInfo
.newHighlightInfo(HighlightInfoType.ERROR).range(classIdentifier).descriptionAndTooltip(inheritUnrelatedDefaultsMessage)
.create();
}
}
}

View File

@@ -12,4 +12,17 @@ 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 SecondSon implements SecondParent, FirstParent</error> {}
interface A {
default int foo() {
return 1;
}
}
interface B {
abstract int foo();
}
interface <error descr="C inherits abstract and default for foo() from types A and B">C</error> extends A, B {
}