From 42660e4ae70ade33887c04226a13bf355daf24bf Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Thu, 2 Feb 2017 19:32:17 +0300 Subject: [PATCH] IDEA-167473 'Quick Documentation' doesn't work on a method call if there are several applicable overloads --- .../lang/java/JavaDocumentationProvider.java | 9 +++++--- .../codeInsight/JavaDocumentationTest.groovy | 22 ++++++++++++++++++- .../JavaExternalDocumentationTest.java | 8 +++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java b/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java index f54518fb3c2e..ab4061cef53e 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -506,8 +506,11 @@ public class JavaDocumentationProvider extends DocumentationProviderEx implement @Override public String generateDoc(PsiElement element, PsiElement originalElement) { - if (element instanceof PsiExpressionList) { - element = element.getParent(); // for new Class() or methodCall() proceed from method call or new expression + // for new Class() or methodCall() proceed from method call or new expression + // same for new Class() or methodCall() + if (element instanceof PsiExpressionList || + element instanceof PsiReferenceExpression && element.getParent() instanceof PsiMethodCallExpression) { + element = element.getParent(); originalElement = null; } if (element instanceof PsiMethodCallExpression) { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/JavaDocumentationTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/JavaDocumentationTest.groovy index 1a4a10257d2f..3785ae8cbca0 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/JavaDocumentationTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/JavaDocumentationTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -231,6 +231,26 @@ class Bar { assert doc == expected } + void "test at method name with overloads"() { + def input = """\ + class Foo { + void foo(String s) { + s.regionMatches() + } + }""".stripIndent() + + def actual = JavaExternalDocumentationTest.getDocumentationText(myFixture.project, input) + + def expected = + "Candidates for method call s.regionMatches() are:
" + + "
" + + "  boolean regionMatches(int, String, int, int)
" + + "  boolean regionMatches(boolean, int, String, int, int)
" + + "" + + assert actual == expected + } + private void configure(String text) { myFixture.configureByText 'a.java', text } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/JavaExternalDocumentationTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/JavaExternalDocumentationTest.java index 3f3524c89f9b..87ba7b66f9c5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/JavaExternalDocumentationTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/JavaExternalDocumentationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -150,12 +150,16 @@ public class JavaExternalDocumentationTest extends PlatformTestCase { } private String getDocumentationText(String sourceEditorText) throws Exception { + return getDocumentationText(myProject, sourceEditorText); + } + + public static String getDocumentationText(Project project, String sourceEditorText) throws Exception { int caretPosition = sourceEditorText.indexOf(EditorTestUtil.CARET_TAG); if (caretPosition >= 0) { sourceEditorText = sourceEditorText.substring(0, caretPosition) + sourceEditorText.substring(caretPosition + EditorTestUtil.CARET_TAG.length()); } - PsiFile psiFile = PsiFileFactory.getInstance(myProject).createFileFromText(JavaLanguage.INSTANCE, sourceEditorText); + PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText(JavaLanguage.INSTANCE, sourceEditorText); return getDocumentationText(psiFile, caretPosition); }