mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-96639 Groovy: don't complete primitive types with space in expressions
This commit is contained in:
+16
-9
@@ -29,6 +29,7 @@ import com.intellij.codeInsight.lookup.TailTypeDecorator;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.PlatformPatterns;
|
||||
import com.intellij.patterns.StandardPatterns;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.templateLanguages.OuterLanguageElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -75,6 +76,10 @@ import static org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionUtil.
|
||||
public class GroovyCompletionData {
|
||||
public static final String[] BUILT_IN_TYPES = {"boolean", "byte", "char", "short", "int", "float", "long", "double", "void"};
|
||||
public static final String[] MODIFIERS = new String[]{"private", "public", "protected", "transient", "abstract", "native", "volatile", "strictfp", "static"};
|
||||
public static final ElementPattern<PsiElement> IN_CAST_TYPE_ELEMENT = StandardPatterns.or(
|
||||
psiElement().afterLeaf(psiElement().withText("(").withParent(psiElement(GrParenthesizedExpression.class, GrTypeCastExpression.class))),
|
||||
psiElement().afterLeaf(psiElement().withElementType(GroovyTokenTypes.kAS).withParent(GrSafeCastExpression.class))
|
||||
);
|
||||
static final String[] INLINED_DOC_TAGS = {"code", "docRoot", "inheritDoc", "link", "linkplain", "literal"};
|
||||
static final String[] DOC_TAGS = {"author", "deprecated", "exception", "param", "return", "see", "serial", "serialData",
|
||||
"serialField", "since", "throws", "version"};
|
||||
@@ -128,15 +133,8 @@ public class GroovyCompletionData {
|
||||
result.addElement(keyword(PsiKeyword.THROWS, TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
if (suggestPrimitiveTypes(position)) {
|
||||
boolean inCast = psiElement()
|
||||
.afterLeaf(psiElement().withText("(").withParent(psiElement(GrParenthesizedExpression.class, GrTypeCastExpression.class)))
|
||||
.accepts(position) ||
|
||||
psiElement()
|
||||
.afterLeaf(psiElement().withElementType(GroovyTokenTypes.kAS).withParent(GrSafeCastExpression.class))
|
||||
.accepts(position);
|
||||
|
||||
boolean inNew = psiElement().afterLeaf(psiElement(GroovyTokenTypes.kNEW)).accepts(position);
|
||||
addKeywords(result, !inCast && !inNew, BUILT_IN_TYPES);
|
||||
final boolean addSpace = !IN_CAST_TYPE_ELEMENT.accepts(position) && !GroovySmartCompletionContributor.AFTER_NEW.accepts(position) && !isInExpression(position);
|
||||
addKeywords(result, addSpace, BUILT_IN_TYPES);
|
||||
}
|
||||
|
||||
if (psiElement(GrReferenceExpression.class).inside(or(psiElement(GrWhileStatement.class), psiElement(GrForStatement.class))).accepts(parent)) {
|
||||
@@ -165,6 +163,15 @@ public class GroovyCompletionData {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether promitive type used in expression
|
||||
*/
|
||||
private static boolean isInExpression(PsiElement position) {
|
||||
final PsiElement actual = position.getParent();
|
||||
final PsiElement parent = actual.getParent();
|
||||
return parent instanceof GrArgumentList || parent instanceof GrBinaryExpression;
|
||||
}
|
||||
|
||||
private static void addExtendsForTypeParams(PsiElement position, CompletionResultSet result) {
|
||||
if (isWildcardCompletion(position)) {
|
||||
addKeywords(result, true, PsiKeyword.EXTENDS, PsiKeyword.SUPER);
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ public class GroovySmartCompletionContributor extends CompletionContributor {
|
||||
psiElement().withSuperParent(3, psiElement(GrTypeCastExpression.class).withParent(
|
||||
or(psiElement(GrAssignmentExpression.class), psiElement(GrVariable.class))));
|
||||
|
||||
static final ElementPattern<PsiElement> AFTER_NEW = psiElement().afterLeaf(psiElement().withText(PsiKeyword.NEW));
|
||||
static final ElementPattern<PsiElement> AFTER_NEW = psiElement().afterLeaf(psiElement(GroovyTokenTypes.kNEW));
|
||||
|
||||
private static final ElementPattern<PsiElement> IN_ANNOTATION = psiElement().withParent(psiElement(GrReferenceExpression.class).withParent(GrAnnotationNameValuePair.class));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user