mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java completion: use a single way to find previous interesting PSI (IDEA-184555)
This commit is contained in:
@@ -12,6 +12,7 @@ import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.PsiElementPattern;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.filters.FilterPositionUtil;
|
||||
import com.intellij.psi.templateLanguages.OuterLanguageElement;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -19,7 +20,6 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -124,7 +124,7 @@ public class JavaKeywordCompletion {
|
||||
}
|
||||
|
||||
private static PsiElement prevSignificantLeaf(PsiElement position) {
|
||||
return JBIterable.generate(position, PsiTreeUtil::prevVisibleLeaf).skip(1).skipWhile(e -> PsiTreeUtil.getNonStrictParentOfType(e, PsiComment.class) != null).first();
|
||||
return FilterPositionUtil.searchNonSpaceNonCommentBack(position);
|
||||
}
|
||||
|
||||
private void addKeyword(LookupElement element) {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
abstract /** javadoc */
|
||||
<caret> class Primitive {
|
||||
|
||||
public abstract void draw();
|
||||
|
||||
|
||||
}
|
||||
+1
@@ -48,6 +48,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
|
||||
public void testFileScope1() { doTest(8, FILE_SCOPE_KEYWORDS); }
|
||||
public void testFileScopeAfterComment() { doTest(4, "package", "class", "import", "public", "private"); }
|
||||
public void testFileScopeAfterJavaDoc() { doTest(4, "package", "class", "import", "public", "private"); }
|
||||
public void testFileScopeAfterJavaDocInsideModifierList() { doTest(2, "class", "public"); }
|
||||
public void testFileScope2() { doTest(7, CLASS_SCOPE_KEYWORDS); }
|
||||
public void testClassScope1() { doTest(5, CLASS_SCOPE_KEYWORDS); }
|
||||
public void testClassScope2() { doTest(4, CLASS_SCOPE_KEYWORDS); }
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.impl.source.tree.TreeUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -37,7 +38,8 @@ public class FilterPositionUtil {
|
||||
ASTNode leftNeighbour = TreeUtil.prevLeaf(element.getNode());
|
||||
if (!strict) {
|
||||
while (leftNeighbour != null &&
|
||||
(leftNeighbour.getElementType() == TokenType.WHITE_SPACE || leftNeighbour.getPsi() instanceof PsiComment)) {
|
||||
(leftNeighbour.getElementType() == TokenType.WHITE_SPACE ||
|
||||
PsiTreeUtil.getNonStrictParentOfType(leftNeighbour.getPsi(), PsiComment.class) != null)) {
|
||||
leftNeighbour = TreeUtil.prevLeaf(leftNeighbour);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user