mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
get rid of Java15CompletionData and Java18CompletionData
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.filters.*;
|
||||
import com.intellij.psi.filters.position.LeftNeighbour;
|
||||
import com.intellij.psi.filters.position.SuperParentFilter;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class Java15CompletionData extends JavaCompletionData {
|
||||
|
||||
@Override
|
||||
protected void initVariantsInFileScope() {
|
||||
super.initVariantsInFileScope();
|
||||
//static keyword in static import
|
||||
{
|
||||
final CompletionVariant variant = new CompletionVariant(PsiImportList.class, new LeftNeighbour(new TextFilter (PsiKeyword.IMPORT)));
|
||||
variant.addCompletion(PsiKeyword.STATIC, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
|
||||
registerVariant(variant);
|
||||
}
|
||||
|
||||
{
|
||||
final ElementFilter position = new AndFilter(new LeftNeighbour(new TextFilter("@")),
|
||||
new NotFilter(new SuperParentFilter(
|
||||
new OrFilter(new ClassFilter(PsiNameValuePair.class),
|
||||
new ClassFilter(PsiParameterList.class))))
|
||||
);
|
||||
|
||||
final CompletionVariant variant = new CompletionVariant(PsiJavaFile.class, position);
|
||||
variant.includeScopeClass(PsiClass.class);
|
||||
|
||||
variant.addCompletion(PsiKeyword.INTERFACE, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
|
||||
registerVariant(variant);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.LambdaHighlightingUtil;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.patterns.PsiElementPattern;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiElement;
|
||||
|
||||
public class Java18CompletionData extends Java15CompletionData {
|
||||
private static final PsiElementPattern<PsiElement, ?> AFTER_DOUBLE_COLON = psiElement()
|
||||
.afterLeaf(psiElement(JavaTokenType.DOUBLE_COLON));
|
||||
|
||||
@Override
|
||||
public void fillCompletions(final CompletionParameters parameters, final Consumer<LookupElement> result) {
|
||||
PsiElement position = parameters.getPosition();
|
||||
|
||||
if (!inComment(position)) {
|
||||
if (AFTER_DOUBLE_COLON.accepts(position)) {
|
||||
PsiMethodReferenceExpression parent = PsiTreeUtil.getParentOfType(parameters.getPosition(), PsiMethodReferenceExpression.class);
|
||||
TailType tail = parent != null && !LambdaHighlightingUtil.insertSemicolon(parent.getParent()) ? TailType.SEMICOLON : TailType.NONE;
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.NEW), tail));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSuitableForClass(position)) {
|
||||
PsiElement scope = position.getParent();
|
||||
while (scope != null && !(scope instanceof PsiFile)) {
|
||||
if (scope instanceof PsiClass && ((PsiClass)scope).isInterface()) {
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.DEFAULT), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
break;
|
||||
}
|
||||
scope = scope.getParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.fillCompletions(parameters, result);
|
||||
}
|
||||
|
||||
private static boolean inComment(final PsiElement position) {
|
||||
return PsiTreeUtil.getParentOfType(position, PsiComment.class, false) != null;
|
||||
}
|
||||
}
|
||||
+3
-16
@@ -71,26 +71,13 @@ import static com.intellij.util.ObjectUtils.assertNotNull;
|
||||
public class JavaCompletionContributor extends CompletionContributor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.JavaCompletionContributor");
|
||||
|
||||
private static final Map<LanguageLevel, JavaCompletionData> ourCompletionData;
|
||||
|
||||
static {
|
||||
ourCompletionData = new LinkedHashMap<LanguageLevel, JavaCompletionData>();
|
||||
ourCompletionData.put(LanguageLevel.JDK_1_8, new Java18CompletionData());
|
||||
ourCompletionData.put(LanguageLevel.JDK_1_5, new Java15CompletionData());
|
||||
ourCompletionData.put(LanguageLevel.JDK_1_3, new JavaCompletionData());
|
||||
}
|
||||
|
||||
public static final ElementPattern<PsiElement> ANNOTATION_NAME = psiElement().
|
||||
withParents(PsiJavaCodeReferenceElement.class, PsiAnnotation.class).afterLeaf("@");
|
||||
private static final PsiJavaElementPattern.Capture<PsiElement> UNEXPECTED_REFERENCE_AFTER_DOT =
|
||||
psiElement().afterLeaf(".").insideStarting(psiExpressionStatement());
|
||||
|
||||
private static JavaCompletionData getCompletionData(LanguageLevel level) {
|
||||
final Set<Map.Entry<LanguageLevel, JavaCompletionData>> entries = ourCompletionData.entrySet();
|
||||
for (Map.Entry<LanguageLevel, JavaCompletionData> entry : entries) {
|
||||
if (entry.getKey().isAtLeast(level)) return entry.getValue();
|
||||
}
|
||||
return ourCompletionData.get(LanguageLevel.JDK_1_3);
|
||||
return new JavaCompletionData();
|
||||
}
|
||||
|
||||
private static final PsiNameValuePairPattern NAME_VALUE_PAIR =
|
||||
@@ -460,10 +447,10 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
PsiElement position = parameters.getPosition();
|
||||
final Set<LookupElement> lookupSet = new LinkedHashSet<LookupElement>();
|
||||
final Set<CompletionVariant> keywordVariants = new HashSet<CompletionVariant>();
|
||||
final JavaCompletionData completionData = getCompletionData(PsiUtil.getLanguageLevel(position));
|
||||
final JavaCompletionData completionData = new JavaCompletionData();
|
||||
completionData.addKeywordVariants(keywordVariants, position, parameters.getOriginalFile());
|
||||
completionData.completeKeywordsBySet(lookupSet, keywordVariants, position, result.getPrefixMatcher(), parameters.getOriginalFile());
|
||||
completionData.fillCompletions(parameters, noMiddleMatches);
|
||||
JavaCompletionData.addKeywords(parameters, noMiddleMatches);
|
||||
|
||||
for (final LookupElement item : lookupSet) {
|
||||
noMiddleMatches.consume(item);
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
import com.intellij.codeInsight.TailType;
|
||||
import com.intellij.codeInsight.TailTypes;
|
||||
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.LambdaHighlightingUtil;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.openapi.util.AtomicNotNullLazyValue;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
@@ -40,6 +41,7 @@ import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.patterns.PsiJavaPatterns.*;
|
||||
import static com.intellij.patterns.StandardPatterns.not;
|
||||
@@ -173,7 +175,6 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
public JavaCompletionData(){
|
||||
declareCompletionSpaces();
|
||||
|
||||
initVariantsInFileScope();
|
||||
initVariantsInClassScope();
|
||||
|
||||
defineScopeEquivalence(PsiMethod.class, PsiClassInitializer.class);
|
||||
@@ -228,9 +229,6 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
declareFinalScope(PsiComment.class);
|
||||
}
|
||||
|
||||
protected void initVariantsInFileScope(){
|
||||
}
|
||||
|
||||
/**
|
||||
* aClass == null for JspDeclaration scope
|
||||
*/
|
||||
@@ -348,7 +346,7 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
|
||||
}
|
||||
|
||||
public void fillCompletions(CompletionParameters parameters, final Consumer<LookupElement> result) {
|
||||
public static void addKeywords(CompletionParameters parameters, final Consumer<LookupElement> result) {
|
||||
final PsiElement position = parameters.getPosition();
|
||||
if (PsiTreeUtil.getNonStrictParentOfType(position, PsiLiteralExpression.class, PsiComment.class) != null) {
|
||||
return;
|
||||
@@ -369,13 +367,13 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
|
||||
addThisSuper(result, position);
|
||||
|
||||
addExpressionKeywords(parameters, result, position);
|
||||
addExpressionKeywords(parameters, result, position, prevLeaf);
|
||||
|
||||
addFileHeaderKeywords(result, position, prevLeaf);
|
||||
|
||||
addInstanceof(result, position);
|
||||
|
||||
addClassKeywords(result, position);
|
||||
addClassKeywords(result, position, prevLeaf);
|
||||
|
||||
addMethodHeaderKeywords(result, position, prevLeaf);
|
||||
|
||||
@@ -462,7 +460,14 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addExpressionKeywords(CompletionParameters parameters, Consumer<LookupElement> result, PsiElement position) {
|
||||
private static void addExpressionKeywords(CompletionParameters parameters, Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf) {
|
||||
if (psiElement(JavaTokenType.DOUBLE_COLON).accepts(prevLeaf)) {
|
||||
PsiMethodReferenceExpression parent = PsiTreeUtil.getParentOfType(parameters.getPosition(), PsiMethodReferenceExpression.class);
|
||||
TailType tail = parent != null && !LambdaHighlightingUtil.insertSemicolon(parent.getParent()) ? TailType.SEMICOLON : TailType.NONE;
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.NEW), tail));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isExpressionPosition(position)) {
|
||||
if (PsiTreeUtil.getParentOfType(position, PsiAnnotation.class) == null) {
|
||||
result.consume(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.NEW), TailType.INSERT_SPACE));
|
||||
@@ -488,6 +493,10 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.IMPORT), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
|
||||
if (PsiUtil.isLanguageLevel5OrHigher(position) && prevLeaf != null && prevLeaf.textMatches(PsiKeyword.IMPORT)) {
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.STATIC), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
|
||||
private static void addInstanceof(Consumer<LookupElement> result, PsiElement position) {
|
||||
@@ -518,19 +527,31 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addClassKeywords(Consumer<LookupElement> result, PsiElement position) {
|
||||
private static void addClassKeywords(Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf) {
|
||||
if (isSuitableForClass(position)) {
|
||||
for (String s : ModifierChooser.getKeywords(position)) {
|
||||
result.consume(new OverrideableSpace(createKeyword(position, s), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(position)) {
|
||||
PsiClass containingClass = PsiTreeUtil.getParentOfType(position, PsiClass.class);
|
||||
if (containingClass != null && containingClass.isInterface()) {
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.DEFAULT), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.CLASS), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
if (PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class, true, PsiMember.class) == null) {
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.INTERFACE), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
if (PsiUtil.getLanguageLevel(position).isAtLeast(LanguageLevel.JDK_1_5)) {
|
||||
if (PsiUtil.isLanguageLevel5OrHigher(position)) {
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.ENUM), TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (psiElement().withText("@").andNot(psiElement().inside(PsiParameterList.class)).andNot(psiElement().inside(psiNameValuePair()))
|
||||
.accepts(prevLeaf)) {
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.INTERFACE), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
|
||||
private static void addClassLiteral(Consumer<LookupElement> result, PsiElement position) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
import <caret>
|
||||
+2
-1
@@ -101,7 +101,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
|
||||
public void testDefaultInAnno() throws Exception { doTest(false); }
|
||||
public void testNullInMethodCall() throws Exception { doTest(false); }
|
||||
public void testNullInMethodCall2() throws Exception { doTest(false); }
|
||||
public void testNewInMethodRefs() throws Exception { doTest(1, "new"); }
|
||||
public void testNewInMethodRefs() throws Exception { doTest(1, "new", "null", "true", "false"); }
|
||||
public void testSpaceAfterInstanceof() throws Exception { doTest(false); }
|
||||
public void testInstanceofAfterUnresolved() throws Exception { doTest(1, "instanceof"); }
|
||||
public void testInstanceofAfterStatementStart() throws Exception { doTest(1, "instanceof"); }
|
||||
@@ -112,6 +112,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(true) + "_after.java");
|
||||
}
|
||||
|
||||
public void testImportStatic() throws Exception { doTest(1, "static"); }
|
||||
public void testAbstractInInterface() throws Exception { doTest(1, "abstract"); }
|
||||
public void testCharInAnnotatedParameter() throws Exception { doTest(1, "char"); }
|
||||
public void testReturnInTernary() throws Exception { doTest(1, "return"); }
|
||||
|
||||
Reference in New Issue
Block a user