IDEA-167285 Using "complete current statement" with code completion produces broken code

This commit is contained in:
peter
2017-01-30 19:38:25 +01:00
parent 19f208e621
commit a5a04bb4af
4 changed files with 28 additions and 5 deletions

View File

@@ -886,7 +886,9 @@ public class JavaCompletionUtil {
context.getDocument().insertString(offset, open);
context.getEditor().getCaretModel().moveToOffset(offset + open.length());
context.getDocument().insertString(offset + open.length(), escapeXmlIfNeeded(context, ">"));
context.setAddCompletionChar(false);
if (context.getCompletionChar() != Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
context.setAddCompletionChar(false);
}
return true;
}

View File

@@ -0,0 +1,7 @@
import java.util.*;
public class Util {
int goo() {
Map<Object, Object> m = new HasMa<caret>
}
}

View File

@@ -0,0 +1,7 @@
import java.util.*;
public class Util {
int goo() {
Map<Object, Object> m = new HashMap<>();<caret>
}
}

View File

@@ -16,6 +16,7 @@
package com.intellij.codeInsight.completion
import com.intellij.JavaTestUtil
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.annotations.NotNull
@@ -28,7 +29,7 @@ class Normal17CompletionTest extends LightFixtureCompletionTestCase {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_LATEST
return JAVA_1_7
}
void testOnlyExceptionsInMultiCatch1() { doTest() }
@@ -50,7 +51,7 @@ class Normal17CompletionTest extends LightFixtureCompletionTestCase {
void testMethodReferenceCallContext() { doTest() }
void testResourceParentInResourceList() {
configureByFile(getTestName(false) + ".java")
configureByTestName()
assert 'MyOuterResource' == myFixture.lookupElementStrings[0]
assert 'MyClass' in myFixture.lookupElementStrings
myFixture.type('C\n')
@@ -58,14 +59,20 @@ class Normal17CompletionTest extends LightFixtureCompletionTestCase {
}
private void doTest() {
configureByFile(getTestName(false) + ".java")
configureByTestName()
myFixture.type('\n')
checkResultByFile(getTestName(false) + "_after.java")
}
void testAfterTryWithResources() {
configureByFile(getTestName(false) + ".java")
configureByTestName()
def strings = myFixture.lookupElementStrings
assert strings.containsAll(['final', 'finally', 'int', 'Util'])
}
void testNewObjectHashMapWithSmartEnter() {
configureByTestName()
myFixture.performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT)
checkResultByFile(getTestName(false) + "_after.java")
}
}