diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/ModifierChooser.java b/java/java-impl/src/com/intellij/codeInsight/completion/ModifierChooser.java index 54f514c4a5c6..3563758064f4 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/ModifierChooser.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/ModifierChooser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import com.intellij.psi.filters.FilterPositionUtil; import com.intellij.psi.impl.source.jsp.jspJava.JspClassLevelDeclarationStatement; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.psi.util.PsiUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -47,12 +48,24 @@ public class ModifierChooser { {PsiKeyword.VOLATILE}, {PsiKeyword.TRANSIENT} }; - private static final String[][] INTERFACE_MEMBER_MODIFIERS = { + + private static final String[][] INTERFACE_9_MEMBER_MODIFIERS = { + {PsiKeyword.PUBLIC, PsiKeyword.PROTECTED, PsiKeyword.PRIVATE}, + {PsiKeyword.STATIC}, + {PsiKeyword.FINAL, PsiKeyword.ABSTRACT} + }; + + private static final String[][] INTERFACE_8_MEMBER_MODIFIERS = { {PsiKeyword.PUBLIC, PsiKeyword.PROTECTED}, {PsiKeyword.STATIC}, {PsiKeyword.FINAL, PsiKeyword.ABSTRACT} }; + private static final String[][] INTERFACE_MEMBER_MODIFIERS = { + {PsiKeyword.PUBLIC, PsiKeyword.PROTECTED}, + {PsiKeyword.FINAL, PsiKeyword.ABSTRACT} + }; + static String[] getKeywords(@NotNull PsiElement position) { final PsiModifierList list = findModifierList(position); if (list == null && !shouldSuggestModifiers(position)) { @@ -65,7 +78,7 @@ public class ModifierChooser { return addClassModifiers(list); } if (scope instanceof PsiClass) { - return addMemberModifiers(list, ((PsiClass)scope).isInterface()); + return addMemberModifiers(list, ((PsiClass)scope).isInterface(), scope); } scope = scope.getParent(); @@ -78,8 +91,18 @@ public class ModifierChooser { return addKeywords(list, CLASS_MODIFIERS); } - public static String[] addMemberModifiers(PsiModifierList list, final boolean inInterface) { - return addKeywords(list, inInterface ? INTERFACE_MEMBER_MODIFIERS : CLASS_MEMBER_MODIFIERS); + public static String[] addMemberModifiers(PsiModifierList list, final boolean inInterface, @NotNull PsiElement position) { + return addKeywords(list, inInterface ? getInterfaceMemberModifiers(position) : CLASS_MEMBER_MODIFIERS); + } + + private static String[][] getInterfaceMemberModifiers(@NotNull PsiElement list) { + if (PsiUtil.isLanguageLevel9OrHigher(list)) { + return INTERFACE_9_MEMBER_MODIFIERS; + } + if (PsiUtil.isLanguageLevel8OrHigher(list)) { + return INTERFACE_8_MEMBER_MODIFIERS; + } + return INTERFACE_MEMBER_MODIFIERS; } private static String[] addKeywords(PsiModifierList list, String[][] keywordSets) { diff --git a/java/java-tests/testData/codeInsight/completion/keywords/privateInJava9Interface.java b/java/java-tests/testData/codeInsight/completion/keywords/privateInJava9Interface.java new file mode 100644 index 000000000000..90b795457a0e --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/keywords/privateInJava9Interface.java @@ -0,0 +1,3 @@ +interface A { + pri +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/keywords/privateInJava9Interface_after.java b/java/java-tests/testData/codeInsight/completion/keywords/privateInJava9Interface_after.java new file mode 100644 index 000000000000..a8917bcbd9c5 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/keywords/privateInJava9Interface_after.java @@ -0,0 +1,3 @@ +interface A { + private +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java index 9eb6d550ec6e..abf41922cf82 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/KeywordCompletionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ package com.intellij.codeInsight.completion; import com.intellij.JavaTestUtil; import com.intellij.lang.java.JavaLanguage; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -140,6 +142,18 @@ public class KeywordCompletionTest extends LightCompletionTestCase { public void testIntInGenerics2() throws Throwable { doTest(2, "int", "char", "final"); } public void testBreakInLabeledBlock() { doTest(1, "break label", "continue"); } + public void testPrivateInJava9Interface() throws Exception { + LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject()); + LanguageLevel oldLevel = levelProjectExtension.getLanguageLevel(); + try { + levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_9); + doTest(false); + } + finally { + levelProjectExtension.setLanguageLevel(oldLevel); + } + } + public void testTryInExpression() throws Exception { configureByFile(BASE_PATH + "/" + getTestName(true) + ".java"); assertEquals("toString", myItems[0].getLookupString()); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 103e78e0161e..1ddffb87f647 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -217,7 +217,7 @@ public class GroovyCompletionData { public static void addModifiers(PsiElement position, CompletionResultSet result) { PsiClass scope = PsiTreeUtil.getParentOfType(position, PsiClass.class); PsiModifierList modifierList = ModifierChooser.findModifierList(position); - addKeywords(result, true, ModifierChooser.addMemberModifiers(modifierList, scope != null && scope.isInterface())); + addKeywords(result, true, ModifierChooser.addMemberModifiers(modifierList, scope != null && scope.isInterface(), position)); } private static void addTypeDefinitionKeywords(CompletionResultSet result, PsiElement position) {