diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MethodCallFixer.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MethodCallFixer.java index 240678e0726b..8a01a5a26334 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MethodCallFixer.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MethodCallFixer.java @@ -44,7 +44,7 @@ public class MethodCallFixer implements Fixer { if (args != null && !hasRParenth(args)) { int caret = editor.getCaretModel().getOffset(); - PsiCallExpression innermostCall = PsiTreeUtil.findElementOfClassAtOffset(psiElement.getContainingFile(), caret, PsiCallExpression.class, false); + PsiCallExpression innermostCall = PsiTreeUtil.findElementOfClassAtOffset(psiElement.getContainingFile(), caret - 1, PsiCallExpression.class, false); if (innermostCall == null) return; args = innermostCall.getArgumentList(); diff --git a/java/java-tests/testData/codeInsight/completion/normal/SmartEnterInsideArrayBrackets.java b/java/java-tests/testData/codeInsight/completion/normal/SmartEnterInsideArrayBrackets.java new file mode 100644 index 000000000000..1c7f2fa998d9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/SmartEnterInsideArrayBrackets.java @@ -0,0 +1,8 @@ +class Main { + public void test() { + double[] d = new double[si]; + } + + int size(); + int size2(); +} diff --git a/java/java-tests/testData/codeInsight/completion/normal/SmartEnterInsideArrayBrackets_after.java b/java/java-tests/testData/codeInsight/completion/normal/SmartEnterInsideArrayBrackets_after.java new file mode 100644 index 000000000000..68f51a6c24dc --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/SmartEnterInsideArrayBrackets_after.java @@ -0,0 +1,8 @@ +class Main { + public void test() { + double[] d = new double[size()]; + } + + int size(); + int size2(); +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index 1e79ca0a017a..8194c1fd951d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -935,6 +935,7 @@ public class ListUtils { public void testSmartEnterNoNewLine() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) } public void testSmartEnterWithNewLine() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) } public void testSmartEnterGuessArgumentCount() throws Throwable { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) } + public void testSmartEnterInsideArrayBrackets() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) } public void testTabReplacesMethodNameWithLocalVariableName() throws Throwable { doTest('\t'); } public void testMethodParameterAnnotationClass() throws Throwable { doTest(); }