mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-120885: complete 'as' keyword in appropriate place
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -32,6 +32,8 @@ import java.util.List;
|
||||
@SuppressWarnings("unchecked")
|
||||
public class StandardPatterns {
|
||||
|
||||
private static final FalsePattern FALSE_PATTERN = new FalsePattern();
|
||||
|
||||
public static StringPattern string() {
|
||||
return new StringPattern();
|
||||
}
|
||||
@@ -178,4 +180,30 @@ public class StandardPatterns {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static <E> ElementPattern<E> alwaysFalse() {
|
||||
return FALSE_PATTERN;
|
||||
}
|
||||
|
||||
private static final class FalsePattern implements ElementPattern {
|
||||
@Override
|
||||
public boolean accepts(@Nullable Object o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(@Nullable Object o, ProcessingContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementPatternCondition getCondition() {
|
||||
return new ElementPatternCondition(new InitialPatternCondition(Object.class) {
|
||||
@Override
|
||||
public boolean accepts(@Nullable Object o, ProcessingContext context) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -78,6 +78,7 @@ import java.util.Set;
|
||||
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.elementType;
|
||||
import static com.intellij.patterns.StandardPatterns.alwaysFalse;
|
||||
import static com.intellij.util.containers.ContainerUtil.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.SEPARATORS;
|
||||
@@ -170,7 +171,8 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
))
|
||||
);
|
||||
|
||||
private static final ElementPattern<PsiElement> AFTER_NUMBER_LITERAL = psiElement().afterLeaf(
|
||||
private static final ElementPattern<PsiElement> AFTER_NUMBER_LITERAL = psiElement().afterLeafSkipping(
|
||||
alwaysFalse(),
|
||||
psiElement().withElementType(elementType().oneOf(mNUM_DOUBLE, mNUM_INT, mNUM_LONG, mNUM_FLOAT, mNUM_BIG_INT, mNUM_BIG_DECIMAL)));
|
||||
public static final ElementPattern<PsiElement> AFTER_AT = psiElement().afterLeaf("@");
|
||||
public static final ElementPattern<PsiElement> IN_CATCH_TYPE = psiElement().afterLeaf(psiElement().withText("(").withParent(GrCatchClause.class));
|
||||
|
||||
+2
-3
@@ -132,17 +132,16 @@ public class GroovyCompletionData {
|
||||
|
||||
registerControlCompletion(position, result);
|
||||
|
||||
if (parent instanceof GrExpression) {
|
||||
if (parent instanceof GrExpression || isInfixOperatorPosition(position)) {
|
||||
addKeywords(result, false, PsiKeyword.TRUE, PsiKeyword.FALSE, PsiKeyword.NULL, PsiKeyword.SUPER, PsiKeyword.THIS);
|
||||
result.addElement(keyword(PsiKeyword.NEW, TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
result.addElement(keyword("as", TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
|
||||
if (isAfterForParameter(position)) {
|
||||
result.addElement(keyword("in", TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
if (isInfixOperatorPosition(position)) {
|
||||
addKeywords(result, true, "in", PsiKeyword.INSTANCEOF);
|
||||
addKeywords(result, true, "as", "in", PsiKeyword.INSTANCEOF);
|
||||
}
|
||||
if (suggestPrimitiveTypes(position)) {
|
||||
final boolean addSpace = !IN_CAST_TYPE_ELEMENT.accepts(position) && !GroovySmartCompletionContributor.AFTER_NEW.accepts(position) && !isInExpression(position);
|
||||
|
||||
+1
@@ -106,6 +106,7 @@ public class KeywordCompletionTest extends CompletionTestBase {
|
||||
void testClassAfterAnno2() { doTest() }
|
||||
void testExtends() { doTest() }
|
||||
void testImplements() { doTest() }
|
||||
void testAfterNumberLiteral() { doTest() }
|
||||
|
||||
String basePath = TestUtils.testDataPath + 'groovy/oldCompletion/keyword'
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
def foo() {
|
||||
foo() <caret>
|
||||
}
|
||||
-----
|
||||
@@ -1,6 +1,5 @@
|
||||
foo: <caret>
|
||||
-----
|
||||
as
|
||||
assert
|
||||
boolean
|
||||
byte
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
def foo() {
|
||||
4 <caret>
|
||||
}
|
||||
-----
|
||||
as
|
||||
false
|
||||
in
|
||||
instanceof
|
||||
new
|
||||
null
|
||||
super
|
||||
this
|
||||
true
|
||||
@@ -1,4 +1,3 @@
|
||||
as<caret>sert true
|
||||
-----
|
||||
as
|
||||
assert
|
||||
@@ -8,7 +8,6 @@ class BaseLineService {
|
||||
|
||||
String abc = 5
|
||||
-----
|
||||
as
|
||||
assert
|
||||
boolean
|
||||
byte
|
||||
|
||||
@@ -11,7 +11,6 @@ class A {
|
||||
}
|
||||
}
|
||||
-----
|
||||
as
|
||||
assert
|
||||
boolean
|
||||
byte
|
||||
|
||||
@@ -2,7 +2,6 @@ try {}
|
||||
<caret>
|
||||
-----
|
||||
abstract
|
||||
as
|
||||
assert
|
||||
boolean
|
||||
byte
|
||||
|
||||
-1
@@ -1,6 +1,5 @@
|
||||
(<caret>)
|
||||
-----
|
||||
as
|
||||
boolean
|
||||
byte
|
||||
char
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<caret>def foo(){}
|
||||
-----
|
||||
abstract
|
||||
as
|
||||
assert
|
||||
boolean
|
||||
byte
|
||||
|
||||
@@ -9,7 +9,6 @@ class A {
|
||||
}
|
||||
-----
|
||||
abstract
|
||||
as
|
||||
assert
|
||||
boolean
|
||||
byte
|
||||
|
||||
@@ -11,7 +11,6 @@ class A {
|
||||
}
|
||||
}
|
||||
-----
|
||||
as
|
||||
boolean
|
||||
byte
|
||||
char
|
||||
|
||||
@@ -11,7 +11,6 @@ class A {
|
||||
}
|
||||
-----
|
||||
abstract
|
||||
as
|
||||
assert
|
||||
boolean
|
||||
byte
|
||||
|
||||
Reference in New Issue
Block a user