mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-141078 "null" in Ctrl+hover quickdoc popup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T> { java.util.List<T> foo(T param); }
|
||||
|
||||
class Foo {{
|
||||
@@ -92,7 +92,7 @@ class Foo {{
|
||||
}
|
||||
|
||||
public void testGenericField() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
configure '''
|
||||
class Bar<T> { 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() {
|
||||
<caret>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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PsiElement> resolvedElements = ref == null ? Collections.<PsiElement>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) {
|
||||
|
||||
Reference in New Issue
Block a user