neilcsmith-net commented on code in PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#discussion_r2242707348


##########
java/maven/src/org/netbeans/modules/maven/nodes/DependencyNode.java:
##########
@@ -1425,43 +1428,42 @@ 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('/', '.').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) {
+                            RP.post(() -> {
+                                URL javadocUrl = 
SourceUtils.getPreferredJavadoc(element);

Review Comment:
   Probably need to run everything off the EDT. However, if we're not rushing 
to get this in, I think we should consider moving this all into SourceUtils and 
an overload that accepts a FQN directly.



-- 
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

Reply via email to