diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java b/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java index 77c78754d233..2436ce146de6 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.completion.simple; import com.intellij.codeInsight.TailType; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; @@ -35,6 +36,11 @@ public abstract class ParenthesesTailType extends TailType { if (isSpaceBeforeParentheses(styleSettings, editor, tailOffset)) { tailOffset = insertChar(editor, tailOffset, ' '); } + Document document = editor.getDocument(); + if (tailOffset < document.getTextLength() && document.getCharsSequence().charAt(tailOffset) == '(') { + return moveCaret(editor, tailOffset, 1); + } + tailOffset = insertChar(editor, tailOffset, '('); if (isSpaceWithinParentheses(styleSettings, editor, tailOffset)) { tailOffset = insertChar(editor, tailOffset, ' '); diff --git a/java/java-tests/testData/codeInsight/completion/keywords/overwriteCatch.java b/java/java-tests/testData/codeInsight/completion/keywords/overwriteCatch.java new file mode 100644 index 000000000000..33ff9d184ed6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/keywords/overwriteCatch.java @@ -0,0 +1,10 @@ +class A { + { + try { + mySocket.receive(p); + } + catch (SocketTimeoutException e) { + throw new TimeoutOccurredException(e); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/keywords/overwriteCatch_after.java b/java/java-tests/testData/codeInsight/completion/keywords/overwriteCatch_after.java new file mode 100644 index 000000000000..625bf332e209 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/keywords/overwriteCatch_after.java @@ -0,0 +1,10 @@ +class A { + { + try { + mySocket.receive(p); + } + catch (SocketTimeoutException e) { + throw new TimeoutOccurredException(e); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/KeywordCompletionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/KeywordCompletionTest.java index 1e6543944d71..2368e99375af 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/KeywordCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/KeywordCompletionTest.java @@ -17,6 +17,7 @@ package com.intellij.java.codeInsight.completion; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.completion.LightCompletionTestCase; +import com.intellij.codeInsight.lookup.Lookup; import com.intellij.lang.java.JavaLanguage; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; @@ -111,9 +112,9 @@ public class KeywordCompletionTest extends LightCompletionTestCase { public void testInstanceofAfterStatementStart() { doTest(1, "instanceof"); } public void testInstanceofNegation() { - configureByFile(BASE_PATH + getTestName(true) + ".java"); + configureByTestName(); selectItem(myItems[0], '!'); - checkResultByFile(BASE_PATH + getTestName(true) + "_after.java"); + checkResultByTestName(); } public void testNoPrimitivesInBooleanAnnotationAttribute() { doTest(1, "true", "int", "boolean"); } @@ -146,20 +147,34 @@ public class KeywordCompletionTest extends LightCompletionTestCase { public void testPrimitiveInForLoop() { doTest(1, "int"); } public void testPrivateInJava9Interface() { setLanguageLevel(LanguageLevel.JDK_1_9); doTest(); } + public void testOverwriteCatch() { + configureByTestName(); + selectItem(myItems[0], Lookup.REPLACE_SELECT_CHAR); + checkResultByTestName(); + } + public void testTryInExpression() { - configureByFile(BASE_PATH + getTestName(true) + ".java"); + configureByTestName(); assertEquals("toString", myItems[0].getLookupString()); assertEquals("this", myItems[1].getLookupString()); } private void doTest() { + configureByTestName(); + checkResultByTestName(); + } + + private void configureByTestName() { configureByFile(BASE_PATH + getTestName(true) + ".java"); + } + + private void checkResultByTestName() { checkResultByFile(BASE_PATH + getTestName(true) + "_after.java"); } // todo: check included/excluded variants separately protected void doTest(int finalCount, String... values) { - configureByFile(BASE_PATH + getTestName(true) + ".java"); + configureByTestName(); testByCount(finalCount, values); } } \ No newline at end of file