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 93be44e41110..aae25be3c49d 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java @@ -271,8 +271,8 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext PsiClass parentClass = method.getContainingClass(); - if (parentClass != null) { - if (method.isConstructor() && !(parentClass instanceof PsiAnonymousClass)) { + if (parentClass != null && !(parentClass instanceof PsiAnonymousClass)) { + if (method.isConstructor()) { generatePackageInfo(buffer, parentClass); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/JavaDocumentationTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/JavaDocumentationTest.groovy index 306367f6994b..d19a988f77b2 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-2012 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -26,7 +26,7 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase class JavaDocumentationTest extends LightCodeInsightFixtureTestCase { public void testConstructorDoc() { - myFixture.configureByText 'a.java', ''' + configure ''' class Foo { Foo() {} Foo(int param) {} } class Foo2 {{ @@ -43,7 +43,7 @@ class Foo2 {{ } public void testConstructorDoc2() { - myFixture.configureByText 'a.java', ''' + configure ''' class Foo { Foo() {} Foo(int param) {} } class Foo2 {{ @@ -62,7 +62,7 @@ class Foo2 {{ } public void testMethodDocWhenInArgList() { - myFixture.configureByText 'a.java', ''' + configure ''' class Foo { void doFoo() {} } class Foo2 {{ @@ -79,7 +79,7 @@ class Foo2 {{ } public void testGenericMethod() { - myFixture.configureByText 'a.java', ''' + configure ''' class Bar { java.util.List foo(T param); } class Foo {{ @@ -92,7 +92,7 @@ class Foo {{ } public void testGenericField() { - myFixture.configureByText 'a.java', ''' + configure ''' class Bar { T field; } class Foo {{ @@ -103,5 +103,24 @@ class Foo {{ assert CtrlMouseHandler.getInfo(ref.resolve(), ref.element) == """Bar java.lang.Integer field""" } + + public void testMethodInAnonymousClass() { + configure ''' +class Foo {{ + new Runnable() { + @Override + public void run() { + m(); + } + + private void m() {} + }.run(); +}} +''' + assert CtrlMouseHandler.getInfo(editor, CtrlMouseHandler.BrowseMode.Declaration) == "private void m ()" + } + private void configure(String text) { + myFixture.configureByText 'a.java', text + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java index b2eb7c3ea2f8..ea96905f470d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java @@ -113,7 +113,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { @Nullable private Point myPrevMouseLocation; private LightweightHint myHint; - private enum BrowseMode {None, Declaration, TypeDeclaration, Implementation} + public enum BrowseMode {None, Declaration, TypeDeclaration, Implementation} private final KeyListener myEditorKeyListener = new KeyAdapter() { @Override @@ -307,6 +307,17 @@ public class CtrlMouseHandler extends AbstractProjectComponent { return generateInfo(element, atPointer).text; } + @Nullable + @TestOnly + public static String getInfo(@NotNull Editor editor, BrowseMode browseMode) { + Project project = editor.getProject(); + if (project == null) return null; + PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); + if (file == null) return null; + Info info = getInfoAt(project, editor, file, editor.getCaretModel().getOffset(), browseMode); + return info == null ? null : info.getInfo().text; + } + @NotNull private static DocInfo generateInfo(PsiElement element, PsiElement atPointer) { final DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(element, atPointer); @@ -479,6 +490,12 @@ public class CtrlMouseHandler extends AbstractProjectComponent { @Nullable private Info getInfoAt(@NotNull final Editor editor, @NotNull PsiFile file, int offset, @NotNull BrowseMode browseMode) { + return getInfoAt(myProject, editor, file, offset, browseMode); + } + + @Nullable + private static Info getInfoAt(@NotNull Project project, @NotNull final Editor editor, @NotNull PsiFile file, int offset, + @NotNull BrowseMode browseMode) { PsiElement targetElement = null; if (browseMode == BrowseMode.TypeDeclaration) { @@ -486,7 +503,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { targetElement = GotoTypeDeclarationAction.findSymbolType(editor, offset); } catch (IndexNotReadyException e) { - showDumbModeNotification(myProject); + showDumbModeNotification(project); } } else if (browseMode == BrowseMode.Declaration) { @@ -494,7 +511,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { final List resolvedElements = ref == null ? Collections.emptyList() : resolve(ref); final PsiElement resolvedElement = resolvedElements.size() == 1 ? resolvedElements.get(0) : null; - final PsiElement[] targetElements = GotoDeclarationAction.findTargetElementsNoVS(myProject, editor, offset, false); + final PsiElement[] targetElements = GotoDeclarationAction.findTargetElementsNoVS(project, editor, offset, false); final PsiElement elementAtPointer = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), offset)); if (targetElements != null) {