Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikael Sterner2021-02-19 13:49:36 +0000
committerAndrey Loskutov2021-02-22 13:51:55 +0000
commit3028abcf84dcc0e5d7cee1ab71518b6b0ff89a11 (patch)
tree6900d09fcc7197a2c691c427e64185c09377dd35
parent8ffafc7925d1fa49a241aa8018a1432d5845cee8 (diff)
downloadeclipse.jdt.core-3028abcf84dcc0e5d7cee1ab71518b6b0ff89a11.tar.gz
eclipse.jdt.core-3028abcf84dcc0e5d7cee1ab71518b6b0ff89a11.tar.xz
eclipse.jdt.core-3028abcf84dcc0e5d7cee1ab71518b6b0ff89a11.zip
Bug 546945 - append module path to Javadoc URL for Java 11+I20210222-1800
Copy of the fix for bug 539684 for the Javadoc browser in JDT UI. Change-Id: Ibc5dd1e4ce1d95c313b1a09f6c15932632931879 Signed-off-by: Mikael Sterner <mikaels@comsol.se>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java15
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/bug546945.jarbin0 -> 1417 bytes
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/bug546945_doc.zipbin0 -> 2724 bytes
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java47
4 files changed, 62 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
index a15c877a84..a3db75e140 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
@@ -1361,5 +1361,20 @@ public class AttachedJavadocTests extends ModifyingResourceTests {
assertTrue("Should not happen", false);
}
}
+ public void testBug546945() throws JavaModelException {
+ IClasspathAttribute attribute =
+ JavaCore.newClasspathAttribute(
+ IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
+ "jar:platform:/resource/AttachedJavadocProject/bug546945_doc.zip!/");
+ IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path("/AttachedJavadocProject/bug546945.jar"), null, null, null, new IClasspathAttribute[] {attribute}, true);
+ this.project.setRawClasspath(new IClasspathEntry[]{newEntry}, null);
+ this.project.getResolvedClasspath(false);
+ this.project.setOption(JavaCore.COMPILER_COMPLIANCE, "11");
+
+ IPackageFragmentRoot jarRoot = this.project.getPackageFragmentRoot(getFile("/AttachedJavadocProject/bug546945.jar"));
+ IOrdinaryClassFile classFile = jarRoot.getPackageFragment("org.eclipse.pub").getOrdinaryClassFile("API.class");
+ String javadoc = classFile.getAttachedJavadoc(new NullProgressMonitor());
+ assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/bug546945.jar b/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/bug546945.jar
new file mode 100644
index 0000000000..b3cd3c674c
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/bug546945.jar
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/bug546945_doc.zip b/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/bug546945_doc.zip
new file mode 100644
index 0000000000..dd787596f9
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/AttachedJavadocProject/bug546945_doc.zip
Binary files differ
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java
index f7ccbe0f40..c8a50c9247 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java
@@ -29,6 +29,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo;
@@ -1083,6 +1084,7 @@ public JavadocContents getJavadocContents(IProgressMonitor monitor) throws JavaM
typeQualifiedName = getElementName();
}
+ appendModulePath(pack, pathBuffer);
pathBuffer.append(pack.getElementName().replace('.', '/')).append('/').append(typeQualifiedName).append(JavadocConstants.HTML_EXTENSION);
if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
final String contents = getURLContents(baseLocation, String.valueOf(pathBuffer));
@@ -1096,4 +1098,49 @@ public JavadocContents getJavadocContents(IProgressMonitor monitor) throws JavaM
public boolean isLambda() {
return false;
}
+
+private static void appendModulePath(IPackageFragment pack, StringBuffer buf) {
+ IModuleDescription moduleDescription= getModuleDescription(pack);
+ if (moduleDescription != null) {
+ String moduleName= moduleDescription.getElementName();
+ if (moduleName != null && moduleName.length() > 0) {
+ buf.append(moduleName);
+ buf.append('/');
+ }
+ }
+}
+
+private static IModuleDescription getModuleDescription(IPackageFragment pack) {
+ if (pack == null) {
+ return null;
+ }
+ IModuleDescription moduleDescription= null;
+ /*
+ * The Javadoc tool for Java SE 11 uses module name in the created URL.
+ * We can't know what format is required, so we just guess by the project's compiler compliance.
+ */
+ IJavaProject javaProject= pack.getJavaProject();
+ if (javaProject != null && isComplianceJava11OrHigher(javaProject)) {
+ if (pack.isReadOnly()) {
+ IPackageFragmentRoot root= (IPackageFragmentRoot) pack.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+ if (root != null) {
+ moduleDescription= root.getModuleDescription();
+ }
+ } else {
+ try {
+ moduleDescription= javaProject.getModuleDescription();
+ } catch (JavaModelException e) {
+ // do nothing
+ }
+ }
+ }
+ return moduleDescription;
+}
+
+private static boolean isComplianceJava11OrHigher(IJavaProject javaProject) {
+ if (javaProject == null) {
+ return false;
+ }
+ return CompilerOptions.versionToJdkLevel(javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true)) >= ClassFileConstants.JDK11;
+}
}

Back to the top