mbien commented on code in PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#discussion_r2195440981
##########
java/maven/src/org/netbeans/modules/maven/nodes/DependencyNode.java:
##########
@@ -1398,11 +1399,11 @@ private static class JarFilterNode extends FilterNode {
@Override
public Action[] getActions(boolean context) {
- List<Action> result = new ArrayList<Action>();
- result.addAll(Arrays.asList(super.getActions(false)));
+ List<Action> result = new ArrayList<>();
+ Collections.addAll(result, super.getActions(false));
Review Comment:
nitpick: I personally wouldn't change that to the `Collections` utility.
`asList` is a thin view around the array, passed to the list, the `List`
impl can decide how to append the elements to it.
Collections will add them one by one to a generic `Collection` impl.
##########
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:
I am not completely sure why `runUserActionTask` wraps exceptions in
`IOExceptions`, but we probably shouldn't leave this empty, given that this is
an UI action.
```
Exceptions.printStackTrace(ioex);
```
would display exceptions as notification.
--
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