mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-74356 Code completion: Tab in the middle of already typed code adds a space
This commit is contained in:
@@ -353,17 +353,6 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
registerVariant(variant);
|
||||
}
|
||||
|
||||
// Completion in cast expressions
|
||||
{
|
||||
final CompletionVariant variant = new CompletionVariant(PsiMethod.class, new LeftNeighbour(new AndFilter(
|
||||
new TextFilter("("),
|
||||
new ParentElementFilter(new OrFilter(
|
||||
new ClassFilter(PsiParenthesizedExpression.class),
|
||||
new ClassFilter(PsiTypeCastExpression.class))))));
|
||||
addPrimitiveTypes(variant, CompletionVariant.DEFAULT_TAIL_TYPE);
|
||||
registerVariant(variant);
|
||||
}
|
||||
|
||||
{
|
||||
// instanceof keyword
|
||||
final ElementFilter position = INSTANCEOF_PLACE;
|
||||
@@ -581,15 +570,27 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
}
|
||||
|
||||
private static void addPrimitiveTypes(CompletionResultSet result, PsiElement position) {
|
||||
new LeftNeighbour(new AndFilter(
|
||||
new TextFilter("("),
|
||||
new ParentElementFilter(new OrFilter(
|
||||
new ClassFilter(PsiParenthesizedExpression.class),
|
||||
new ClassFilter(PsiTypeCastExpression.class)))));
|
||||
|
||||
boolean inCast = psiElement()
|
||||
.afterLeaf(psiElement().withText("(").withParent(psiElement(PsiParenthesizedExpression.class, PsiTypeCastExpression.class)))
|
||||
.accepts(position);
|
||||
|
||||
boolean declaration = DECLARATION_START.isAcceptable(position, position) ||
|
||||
psiElement().withParents(PsiJavaCodeReferenceElement.class, PsiTypeElement.class, PsiMember.class).accepts(position) ||
|
||||
psiElement().withParents(PsiJavaCodeReferenceElement.class, PsiTypeElement.class, PsiClassLevelDeclarationStatement.class).accepts(position);
|
||||
if (START_FOR.accepts(position) ||
|
||||
INSIDE_PARAMETER_LIST.accepts(position) && !AFTER_DOT.accepts(position) ||
|
||||
VARIABLE_AFTER_FINAL.accepts(position) ||
|
||||
inCast ||
|
||||
declaration) {
|
||||
for (String primitiveType : PRIMITIVE_TYPES) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, primitiveType)));
|
||||
LookupElement keyword = createKeyword(position, primitiveType);
|
||||
result.addElement(inCast ? keyword : new OverrideableSpace(keyword));
|
||||
}
|
||||
}
|
||||
if (declaration) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Zoo2 {
|
||||
{
|
||||
byte v1 = (by<caret>te) 0;
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
public class Zoo2 {
|
||||
{
|
||||
byte v1 = (byte<caret>) 0;
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -853,6 +853,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testMethodParameterAnnotationClass() throws Throwable { doTest(); }
|
||||
public void testPrimitiveCastOverwrite() throws Throwable { doTest '\t' }
|
||||
|
||||
public void testVoidMethodsInNonVoidContext() throws Throwable {
|
||||
configure()
|
||||
|
||||
@@ -49,6 +49,20 @@ public class PsiJavaPatterns extends StandardPatterns{
|
||||
return new PsiJavaElementPattern.Capture<T>(aClass);
|
||||
}
|
||||
|
||||
public static PsiJavaElementPattern.Capture<PsiElement> psiElement(final Class<? extends PsiElement>... classAlternatives) {
|
||||
return new PsiJavaElementPattern.Capture<PsiElement>(new InitialPatternCondition<PsiElement>(PsiElement.class) {
|
||||
@Override
|
||||
public boolean accepts(@Nullable Object o, ProcessingContext context) {
|
||||
for (Class<? extends PsiElement> classAlternative : classAlternatives) {
|
||||
if (classAlternative.isInstance(o)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static PsiJavaElementPattern.Capture<PsiLiteralExpression> literalExpression() {
|
||||
return literalExpression(null);
|
||||
}
|
||||
|
||||
+6
-4
@@ -25,9 +25,7 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.lookup.TailTypeDecorator;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.patterns.PlatformPatterns;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.PsiKeyword;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.templateLanguages.OuterLanguageElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -92,7 +90,11 @@ public class GroovyCompletionData {
|
||||
} else if (suggestThrows(position)) {
|
||||
addKeywords(result, true, PsiKeyword.THROWS);
|
||||
} else if (suggestPrimitiveTypes(position)) {
|
||||
addKeywords(result, true, BUILT_IN_TYPES);
|
||||
boolean inCast = psiElement()
|
||||
.afterLeaf(psiElement().withText("(").withParent(psiElement(GrParenthesizedExpression.class, GrTypeCastExpression.class)))
|
||||
.accepts(position);
|
||||
|
||||
addKeywords(result, !inCast, BUILT_IN_TYPES);
|
||||
}
|
||||
|
||||
if (psiElement(GrReferenceExpression.class).inside(or(psiElement(GrWhileStatement.class), psiElement(GrForStatement.class))).accepts(parent)) {
|
||||
|
||||
+4
@@ -841,4 +841,8 @@ class X {
|
||||
public void testSortOrder0() {
|
||||
doVariantableTest 'se', 'setMetaClass', 'setProperty', 'setSe'
|
||||
}
|
||||
|
||||
public void testPrimitiveCastOverwrite() {
|
||||
checkCompletion 'byte v1 = (by<caret>te) 0', '\t', 'byte v1 = (byte<caret>) 0'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user