private modifier in interfaces: check for modifier combinations, body (IDEA-164596)

This commit is contained in:
Anna.Kozlova
2016-11-28 15:38:48 +01:00
parent ae6793de43
commit d4a9f70ca8
3 changed files with 20 additions and 3 deletions
@@ -1134,8 +1134,13 @@ public class HighlightMethodUtil {
description = JavaErrorMessages.message("extension.method.should.have.a.body");
additionalFixes.add(QUICK_FIX_FACTORY.createAddMethodBodyFix(method));
}
else if (isInterface && isStatic && languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
description = "Static methods in interfaces should have a body";
else if (isInterface) {
if (isStatic && languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
description = "Static methods in interfaces should have a body";
}
else if (isPrivate && languageLevel.isAtLeast(LanguageLevel.JDK_1_9)) {
description = "Private methods in interfaces should have a body";
}
}
}
else if (isInterface) {
@@ -123,7 +123,7 @@ public class HighlightUtil extends HighlightUtilBase {
ourMethodIncompatibleModifiers.put(PsiModifier.PUBLIC, ContainerUtil.newTroveSet(PsiModifier.PACKAGE_LOCAL, PsiModifier.PRIVATE, PsiModifier.PROTECTED));
ourMethodIncompatibleModifiers.put(PsiModifier.PROTECTED, ContainerUtil.newTroveSet(PsiModifier.PACKAGE_LOCAL, PsiModifier.PUBLIC, PsiModifier.PRIVATE));
ourMethodIncompatibleModifiers.put(PsiModifier.STATIC, ContainerUtil.newTroveSet(PsiModifier.ABSTRACT, PsiModifier.DEFAULT, PsiModifier.FINAL));
ourMethodIncompatibleModifiers.put(PsiModifier.DEFAULT, ContainerUtil.newTroveSet(PsiModifier.ABSTRACT, PsiModifier.STATIC, PsiModifier.FINAL));
ourMethodIncompatibleModifiers.put(PsiModifier.DEFAULT, ContainerUtil.newTroveSet(PsiModifier.ABSTRACT, PsiModifier.STATIC, PsiModifier.FINAL, PsiModifier.PRIVATE));
ourMethodIncompatibleModifiers.put(PsiModifier.SYNCHRONIZED, ContainerUtil.newTroveSet(PsiModifier.ABSTRACT));
ourMethodIncompatibleModifiers.put(PsiModifier.STRICTFP, ContainerUtil.newTroveSet(PsiModifier.ABSTRACT));
ourMethodIncompatibleModifiers.put(PsiModifier.FINAL, ContainerUtil.newTroveSet(PsiModifier.ABSTRACT));
@@ -1,3 +1,15 @@
interface A {
private void m() {}
}
interface B {
<error descr="Private methods in interfaces should have a body">private void m()</error>;
}
interface C {
private <error descr="Illegal combination of modifiers: 'default' and 'private'">default</error> void m() {}
}
interface D {
private static void m() {}
}