This is an automated email from the ASF dual-hosted git repository.
neilcsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 65eee6b93c Fix missing module name in Javadoc URLs for Show Javadoc,
etc.
new 5ef781bbba Merge pull request #4363 from neilcsmith-net/javadoc-jpms
65eee6b93c is described below
commit 65eee6b93c974dc6657ceae979cd50bdc67fd578
Author: Neil C Smith <[email protected]>
AuthorDate: Mon Jul 11 17:11:16 2022 +0100
Fix missing module name in Javadoc URLs for Show Javadoc, etc.
---
.../modules/java/source/JavadocHelper.java | 71 ++++++++++++++++------
1 file changed, 52 insertions(+), 19 deletions(-)
diff --git
a/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java
b/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java
index c0db82ecd2..070d925daf 100644
---
a/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java
+++
b/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java
@@ -57,6 +57,8 @@ import java.util.logging.Logger;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.Name;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
@@ -578,6 +580,7 @@ public class JavadocHelper {
throw new IllegalArgumentException("Cannot pass null as an
argument of the SourceUtils.getJavadoc"); // NOI18N
}
ClassSymbol clsSym = null;
+ String moduleName = null;
String pkgName;
String pageName;
boolean buildFragment = false;
@@ -592,6 +595,7 @@ public class JavadocHelper {
if (clsSym == null) {
return Collections.emptyList();
}
+ moduleName = moduleNameFor(element);
pkgName = FileObjects.convertPackage2Folder(((PackageElement)
element).getQualifiedName().toString());
pageName = PACKAGE_SUMMARY;
} else if (element.getKind() == ElementKind.MODULE) {
@@ -615,6 +619,7 @@ public class JavadocHelper {
if (clsSym == null) {
return Collections.emptyList();
}
+ moduleName = moduleNameFor(e);
pkgName = FileObjects.convertPackage2Folder(((PackageElement)
e).getQualifiedName().toString());
pageName = sb.toString();
buildFragment = element != clsSym;
@@ -626,6 +631,7 @@ public class JavadocHelper {
if (clsSym.classfile != null) {
try {
final URL classFile = clsSym.classfile.toUri().toURL();
+ final String moduleNameF = moduleName;
final String pkgNameF = pkgName;
final String pageNameF = pageName;
final Collection<? extends CharSequence> fragment =
buildFragment ? getFragment(element) : Collections.<CharSequence>emptySet();
@@ -633,7 +639,7 @@ public class JavadocHelper {
@Override
@NonNull
public List<TextStream> call() throws Exception {
- return findJavadoc(classFile, pkgNameF, pageNameF,
fragment, remoteJavadocPolicy);
+ return findJavadoc(classFile, moduleNameF, pkgNameF,
pageNameF, fragment, remoteJavadocPolicy);
}
};
final boolean sync = cancel == null || remoteJavadocPolicy !=
RemoteJavadocPolicy.USE;
@@ -676,9 +682,26 @@ public class JavadocHelper {
private static final String PACKAGE_SUMMARY = "package-summary"; // NOI18N
+ private static String moduleNameFor(Element element) {
+ Element e = element;
+ while (e != null && e.getKind() != ElementKind.MODULE) {
+ e = element.getEnclosingElement();
+ }
+ if (e == null) {
+ return null;
+ }
+ String name = ((ModuleElement) e).getQualifiedName().toString();
+ if (!name.isEmpty()) {
+ return name;
+ } else {
+ return null;
+ }
+ }
+
@NonNull
private static List<TextStream> findJavadoc(
@NonNull final URL classFile,
+ final String moduleName,
@NonNull final String pkgName,
@NonNull final String pageName,
@NonNull final Collection<? extends CharSequence> fragment,
@@ -762,7 +785,12 @@ binRoots: for (URL binary : binaries) {
throw new
IllegalArgumentException(remoteJavadocPolicy.name());
}
}
- URL url = new URL(root, pkgName + "/" + pageName +
".html");
+ URL url;
+ if (moduleName != null) {
+ url = new URL(root, moduleName + "/" + pkgName + "/" +
pageName + ".html");
+ } else {
+ url = new URL(root, pkgName + "/" + pageName +
".html");
+ }
InputStream is = null;
String rootS = root.toString();
boolean useKnownGoodRoots = result.length == 1 && isRemote;
@@ -775,25 +803,30 @@ binRoots: for (URL binary : binaries) {
} catch (InterruptedIOException iioe) {
throw iioe;
} catch (IOException x) {
- // Some libraries like OpenJFX prefix their
- // javadoc by module, similar to the JDK.
- // Only search there when the default fails
- // to avoid additional I/O.
- // NOTE: No multi-release jar support for now.
- URL moduleInfo = new URL(binary,
"module-info.class");
- try (InputStream classData =
moduleInfo.openStream()) {
- ClassFile clazz = new ClassFile(classData,
false);
- Module module = clazz.getModule();
- if (module == null) {
- throw x;
- }
- String moduleName = module.getName();
- if (moduleName == null) {
- throw x;
+ if (moduleName == null) {
+ // Some libraries like OpenJFX prefix their
+ // javadoc by module, similar to the JDK.
+ // Only search there when the default fails
+ // to avoid additional I/O.
+ // NOTE: No multi-release jar support for
now.
+ URL moduleInfo = new URL(binary,
"module-info.class");
+ try (InputStream classData =
moduleInfo.openStream()) {
+ ClassFile clazz = new
ClassFile(classData, false);
+ Module module = clazz.getModule();
+ if (module == null) {
+ throw x;
+ }
+ String modName = module.getName();
+ if (modName == null) {
+ throw x;
+ }
+ url = new URL(root, modName + "/" +
pkgName + "/" + pageName + ".html");
}
- url = new URL(root, moduleName + "/" +
pkgName + "/" + pageName + ".html");
- is = openStream(url,
Bundle.LBL_HTTPJavadocDownload());
+ } else {
+ // fallback to without module name
+ url = new URL(root, pkgName + "/" +
pageName + ".html");
}
+ is = openStream(url,
Bundle.LBL_HTTPJavadocDownload());
}
if (useKnownGoodRoots) {
knownGoodRoots.add(rootS);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists