Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageHover/PackageJavadocTests.java39
-rw-r--r--org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java3
-rw-r--r--org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.properties3
-rw-r--r--org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java21
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java12
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java5
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java1
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties1
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java3
9 files changed, 72 insertions, 16 deletions
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageHover/PackageJavadocTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageHover/PackageJavadocTests.java
index f8c69ffec6..9ae5547fa3 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageHover/PackageJavadocTests.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageHover/PackageJavadocTests.java
@@ -229,7 +229,8 @@ public class PackageJavadocTests extends CoreTests {
Assert.assertTrue(actualHtmlContent.contains("Provides classes for performing arbitrary-precision integer arithmetic"));
} catch (Exception e) {
//there is no internet connection, so the Javadoc cannot be retrieved.
- Assert.assertTrue(actualHtmlContent.contains(CorextMessages.JavaDocLocations_noAttachedSource) || actualHtmlContent.contains(CorextMessages.JavaDocLocations_error_gettingJavadoc));
+ Assert.assertTrue(actualHtmlContent.contains(CorextMessages.JavaDocLocations_noAttachedSource) || actualHtmlContent.contains(CorextMessages.JavaDocLocations_error_gettingJavadoc)
+ || actualHtmlContent.contains(CorextMessages.JavaDocLocations_error_gettingAttachedJavadoc));
}
}
@@ -291,6 +292,42 @@ public class PackageJavadocTests extends CoreTests {
Assert.assertTrue(actualHtmlContent.contains(CorextMessages.JavaDocLocations_noAttachedJavadoc));
}
+ public void testErrotGettingAttachedJavadoc() throws Exception {
+ File junitSrcArchive= JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/PackageJavadocTests/JavadocHover_src.zip"));
+
+ assertTrue("junit src not found", junitSrcArchive != null && junitSrcArchive.exists());
+
+ JavaProjectHelper.addSourceContainerWithImport(fJProject1, "src", junitSrcArchive, JavaProjectHelper.JUNIT_SRC_ENCODING);
+ ICompilationUnit cu= (ICompilationUnit)fJProject1.findElement(new Path("junit/javadochoverhtml/JavaDocHoverTest.java"));
+ assertNotNull("JavaDocHoverTest.java", cu);
+
+ //set a wrong Javadoc location URL
+ IClasspathAttribute attribute=
+ JavaCore.newClasspathAttribute(
+ IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
+ "url:http://download.oracle.com/javase/6/docs/apii/");
+ IClasspathEntry[] rawClasspath= fJProject1.getRawClasspath();
+ IClasspathEntry newEntry= JavaCore.newLibraryEntry(new Path(JavaTestPlugin.getDefault().getFileInPlugin(new Path("/testresources/rtstubs15.jar")).getAbsolutePath()), null, null, null,
+ new IClasspathAttribute[] { attribute }, false);
+ rawClasspath[0]= newEntry;
+ IClasspathEntry[] newPathEntry= new IClasspathEntry[] { rawClasspath[0], rawClasspath[1] };
+ this.fJProject1.setRawClasspath(newPathEntry, null);
+ this.fJProject1.getResolvedClasspath(false);
+
+ int offset= cu.getSource().indexOf("java.math");
+ int length= "java.math".length();
+ IJavaElement[] codeSelect= cu.codeSelect(offset, length);
+ Assert.assertNotNull(codeSelect);
+ Assert.assertTrue("No package found !", codeSelect.length > 0);
+
+ JavadocBrowserInformationControlInput hoverInfo= JavadocHover.getHoverInfo(codeSelect, cu, new Region(offset, length), null);
+ String actualHtmlContent= hoverInfo.getHtml();
+ Assert.assertNotNull(actualHtmlContent);
+
+ Assert.assertTrue(actualHtmlContent.contains(CorextMessages.JavaDocLocations_error_gettingAttachedJavadoc));
+
+ }
+
public static Test setUpTest(Test test) {
return new ProjectTestSetup(test);
}
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java
index 338adbdfc2..365b0da6a5 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 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
@@ -26,6 +26,7 @@ public final class CorextMessages extends NLS {
public static String Resources_fileModified;
public static String JavaDocLocations_migrate_operation;
+ public static String JavaDocLocations_error_gettingAttachedJavadoc;
public static String JavaDocLocations_error_gettingJavadoc;
public static String JavaDocLocations_error_readXML;
public static String JavaDocLocations_migratejob_name;
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.properties b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.properties
index 7801e94174..5a99503045 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.properties
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/CorextMessages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2012 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
@@ -14,6 +14,7 @@ Resources_modifiedResources= There are modified resources
Resources_fileModified= File ''{0}'' has been modified since the beginning of the operation
JavaDocLocations_migrate_operation=Migrate Javadoc locations to build path attributes...
+JavaDocLocations_error_gettingAttachedJavadoc=<em>Note: The attached Javadoc could not be retrieved as the specified Javadoc location is either wrong or currently not accessible.</em>
JavaDocLocations_error_gettingJavadoc=<em>Note: An exception occurred while getting the Javadoc. See log for details.</em>
JavaDocLocations_error_readXML=Problems while reading the Javadoc locations from XML
JavaDocLocations_migratejob_name=Migrate Javadoc locations to build path attributes
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java
index 28a54806c8..71aa8b7922 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/javadoc/JavaDocLocations.java
@@ -67,6 +67,7 @@ import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IImportDeclaration;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaModelStatusConstants;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
@@ -670,6 +671,26 @@ public class JavaDocLocations {
}
/**
+ * Handles the exception thrown from <code>org.eclipse.jdt.core</code> when the attached Javadoc
+ * cannot be retrieved due to accessibility issues or location URL issue. This exception is not
+ * logged but the exceptions occurred due to other reasons are logged.
+ *
+ * @param e the exception thrown when retrieving the Javadoc fails
+ * @return the String message for why the Javadoc could not be retrieved
+ */
+ public static String handleFailedJavadocFetch(CoreException e) {
+ //filter the exception thrown from JavaElement while trying to fetch the attached Javadoc
+ if (e.getCause() instanceof IOException) {
+ IStatus status= e.getStatus();
+ if (status.getCode() == IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC && JavaCore.PLUGIN_ID.equals(status.getPlugin())) {
+ return CorextMessages.JavaDocLocations_error_gettingAttachedJavadoc;
+ }
+ }
+ JavaPlugin.log(e);
+ return CorextMessages.JavaDocLocations_error_gettingJavadoc;
+ }
+
+ /**
* Parse a URL from a String. This method first tries to treat <code>url</code> as a valid, encoded URL.
* If that didn't work, it tries to recover from bad URLs, e.g. the unencoded form we used to use in persistent storage.
*
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 7a11720dd7..4c0a811bc8 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
@@ -465,7 +465,7 @@ public class JavadocView extends AbstractInfoView {
private LinkAction fToggleLinkAction;
/**
- * Action to open the attached Javadoc.
+ * Action to open the attached Javadoc.
* @since 3.4
*/
private OpenInBrowserAction fOpenBrowserAction;
@@ -1081,8 +1081,7 @@ public class JavadocView extends AbstractInfoView {
content= JavadocContentAccess2.getHTMLContent((IPackageFragment) curr);
}
} catch (CoreException e) {
- reader= new StringReader(InfoViewMessages.JavadocView_error_gettingJavadoc);
- JavaPlugin.log(e);
+ reader= new StringReader(JavaDocLocations.handleFailedJavadocFetch(e));
}
IPackageFragmentRoot root= (IPackageFragmentRoot) curr.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
try {
@@ -1090,7 +1089,7 @@ public class JavadocView extends AbstractInfoView {
if (content != null) {
base= JavaDocLocations.getBaseURL(curr, isBinary);
reader= new StringReader(content);
- } else {
+ } else if (reader == null) {
String explanationForMissingJavadoc= JavaDocLocations.getExplanationForMissingJavadoc(curr, root);
if (explanationForMissingJavadoc != null) {
reader= new StringReader(explanationForMissingJavadoc);
@@ -1141,8 +1140,7 @@ public class JavadocView extends AbstractInfoView {
}
}
} catch (JavaModelException ex) {
- reader= new StringReader(InfoViewMessages.JavadocView_error_gettingJavadoc);
- JavaPlugin.log(ex.getStatus());
+ reader= new StringReader(JavaDocLocations.handleFailedJavadocFetch(ex));
}
if (reader != null) {
HTMLPrinter.addParagraph(buffer, reader);
@@ -1242,7 +1240,7 @@ public class JavadocView extends AbstractInfoView {
@Override
protected IJavaElement findSelectedJavaElement(IWorkbenchPart part, ISelection selection) {
IJavaElement element= super.findSelectedJavaElement(part, selection);
- try {
+ try {
//update the Javadoc view when package.html is selected in project explorer view
if (element == null && selection instanceof IStructuredSelection) {
Object selectedElement= ((IStructuredSelection) selection).getFirstElement();
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java
index 51305ace00..eaaa8a9405 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ProposalInfo.java
@@ -19,7 +19,8 @@ import org.eclipse.jdt.core.IPackageDeclaration;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations;
+
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
@@ -75,7 +76,7 @@ public class ProposalInfo {
final IJavaElement javaElement= getJavaElement();
return extractJavadoc(javaElement);
} catch (CoreException e) {
- JavaPlugin.log(e);
+ JavaDocLocations.handleFailedJavadocFetch(e);
}
return null;
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java
index af4b4f0a06..d5d377f43a 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.java
@@ -32,7 +32,6 @@ final class JavaHoverMessages extends NLS {
public static String JavadocHover_back;
public static String JavadocHover_back_toElement_toolTip;
public static String JavadocHover_constantValue_hexValue;
- public static String JavadocHover_error_gettingJavadoc;
public static String JavadocHover_forward;
public static String JavadocHover_forward_toElement_toolTip;
public static String JavadocHover_forward_toolTip;
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties
index 6765a2ec9b..7201da407f 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaHoverMessages.properties
@@ -25,7 +25,6 @@ JavadocHover_back= Back
JavadocHover_back_toElement_toolTip=Back to {0}
# The first parameter is the constant value string and the second is its hex representation
JavadocHover_constantValue_hexValue={0} [{1}]
-JavadocHover_error_gettingJavadoc= <em>Note: An exception occurred while getting the Javadoc. See log for details.</em>
JavadocHover_forward= Forward
JavadocHover_forward_toElement_toolTip=Forward to {0}
JavadocHover_forward_toolTip=Forward
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 b70fbb9973..b0e49f9c82 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
@@ -704,8 +704,7 @@ public class JavadocHover extends AbstractJavaEditorTextHover {
reader= new StringReader(explanationForMissingJavadoc);
}
} catch (CoreException ex) {
- reader= new StringReader(JavaHoverMessages.JavadocHover_error_gettingJavadoc);
- JavaPlugin.log(ex);
+ reader= new StringReader(JavaDocLocations.handleFailedJavadocFetch(ex));
}
if (reader != null) {

Back to the top