From 95e8bee5d2e827e1197ed652d6dd4167b1931589 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 21 May 2018 17:01:38 +0300 Subject: [PATCH] IDEABKL-6984 Add Eclipse Style Paren/Bracket/Quote Completiton case of array creation completion --- .../codeInsight/lookup/PsiTypeLookupItem.java | 32 ++++++------------- .../completion/EditorTabOutTest.java | 8 +++++ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java b/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java index d4d9d1104fc6..64fa79e4d56e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java +++ b/java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java @@ -1,21 +1,8 @@ -/* - * Copyright 2000-2013 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.lookup; import com.intellij.codeInsight.completion.*; +import com.intellij.codeInsight.editorActions.TabOutScopesTracker; import com.intellij.diagnostic.AttachmentFactory; import com.intellij.diagnostic.LogMessageEx; import com.intellij.openapi.diagnostic.Logger; @@ -123,24 +110,23 @@ public class PsiTypeLookupItem extends LookupItem implements TypedLookupItem { JavaCompletionUtil.shortenReference(context.getFile(), genericsStart - 1); } - int tail = context.getTailOffset(); + int targetOffset = context.getTailOffset(); String braces = StringUtil.repeat("[]", getBracketsCount()); Editor editor = context.getEditor(); if (!braces.isEmpty()) { if (myAddArrayInitializer) { - context.getDocument().insertString(tail, braces + "{}"); - editor.getCaretModel().moveToOffset(tail + braces.length() + 1); + context.getDocument().insertString(targetOffset, braces + "{}"); + targetOffset += braces.length() + 1; } else { - context.getDocument().insertString(tail, braces); - editor.getCaretModel().moveToOffset(tail + 1); + context.getDocument().insertString(targetOffset, braces); + targetOffset++; if (context.getCompletionChar() == '[') { context.setAddCompletionChar(false); } } + TabOutScopesTracker.getInstance().registerEmptyScope(editor, targetOffset); } - else { - editor.getCaretModel().moveToOffset(tail); - } + editor.getCaretModel().moveToOffset(targetOffset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); InsertHandler handler = getInsertHandler(); diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/EditorTabOutTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/EditorTabOutTest.java index 45b9e2e7f339..8b6193ef0cbc 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/EditorTabOutTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/EditorTabOutTest.java @@ -57,6 +57,14 @@ public class EditorTabOutTest extends AbstractParameterInfoTestCase { checkResult("class C { Comparable }"); } + public void testArray() { + configureJava("class C { int[] ar = new in }"); + complete(); + type("123"); + tabOut(); + checkResult("class C { int[] ar = new int[123] }"); + } + private void tabOut() { myFixture.performEditorAction(IdeActions.ACTION_BRACE_OR_QUOTE_OUT); }