mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't overwrite trailing space in java & groovy keyword completion
This commit is contained in:
@@ -31,7 +31,7 @@ public class Java15CompletionData extends JavaCompletionData {
|
||||
//static keyword in static import
|
||||
{
|
||||
final CompletionVariant variant = new CompletionVariant(PsiImportList.class, new LeftNeighbour(new TextFilter (PsiKeyword.IMPORT)));
|
||||
variant.addCompletion(PsiKeyword.STATIC, TailType.SPACE);
|
||||
variant.addCompletion(PsiKeyword.STATIC, TailType.INSERT_SPACE);
|
||||
|
||||
registerVariant(variant);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class Java15CompletionData extends JavaCompletionData {
|
||||
final CompletionVariant variant = new CompletionVariant(PsiJavaFile.class, position);
|
||||
variant.includeScopeClass(PsiClass.class);
|
||||
|
||||
variant.addCompletion(PsiKeyword.INTERFACE, TailType.SPACE);
|
||||
variant.addCompletion(PsiKeyword.INTERFACE, TailType.INSERT_SPACE);
|
||||
|
||||
registerVariant(variant);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class Java15CompletionData extends JavaCompletionData {
|
||||
final CompletionVariant variant = new CompletionVariant(PsiJavaFile.class, CLASS_START);
|
||||
variant.includeScopeClass(PsiClass.class);
|
||||
|
||||
variant.addCompletion(PsiKeyword.ENUM, TailType.SPACE);
|
||||
variant.addCompletion(PsiKeyword.ENUM, TailType.INSERT_SPACE);
|
||||
registerVariant(variant);
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ public class Java15CompletionData extends JavaCompletionData {
|
||||
final CompletionVariant variant = new CompletionVariant(JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN);
|
||||
variant.includeScopeClass(PsiVariable.class, true);
|
||||
variant.includeScopeClass(PsiExpressionStatement.class, true);
|
||||
variant.addCompletion(PsiKeyword.SUPER, TailType.SPACE);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.SPACE);
|
||||
variant.addCompletion(PsiKeyword.SUPER, TailType.INSERT_SPACE);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.INSERT_SPACE);
|
||||
registerVariant(variant);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
// completion
|
||||
final CompletionVariant variant = new CompletionVariant(position);
|
||||
variant.includeScopeClass(PsiClass.class, true);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.INSERT_SPACE);
|
||||
variant.excludeScopeClass(PsiAnonymousClass.class);
|
||||
variant.excludeScopeClass(PsiTypeParameter.class);
|
||||
|
||||
@@ -292,7 +292,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
// completion
|
||||
final CompletionVariant variant = new CompletionVariant(position);
|
||||
variant.includeScopeClass(PsiClass.class, true);
|
||||
variant.addCompletion(PsiKeyword.IMPLEMENTS);
|
||||
variant.addCompletion(PsiKeyword.IMPLEMENTS, TailType.INSERT_SPACE);
|
||||
variant.excludeScopeClass(PsiAnonymousClass.class);
|
||||
|
||||
registerVariant(variant);
|
||||
@@ -304,7 +304,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
psiElement(PsiIdentifier.class).afterLeaf(
|
||||
psiElement().withText(string().oneOf(",", "<")).withParent(PsiTypeParameterList.class))));
|
||||
//variant.includeScopeClass(PsiClass.class, true);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.SPACE);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.INSERT_SPACE);
|
||||
registerVariant(variant);
|
||||
}
|
||||
}
|
||||
@@ -412,7 +412,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
return TailType.SEMICOLON;
|
||||
}
|
||||
|
||||
return TailType.SPACE;
|
||||
return TailType.INSERT_SPACE;
|
||||
}
|
||||
scope = scope.getParent();
|
||||
}
|
||||
@@ -425,12 +425,12 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FOR), TailTypes.FOR_LPARENTH));
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.IF), TailTypes.IF_LPARENTH));
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.TRY), TailType.createSimpleTailType('{')));
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.THROW), TailType.SPACE));
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.NEW), TailType.SPACE));
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.THROW), TailType.INSERT_SPACE));
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.NEW), TailType.INSERT_SPACE));
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.SYNCHRONIZED), TailTypes.SYNCHRONIZED_LPARENTH));
|
||||
|
||||
if (PsiUtil.getLanguageLevel(position).isAtLeast(LanguageLevel.JDK_1_4)) {
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.ASSERT), TailType.SPACE));
|
||||
variant.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.ASSERT), TailType.INSERT_SPACE));
|
||||
}
|
||||
|
||||
TailType returnTail = getReturnTail(position);
|
||||
@@ -454,13 +454,13 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
}
|
||||
if (statement != null && statement.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
|
||||
if (!psiElement().withSuperParent(2, PsiSwitchStatement.class).accepts(statement)) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.SPACE));
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
|
||||
if (isStatementPosition(position)) {
|
||||
if (PsiTreeUtil.getParentOfType(position, PsiSwitchStatement.class, false, PsiMember.class) != null) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.CASE), TailType.SPACE));
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.CASE), TailType.INSERT_SPACE));
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.DEFAULT), TailType.CASE_COLON));
|
||||
if (START_SWITCH.accepts(position)) {
|
||||
return;
|
||||
@@ -499,20 +499,20 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
}
|
||||
|
||||
if (EXPR_KEYWORDS.accepts(position)) {
|
||||
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.NEW), TailType.SPACE));
|
||||
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.NEW), TailType.INSERT_SPACE));
|
||||
result.addElement(createKeyword(position, PsiKeyword.NULL));
|
||||
result.addElement(createKeyword(position, PsiKeyword.TRUE));
|
||||
result.addElement(createKeyword(position, PsiKeyword.FALSE));
|
||||
}
|
||||
|
||||
if (INSIDE_PARAMETER_LIST.accepts(position) && !psiElement().afterLeaf(PsiKeyword.FINAL).accepts(position) && !AFTER_DOT.accepts(position)) {
|
||||
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.SPACE));
|
||||
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.INSERT_SPACE));
|
||||
}
|
||||
|
||||
if (CLASS_START.isAcceptable(position, position) &&
|
||||
PsiTreeUtil.getNonStrictParentOfType(position, PsiLiteralExpression.class, PsiComment.class) == null) {
|
||||
for (String s : ModifierChooser.getKeywords(position)) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, s), TailType.SPACE));
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, s), TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,11 +589,11 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
isStatementPosition(position)) {
|
||||
for (String primitiveType : PRIMITIVE_TYPES) {
|
||||
LookupElement keyword = createKeyword(position, primitiveType);
|
||||
result.addElement(inCast ? keyword : new OverrideableSpace(keyword, TailType.SPACE));
|
||||
result.addElement(inCast ? keyword : new OverrideableSpace(keyword, TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
if (declaration) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.VOID), TailType.SPACE));
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.VOID), TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ public class JavaDocCompletionContributor extends CompletionContributor {
|
||||
if (isInline) {
|
||||
result.addElement(TailTypeDecorator.withInsertHandler(LookupElementBuilder.create(s), new InlineInsertHandler()));
|
||||
} else {
|
||||
result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(s), TailType.SPACE));
|
||||
result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(s), TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -264,7 +264,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
for (PsiClassType ref : method.getThrowsList().getReferencedTypes()) {
|
||||
final PsiClass exception = ref.resolve();
|
||||
if (exception != null && throwsSet.add(exception)) {
|
||||
result.addElement(TailTypeDecorator.withTail(new JavaPsiClassReferenceElement(exception), TailType.SPACE));
|
||||
result.addElement(TailTypeDecorator.withTail(new JavaPsiClassReferenceElement(exception), TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
if (tryBlock == null) return;
|
||||
|
||||
for (final PsiClassType type : ExceptionUtil.getThrownExceptions(tryBlock.getStatements())) {
|
||||
result.addElement(TailTypeDecorator.withTail(PsiTypeLookupItem.createLookupItem(type, tryBlock).setInsertHandler(new DefaultInsertHandler()), TailType.SPACE));
|
||||
result.addElement(TailTypeDecorator.withTail(PsiTypeLookupItem.createLookupItem(type, tryBlock).setInsertHandler(new DefaultInsertHandler()), TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
class Foo<T extends <caret>A> {
|
||||
class Foo<T extends <caret> A> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class AAA{}
|
||||
|
||||
class BBB extends AAA implements <caret>{
|
||||
class BBB extends AAA implements <caret> {
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
public class A{
|
||||
public void method(final String){
|
||||
public void method(final <caret> String){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class A {
|
||||
private long <caret>localizedStringManager;
|
||||
private long <caret> localizedStringManager;
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -720,7 +720,7 @@ class Foo {
|
||||
joinAutopopup()
|
||||
joinCompletion()
|
||||
myFixture.type '\n'
|
||||
myFixture.checkResult(" class Foo { { int newa; new <caret>} } ")
|
||||
myFixture.checkResult(" class Foo { { int newa; new <caret> } } ")
|
||||
assert !lookup
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ public abstract class TailType {
|
||||
}
|
||||
};
|
||||
public static final TailType SPACE = new CharTailType(' ');
|
||||
public static final TailType INSERT_SPACE = new CharTailType(' ', false);
|
||||
public static final TailType DOT = new CharTailType('.');
|
||||
|
||||
public static final TailType CASE_COLON = new CharTailType(':');
|
||||
|
||||
+7
-7
@@ -77,15 +77,15 @@ public class GroovyCompletionData {
|
||||
|
||||
if (!PlatformPatterns.psiElement().afterLeaf(".", ".&").accepts(position)) {
|
||||
if (suggestPackage(position)) {
|
||||
result.addElement(keyword(PsiKeyword.PACKAGE, TailType.SPACE));
|
||||
result.addElement(keyword(PsiKeyword.PACKAGE, TailType.INSERT_SPACE));
|
||||
}
|
||||
if (suggestImport(position)) {
|
||||
result.addElement(keyword(PsiKeyword.IMPORT, TailType.SPACE));
|
||||
result.addElement(keyword(PsiKeyword.IMPORT, TailType.INSERT_SPACE));
|
||||
}
|
||||
|
||||
addTypeDefinitionKeywords(result, position);
|
||||
for (String keyword : addExtendsImplements(position)) {
|
||||
result.addElement(keyword(keyword, TailType.SPACE));
|
||||
result.addElement(keyword(keyword, TailType.INSERT_SPACE));
|
||||
}
|
||||
|
||||
registerControlCompletion(position, result);
|
||||
@@ -144,7 +144,7 @@ public class GroovyCompletionData {
|
||||
addKeywords(result, true, PsiKeyword.CLASS, PsiKeyword.INTERFACE, PsiKeyword.ENUM);
|
||||
}
|
||||
if (afterAtInType(position)) {
|
||||
result.addElement(keyword(PsiKeyword.INTERFACE, TailType.SPACE));
|
||||
result.addElement(keyword(PsiKeyword.INTERFACE, TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ public class GroovyCompletionData {
|
||||
|
||||
public static void addKeywords(CompletionResultSet result, boolean space, String... keywords) {
|
||||
for (String s : keywords) {
|
||||
result.addElement(keyword(s, space ? TailType.SPACE : TailType.NONE));
|
||||
result.addElement(keyword(s, space ? TailType.INSERT_SPACE : TailType.NONE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ public class GroovyCompletionData {
|
||||
addKeywords(result, true, controlKeywords);
|
||||
}
|
||||
if (inCaseSection(context)) {
|
||||
result.addElement(keyword("case", TailType.SPACE));
|
||||
result.addElement(keyword("case", TailType.INSERT_SPACE));
|
||||
result.addElement(keyword("default", TailType.CASE_COLON));
|
||||
}
|
||||
if (afterTry(context)) {
|
||||
@@ -217,7 +217,7 @@ public class GroovyCompletionData {
|
||||
if (PlatformPatterns.psiElement(GroovyDocTokenTypes.mGDOC_TAG_NAME).andNot(PlatformPatterns.psiElement().afterLeaf(".")).accepts(position)) {
|
||||
String[] tags = position.getParent() instanceof GrDocInlinedTag ? INLINED_DOC_TAGS : DOC_TAGS;
|
||||
for (String docTag : tags) {
|
||||
result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(docTag), TailType.SPACE));
|
||||
result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(docTag), TailType.INSERT_SPACE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1064,7 +1064,7 @@ class X {
|
||||
}
|
||||
|
||||
public void testInnerClassStart() {
|
||||
checkSingleItemCompletion 'class Foo { cl<caret> }', 'class Foo { class <caret>}'
|
||||
checkSingleItemCompletion 'class Foo { cl<caret> }', 'class Foo { class <caret> }'
|
||||
}
|
||||
|
||||
public void testPropertyBeforeAccessor() {
|
||||
@@ -1114,7 +1114,8 @@ public class KeyVO {
|
||||
|
||||
public void testSpaceTail() {
|
||||
checkCompletion 'class A <caret> ArrayList {}', ' ', 'class A extends <caret> ArrayList {}'
|
||||
checkCompletion 'class A <caret> ArrayList {}', '\n', 'class A extends <caret>ArrayList {}'
|
||||
checkCompletion 'class A <caret> ArrayList {}', '\n', 'class A extends <caret> ArrayList {}'
|
||||
checkSingleItemCompletion 'class Foo impl<caret> {}', 'class Foo implements <caret> {}'
|
||||
}
|
||||
|
||||
public void testPreferInterfacesInImplements() {
|
||||
|
||||
Reference in New Issue
Block a user