mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Suggest "implements" after record header; don't suggest "extends" for records and enums; don't suggest "class" after record header
Part of IDEA-229300 GitOrigin-RevId: 763781d7a37be1d3d5a4e8fd158471820e31372b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7b7c6c9a8e
commit
13d082389a
@@ -86,7 +86,8 @@ public class JavaKeywordCompletion {
|
||||
return PsiTreeUtil.getParentOfType(PsiTreeUtil.prevVisibleLeaf(element), PsiDocComment.class) != null;
|
||||
}
|
||||
|
||||
return !(parent instanceof PsiExpressionList || parent instanceof PsiTypeCastExpression);
|
||||
return !(parent instanceof PsiExpressionList || parent instanceof PsiTypeCastExpression
|
||||
|| parent instanceof PsiRecordHeader);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -579,24 +580,31 @@ public class JavaKeywordCompletion {
|
||||
}
|
||||
|
||||
private void addExtendsImplements() {
|
||||
if (myPrevLeaf == null || !(myPrevLeaf instanceof PsiIdentifier || myPrevLeaf.textMatches(">"))) return;
|
||||
if (myPrevLeaf == null ||
|
||||
!(myPrevLeaf instanceof PsiIdentifier || myPrevLeaf.textMatches(">") || myPrevLeaf.textMatches(")"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiClass psiClass = null;
|
||||
PsiElement prevParent = myPrevLeaf.getParent();
|
||||
if (myPrevLeaf instanceof PsiIdentifier && prevParent instanceof PsiClass) {
|
||||
psiClass = (PsiClass)prevParent;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
PsiReferenceList referenceList = PsiTreeUtil.getParentOfType(myPrevLeaf, PsiReferenceList.class);
|
||||
if (referenceList != null && referenceList.getParent() instanceof PsiClass) {
|
||||
psiClass = (PsiClass)referenceList.getParent();
|
||||
}
|
||||
else if (prevParent instanceof PsiTypeParameterList && prevParent.getParent() instanceof PsiClass) {
|
||||
else if ((prevParent instanceof PsiTypeParameterList || prevParent instanceof PsiRecordHeader)
|
||||
&& prevParent.getParent() instanceof PsiClass) {
|
||||
psiClass = (PsiClass)prevParent.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
if (psiClass != null) {
|
||||
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.EXTENDS), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
if (!psiClass.isEnum() && !psiClass.isRecord()) {
|
||||
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.EXTENDS), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
if (!psiClass.isInterface()) {
|
||||
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.IMPLEMENTS), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight.completion
|
||||
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import groovy.transform.CompileStatic
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@CompileStatic
|
||||
class Normal14CompletionTest extends NormalCompletionTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_14
|
||||
}
|
||||
|
||||
void testRecordImplements() {
|
||||
myFixture.configureByText("a.java", "record X() impl<caret>")
|
||||
myFixture.completeBasic()
|
||||
myFixture.checkResult("record X() implements ")
|
||||
}
|
||||
|
||||
void testRecordNoClassAfterHeader() {
|
||||
myFixture.configureByText("a.java", "record X() cla<caret>")
|
||||
myFixture.completeBasic()
|
||||
myFixture.checkResult("record X() cla")
|
||||
}
|
||||
}
|
||||
+6
@@ -1944,4 +1944,10 @@ class Abc {
|
||||
}
|
||||
|
||||
void testNoCallsAfterAnnotationInCodeBlock() { doTest() }
|
||||
|
||||
void testExtendsAfterEnum() {
|
||||
myFixture.configureByText("a.java", "enum X ex<caret>") // should not complete
|
||||
myFixture.completeBasic()
|
||||
myFixture.checkResult("enum X ex")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user