summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManju Mathew2013-01-28 18:27:27 (EST)
committerMarkus Keller2013-01-28 18:27:27 (EST)
commite775f37ffdd45a30062233ba3bde2bd8c413bbd4 (patch)
tree31efbf8df4a68a1dc4440d909687b2c2fd3f14cf
parentfc51e8b5424920c03e3818b63be98a56aa3066c1 (diff)
downloadeclipse.jdt.ui-e775f37ffdd45a30062233ba3bde2bd8c413bbd4.zip
eclipse.jdt.ui-e775f37ffdd45a30062233ba3bde2bd8c413bbd4.tar.gz
eclipse.jdt.ui-e775f37ffdd45a30062233ba3bde2bd8c413bbd4.tar.bz2
Bug 397465: [hovering] Open Declaration doesn't work in Javadoc hover on IPackageFragmentv20130128-232727I20130129-0800I20130128-2000
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java5
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java44
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OpenAction.java65
3 files changed, 99 insertions, 15 deletions
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java
index babacaa..e265b91 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java
@@ -1109,8 +1109,7 @@ public class JavadocView extends AbstractInfoView {
if (SourceRange.isAvailable(nameRange)) {
ITypeRoot typeRoot= (ITypeRoot) ((IPackageDeclaration) curr).getParent();
Region hoverRegion= new Region(nameRange.getOffset(), nameRange.getLength());
- buffer.append("<br>"); //$NON-NLS-1$
- JavadocHover.addAnnotations(buffer, curr, typeRoot, hoverRegion);
+ JavadocHover.addAnnotations(buffer, typeRoot.getParent(), typeRoot, hoverRegion);
}
} catch (JavaModelException e) {
// no annotations this time...
@@ -1620,7 +1619,7 @@ public class JavadocView extends AbstractInfoView {
*/
public void handleDeclarationLink(IJavaElement target) {
try {
- JavaUI.openInEditor(target);
+ JavadocHover.openDeclaration(target);
} catch (PartInitException e) {
JavaPlugin.log(e);
} catch (JavaModelException e) {
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java
index 786245c..b967a89 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java
@@ -30,6 +30,8 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.resources.IFile;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.internal.text.html.BrowserInformationControl;
@@ -109,6 +111,8 @@ import org.eclipse.jdt.internal.ui.actions.OpenBrowserUtil;
import org.eclipse.jdt.internal.ui.actions.SimpleSelectionProvider;
import org.eclipse.jdt.internal.ui.infoviews.JavadocView;
import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks;
@@ -256,7 +260,7 @@ public class JavadocHover extends AbstractJavaEditorTextHover {
try {
//FIXME: add hover location to editor navigation history?
- JavaUI.openInEditor(infoInput.getElement());
+ openDeclaration(infoInput.getElement());
} catch (PartInitException e) {
JavaPlugin.log(e);
} catch (JavaModelException e) {
@@ -485,6 +489,42 @@ public class JavadocHover extends AbstractJavaEditorTextHover {
return fHoverControlCreator;
}
+
+ public static IEditorPart openDeclaration(IJavaElement element) throws PartInitException, JavaModelException {
+ if (!(element instanceof IPackageFragment)) {
+ return JavaUI.openInEditor(element);
+ }
+
+ IPackageFragment packageFragment= (IPackageFragment) element;
+ ITypeRoot typeRoot;
+ IPackageFragmentRoot root= (IPackageFragmentRoot) packageFragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+ if (root.getKind() == IPackageFragmentRoot.K_BINARY) {
+ typeRoot= packageFragment.getClassFile(JavaModelUtil.PACKAGE_INFO_CLASS);
+ } else {
+ typeRoot= packageFragment.getCompilationUnit(JavaModelUtil.PACKAGE_INFO_JAVA);
+ }
+
+ // open the package-info file in editor if one exists
+ if (typeRoot.exists())
+ return JavaUI.openInEditor(typeRoot);
+
+ // open the package.html file in editor if one exists
+ Object[] nonJavaResources= packageFragment.getNonJavaResources();
+ for (Object nonJavaResource : nonJavaResources) {
+ if (nonJavaResource instanceof IFile) {
+ IFile file= (IFile) nonJavaResource;
+ if (file.exists() && JavaModelUtil.PACKAGE_HTML.equals(file.getName())) {
+ return EditorUtility.openInEditor(file, true);
+ }
+ }
+ }
+
+ // select the package in the Package Explorer if there is no associated package Javadoc file
+ PackageExplorerPart view= (PackageExplorerPart) JavaPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
+ view.tryToReveal(packageFragment);
+ return null;
+ }
+
private static void addLinkListener(final BrowserInformationControl control) {
control.addLocationListener(JavaElementLinks.createLocationListener(new JavaElementLinks.ILinkHandler() {
/* (non-Javadoc)
@@ -521,7 +561,7 @@ public class JavadocHover extends AbstractJavaEditorTextHover {
control.dispose(); //FIXME: should have protocol to hide, rather than dispose
try {
//FIXME: add hover location to editor navigation history?
- JavaUI.openInEditor(linkTarget);
+ openDeclaration(linkTarget);
} catch (PartInitException e) {
JavaPlugin.log(e);
} catch (JavaModelException e) {
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OpenAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OpenAction.java
index bf867c7..dfe9a19 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OpenAction.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OpenAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -38,6 +38,8 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.IEditorStatusLine;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceReference;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaModelException;
@@ -56,6 +58,7 @@ import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
import org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlinkDetector;
+import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
import org.eclipse.jdt.internal.ui.search.IOccurrencesFinder.OccurrenceLocation;
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
@@ -166,9 +169,12 @@ public class OpenAction extends SelectionDispatchAction {
IJavaElement element= elements[0];
if (elements.length > 1) {
- element= SelectionConverter.selectJavaElement(elements, getShell(), getDialogTitle(), ActionMessages.OpenAction_select_element);
- if (element == null)
- return;
+ // If there are multiple IPackageFragments that could be selected, use the first one on the build path.
+ if (!(element instanceof IPackageFragment)) {
+ element= SelectionConverter.selectJavaElement(elements, getShell(), getDialogTitle(), ActionMessages.OpenAction_select_element);
+ if (element == null)
+ return;
+ }
}
run(new Object[] {element} );
@@ -205,7 +211,6 @@ public class OpenAction extends SelectionDispatchAction {
IJavaElement element= elements[i];
switch (element.getElementType()) {
case IJavaElement.PACKAGE_DECLARATION:
- case IJavaElement.PACKAGE_FRAGMENT:
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
case IJavaElement.JAVA_PROJECT:
case IJavaElement.JAVA_MODEL:
@@ -244,11 +249,26 @@ public class OpenAction extends SelectionDispatchAction {
for (int i= 0; i < elements.length; i++) {
Object element= elements[i];
try {
- element= getElementToOpen(element);
- boolean activateOnOpen= fEditor != null ? true : OpenStrategy.activateOnOpen();
- IEditorPart part= EditorUtility.openInEditor(element, activateOnOpen);
- if (part != null && element instanceof IJavaElement)
- JavaUI.revealInEditor(part, (IJavaElement)element);
+ Object javaElement= getElementToOpen(element);
+ if (javaElement instanceof IPackageFragment) {
+ if (fEditor == null) {
+ try {
+ PackageExplorerPart view= (PackageExplorerPart) JavaPlugin.getActivePage().showView(JavaUI.ID_PACKAGES);
+ view.tryToReveal(element);
+ } catch (PartInitException e) {
+ JavaPlugin.log(e);
+ }
+ } else {
+ setStatusLineMessage();
+ return;
+ }
+
+ } else {
+ boolean activateOnOpen= fEditor != null ? true : OpenStrategy.activateOnOpen();
+ IEditorPart part= EditorUtility.openInEditor(javaElement, activateOnOpen);
+ if (part != null && javaElement instanceof IJavaElement)
+ JavaUI.revealInEditor(part, (IJavaElement) javaElement);
+ }
} catch (PartInitException e) {
String message= Messages.format(ActionMessages.OpenAction_error_problem_opening_editor, new String[] { JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_DEFAULT), e.getStatus().getMessage() });
status.add(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, message, null));
@@ -274,9 +294,34 @@ public class OpenAction extends SelectionDispatchAction {
* @noreference This method is not intended to be referenced by clients.
*/
public Object getElementToOpen(Object object) throws JavaModelException {
+ if (object instanceof IPackageFragment) {
+ return getPackageFragmentObjectToOpen((IPackageFragment) object);
+ }
return object;
}
+ private Object getPackageFragmentObjectToOpen(IPackageFragment packageFragment) throws JavaModelException {
+ ITypeRoot typeRoot= null;
+ IPackageFragmentRoot root= (IPackageFragmentRoot) packageFragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+ if (root.getKind() == IPackageFragmentRoot.K_BINARY)
+ typeRoot= (packageFragment).getClassFile(JavaModelUtil.PACKAGE_INFO_CLASS);
+ else
+ typeRoot= (packageFragment).getCompilationUnit(JavaModelUtil.PACKAGE_INFO_JAVA);
+ if (typeRoot.exists())
+ return typeRoot;
+
+ Object[] nonJavaResources= (packageFragment).getNonJavaResources();
+ for (Object nonJavaResource : nonJavaResources) {
+ if (nonJavaResource instanceof IFile) {
+ IFile file= (IFile) nonJavaResource;
+ if (file.exists() && JavaModelUtil.PACKAGE_HTML.equals(file.getName())) {
+ return file;
+ }
+ }
+ }
+ return packageFragment;
+ }
+
private String getDialogTitle() {
return ActionMessages.OpenAction_error_title;
}