mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
completion for private modifier in java 9 interfaces, hide 'static' from completion in java 6
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
interface A {
|
||||
pri<caret>
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
interface A {
|
||||
private <caret>
|
||||
}
|
||||
+15
-1
@@ -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());
|
||||
|
||||
+2
-2
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user