diff --git a/java/java-impl/src/com/intellij/codeInsight/hints/JavaHintUtils.kt b/java/java-impl/src/com/intellij/codeInsight/hints/JavaHintUtils.kt index c7b5dd5353d0..2be5f0cc3ec8 100644 --- a/java/java-impl/src/com/intellij/codeInsight/hints/JavaHintUtils.kt +++ b/java/java-impl/src/com/intellij/codeInsight/hints/JavaHintUtils.kt @@ -1,4 +1,6 @@ -// Copyright 2000-2017 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. +/* + * 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.hints import com.intellij.codeInsight.completion.CompletionMemory @@ -16,10 +18,14 @@ object JavaInlayHintsProvider { fun hints(callExpression: PsiCallExpression): Set { if (JavaMethodCallElement.isCompletionMode(callExpression)) { + val argumentList = callExpression.argumentList?:return emptySet() + val text = argumentList.text + if (text == null || !text.startsWith('(') || !text.endsWith(')')) return emptySet() + val method = CompletionMemory.getChosenMethod(callExpression)?:return emptySet() - + val params = method.parameterList.parameters - val arguments = callExpression.argumentList?.expressions ?: emptyArray() + val arguments = argumentList.expressions return params.mapIndexedNotNull { i, parameter -> val paramName = parameter.name ?: return@mapIndexedNotNull null @@ -28,7 +34,7 @@ object JavaInlayHintsProvider { val paramToShow = (if (varargHint) ", " else "") + paramName val offset = if (i < arguments.size) inlayOffset(arguments[i]) else if (varargHint && i == arguments.size) callExpression.textRange.endOffset - 1 - else (callExpression.argumentList?.textOffset?:return@mapIndexedNotNull null) + 1 + else argumentList.textOffset + 1 InlayInfo(paramToShow, offset, false, params.size == 1, varargHint) }.toSet() } diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java index 5fd0e0fa2275..b7ffbb96fe4c 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java @@ -837,6 +837,18 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { checkHintContents("String"); } + public void testBrokenPsiCall() throws Exception { + configureJava("class C { void m() { System.setPro } }"); + complete("setProperty"); + checkResultWithInlays("class C { void m() { System.setProperty(, ) } }"); + type(';'); + waitForAllAsyncStuff(); + checkResultWithInlays("class C { void m() { System.setProperty(;, ) } }"); + backspace(); + waitForAllAsyncStuff(); + checkResultWithInlays("class C { void m() { System.setProperty(, ) } }"); + } + private void enableConstructorVariantsCompletion() { Registry.get("java.completion.show.constructors").setValue(true); Disposer.register(myFixture.getTestRootDisposable(), () -> Registry.get("java.completion.show.constructors").setValue(false));