NicolaIsotta commented on code in PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#discussion_r2197252752
##########
java/maven/src/org/netbeans/modules/maven/nodes/DependencyNode.java:
##########
@@ -1425,43 +1426,38 @@ public void actionPerformed(ActionEvent e) {
FileObject jar = FileUtil.getArchiveFile(fil);
FileObject root = FileUtil.getArchiveRoot(jar);
String rel = FileUtil.getRelativePath(root, fil);
- rel = rel.replaceAll("[.]class$", ".html"); //NOI18N
- JavadocForBinaryQuery.Result res =
JavadocForBinaryQuery.findJavadoc(root.toURL());
- if (fil.isFolder()) {
- rel = rel + "/package-summary.html"; //NOI18N
+ if (rel == null) {
+ return;
}
- URL javadocUrl = findJavadoc(rel, res.getRoots());
- if (javadocUrl != null) {
- HtmlBrowser.URLDisplayer.getDefault().showURL(javadocUrl);
- } else {
-
StatusDisplayer.getDefault().setStatusText(ERR_No_Javadoc_Found(fil.getPath()));
+ if (rel.endsWith(".class")) {
+ rel = rel.substring(0, rel.length() - 6);
}
- }
-
- /**
- * Locates a javadoc page by a relative name and an array of
javadoc roots
- * @param resource the relative name of javadoc page
- * @param urls the array of javadoc roots
- * @return the URL of found javadoc page or null if there is no
such a page.
- */
- URL findJavadoc(String resource, URL[] urls) {
- for (int i = 0; i < urls.length; i++) {
- String base = urls[i].toExternalForm();
- if (!base.endsWith("/")) { // NOI18N
- base = base + "/"; // NOI18N
- }
- try {
- URL u = new URL(base + resource);
- FileObject fo = URLMapper.findFileObject(u);
- if (fo != null) {
- return u;
+ String fqn = rel.replace('/', '.');
+ ClasspathInfo cpInfo = ClasspathInfo.create(root);
+ JavaSource js = JavaSource.create(cpInfo);
+ try {
+ js.runUserActionTask(cc -> {
+ cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
+ Elements elements = cc.getElements();
+ Element element;
+ if (fil.isFolder()) {
+ element = elements.getPackageElement(fqn);
+ } else {
+ element = elements.getTypeElement(fqn);
}
- } catch (MalformedURLException ex) {
-//
ErrorManager.getDefault().log(ErrorManager.ERROR, "Cannot create URL for
"+base+resource+". "+ex.toString()); //NOI18N
- continue;
- }
+ if (element != null) {
+ URL javadocUrl =
SourceUtils.getPreferredJavadoc(element);
+ if (javadocUrl != null) {
+
HtmlBrowser.URLDisplayer.getDefault().showURL(javadocUrl);
+ return;
+ }
+ }
+
StatusDisplayer.getDefault().setStatusText(ERR_No_Javadoc_Found(fil.getPath()));
+ }, true);
+ } catch (IOException ioex) {
+
}
Review Comment:
Done!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
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