From 71046b4a52ce8e3e0ab86e5fe8c8ef20a4bd4538 Mon Sep 17 00:00:00 2001 From: Yaroslav Lepenkin Date: Tue, 4 Oct 2016 12:01:51 +0300 Subject: [PATCH] [Parameter Name Hints] show for single param null and this --- .../impl/ParameterNameHintsManager.java | 16 ++++++++++++-- .../daemon/inlays/InlayParameterHintsTest.kt | 21 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/ParameterNameHintsManager.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/ParameterNameHintsManager.java index f308388bab40..accf64efdab0 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/ParameterNameHintsManager.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/ParameterNameHintsManager.java @@ -64,20 +64,32 @@ public class ParameterNameHintsManager { myDescriptors = descriptors; } - private static boolean isMethodToShowParams(PsiCallExpression callExpression, JavaResolveResult resolveResult) { + private static boolean isMethodToShowParams(@NotNull PsiCallExpression callExpression, @NotNull JavaResolveResult resolveResult) { PsiElement element = resolveResult.getElement(); if (element instanceof PsiMethod) { PsiMethod method = (PsiMethod)element; if (isSetter(method) || isBuilder(callExpression, method)) return false; if (hasSingleParameter(method)) { PsiParameter parameter = method.getParameterList().getParameters()[0]; - return PsiType.VOID.equals(method.getReturnType()) || isBoolean(parameter); + return PsiType.VOID.equals(method.getReturnType()) || isBoolean(parameter) || isNullOrThis(callExpression); } return !isCommonMethod(method); } return false; } + private static boolean isNullOrThis(@NotNull PsiCallExpression callExpression) { + PsiExpressionList list = callExpression.getArgumentList(); + PsiExpression[] expressions = list != null ? list.getExpressions() : null; + if (expressions != null && expressions.length > 0) { + PsiExpression expression = expressions[0]; + if (expression.textMatches("null") || expression.textMatches("this")) { + return true; + } + } + return false; + } + private static boolean isBuilder(PsiCallExpression expression, PsiMethod method) { if (expression instanceof PsiNewExpression) { return false; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/inlays/InlayParameterHintsTest.kt b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/inlays/InlayParameterHintsTest.kt index 6f18a4fe58d1..e49fb2e6f845 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/inlays/InlayParameterHintsTest.kt +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/inlays/InlayParameterHintsTest.kt @@ -526,6 +526,27 @@ public class VarArgTest { .assertInlays("test->this", "endIndex->1000") } + fun `test inline strange methods`() { + setup(""" +public class Test { + + void main() { + createContent(null); + createNewContent(this); + } + + Content createContent(DockManager manager) {} + Content createNewContent(Test test) {} + +} +interface DockManager {} +interface Content {} +""") + + onLineStartingWith("createContent").assertInlays("manager->null") + onLineStartingWith("createNewContent").assertInlays("test->this") + } + fun `test do not inline builder pattern`() { setup(""" class Builder {