mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
jdk9: support private methods in interfaces (IDEA-137918)
This commit is contained in:
+2
-1
@@ -1040,6 +1040,7 @@ public class HighlightMethodUtil {
|
||||
boolean isInterface = aClass != null && aClass.isInterface();
|
||||
boolean isExtension = method.hasModifierProperty(PsiModifier.DEFAULT);
|
||||
boolean isStatic = method.hasModifierProperty(PsiModifier.STATIC);
|
||||
boolean isPrivate = method.hasModifierProperty(PsiModifier.PRIVATE);
|
||||
|
||||
final List<IntentionAction> additionalFixes = new ArrayList<IntentionAction>();
|
||||
String description = null;
|
||||
@@ -1053,7 +1054,7 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
}
|
||||
else if (isInterface) {
|
||||
if (!isExtension && !isStatic) {
|
||||
if (!isExtension && !isStatic && !isPrivate) {
|
||||
description = JavaErrorMessages.message("interface.methods.cannot.have.body");
|
||||
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.DEFAULT, true, false));
|
||||
|
||||
+6
-1
@@ -154,12 +154,16 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
Set<String> incompatibles = incompatibleModifiersHash.get(modifier);
|
||||
if (incompatibles == null) return null;
|
||||
final boolean level8OrHigher = PsiUtil.isLanguageLevel8OrHigher(modifierList);
|
||||
final boolean level9OrHigher = PsiUtil.isLanguageLevel9OrHigher(modifierList);
|
||||
for (@PsiModifier.ModifierConstant String incompatible : incompatibles) {
|
||||
if (level8OrHigher) {
|
||||
if (modifier.equals(PsiModifier.STATIC) && incompatible.equals(PsiModifier.ABSTRACT)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (level9OrHigher && modifier.equals(PsiModifier.PRIVATE) && incompatible.equals(PsiModifier.PUBLIC)) {
|
||||
continue;
|
||||
}
|
||||
if (modifier.equals(PsiModifier.STATIC) && incompatible.equals(PsiModifier.FINAL)) {
|
||||
final PsiElement parent = modifierList.getParent();
|
||||
if (parent instanceof PsiMethod) {
|
||||
@@ -883,7 +887,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
|
||||
if (PsiModifier.PRIVATE.equals(modifier) || PsiModifier.PROTECTED.equals(modifier) || PsiModifier.TRANSIENT.equals(modifier) ||
|
||||
PsiModifier.STRICTFP.equals(modifier) || PsiModifier.SYNCHRONIZED.equals(modifier)) {
|
||||
isAllowed &= modifierOwnerParent instanceof PsiClass && !((PsiClass)modifierOwnerParent).isInterface();
|
||||
isAllowed &= modifierOwnerParent instanceof PsiClass &&
|
||||
(!((PsiClass)modifierOwnerParent).isInterface() || PsiUtil.isLanguageLevel9OrHigher(modifierOwner));
|
||||
}
|
||||
|
||||
if (containingClass != null && containingClass.isAnnotationType()) {
|
||||
|
||||
@@ -889,6 +889,10 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
return getLanguageLevel(element).isAtLeast(LanguageLevel.JDK_1_8);
|
||||
}
|
||||
|
||||
public static boolean isLanguageLevel9OrHigher(@NotNull final PsiElement element) {
|
||||
return getLanguageLevel(element).isAtLeast(LanguageLevel.JDK_1_9);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LanguageLevel getLanguageLevel(@NotNull PsiElement element) {
|
||||
if (element instanceof PsiDirectory) {
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
interface A {
|
||||
private void m() {}
|
||||
}
|
||||
+1
@@ -53,4 +53,5 @@ public class LightAdvHighlightingJdk9Test extends LightDaemonAnalyzerTestCase {
|
||||
}
|
||||
|
||||
public void testSafeVarargsApplicability() { doTest(true, false); }
|
||||
public void testPrivateInInterfaces() { doTest(false, false); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user