You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "NicolaIsotta (via GitHub)" <gi...@apache.org> on 2025/07/09 15:53:50 UTC

[PR] Fix "Show Javadoc" menu item for classes inside modulare maven dependecies [netbeans]

NicolaIsotta opened a new pull request, #8642:
URL: https://github.com/apache/netbeans/pull/8642

   To reproduce:
   
   1. create a java maven project
   2. add jakarta.servlet-api as a dependency, the version is not important
   3. from the project tab, expand the "Dependecies" node
   4. Right click the jakarta.servlet-api node and click "Download Javadoc"
   5. Open the node, open a package and right click a .class file
   6. Choose "Show Javadoc" from the context menu
   
   A toast notification will appear, stating the no javadoc was found.
   
   I'm not sure if the way I chose is the right one, but it works: not to reinvent the wheel, this PR uses [JavadocHelper](https://github.com/apache/netbeans/blob/master/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java) via [SourceUtils](https://github.com/apache/netbeans/blob/master/java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java)
   
   
   ---
   **^Add meaningful description above**
   
   <details open>
   <summary>Click to collapse/expand PR instructions</summary>
   
   By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
   
    - are all your own work, and you have the right to contribute them.
    - are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).
   
   Please make sure (eg. `git log`) that all commits have a valid name and email address for you in the Author field.
   
   If you're a first time contributor, see the Contributing guidelines for more information.
   
   If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
   
   ### PR approval and merge checklist:
   
   1. [ ] Was this PR [correctly labeled](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=240884239#PRsandYouAreviewerGuide-PRtriggeredCIJobs(conditionalCIpipeline)), did the right tests run? When did they run?
   8. [ ] Is this PR [squashed](https://cwiki.apache.org/confluence/display/NETBEANS/git%3A+squash+and+merge)?
   9. [ ] Are author name / email address correct? Are [co-authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line) correctly listed? Do the commit messages need updates?
   3. [ ] Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?
   
   If this PR targets the delivery branch: [don't merge](https://cwiki.apache.org/confluence/display/NETBEANS/Pull+requests+for+delivery). ([full wiki article](https://cwiki.apache.org/confluence/display/NETBEANS/PRs+and+You+-+A+reviewer+Guide))
   
   </details>


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "NicolaIsotta (via GitHub)" <gi...@apache.org>.
NicolaIsotta commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3355142914

   Yep, 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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "NicolaIsotta (via GitHub)" <gi...@apache.org>.
NicolaIsotta commented on code in PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#discussion_r2197252046


##########
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:
   Reverted



-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3135000032

   this PR came up on slack as candidate for last minute inclusion in NB 27 rc2. I am going to move the commit to the delivery branch, set target to delivery and force push into the PR branch so that things are ready.
   
   adding do-not-merge until 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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien merged PR #8642:
URL: https://github.com/apache/netbeans/pull/8642


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "NicolaIsotta (via GitHub)" <gi...@apache.org>.
NicolaIsotta commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3307240717

   The classpath problem should be fixed now - it builds a classpath info with just the dependency jar. I tried switching dependency version and there's no caching issues.


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3067164376

   seems to work well for modular and not modular dependencies.
   
   Initially I thought it causes a regression for non-modular dependencies but silly me tried to open javadoc for the one class file which wasn't public.


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3067227710

   we have to think about this. This is essentially taking a shortcut to avoid using `JavadocForBinaryQuery.findJavadoc()` which is part of the `java/api.java` module and _should_ ideally also work.
   
   This could be fine or we could potentially try to improve the `findJavadoc()` query. Lets see what others say. cc @neilcsmith-net 


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3074275255

   > There might be other ways we could find the module name with the existing search pattern
   
   Actually, the right way to handle this might be to make use of the `element-list` file to work out what module a package is in?  eg. https://docs.oracle.com/en/java/javase/24/docs/api/element-list  The original loop in this might do that instead of parsing?  Also doing that in `JavadocHelper` might make it more robust in cases where the module name cannot be inferred.  See #4044 #4363 and #4391


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "NicolaIsotta (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3135865066

   OK, good catch!  Let's hold and rethink this.


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "NicolaIsotta (via GitHub)" <gi...@apache.org>.
NicolaIsotta closed pull request #8642: Fix "Show Javadoc" menu item for classes inside modular maven dependecies
URL: https://github.com/apache/netbeans/pull/8642


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3135847495

   this would be a regression unfortunately, since switching from `4.0.2` to `4.0.3` for example does open the javadoc correctly in NB 26.
   
   We might want to wait with this change after all, potentially some caching issue or so.


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3073119627

   @mbien `JavadocForBinaryQuery` is for finding the Javadoc root?  The assumption in the existing version of this code is how the Javadoc is structured inside that root?
   
   Is this method called on the EDT?  At least `getPreferredJavadoc` warns against doing that, although perhaps not too much of an issue in practice here.  And that whole `JavadocHelper` class is horrible, particularly the support for module names!


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "NicolaIsotta (via GitHub)" <gi...@apache.org>.
NicolaIsotta commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3083415259

   > Is this method called on the EDT? At least `getPreferredJavadoc` warns against doing that, although perhaps not too much of an issue in practice here?
   
   I wrapped `getPreferredJavadoc` inside a `RequestProcessor` call
   
   


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "NicolaIsotta (via GitHub)" <gi...@apache.org>.
NicolaIsotta commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3069112746

   From what I saw this SourceUtils uses JavadocForBinaryQuery under the hood.
   SourceUtils -> JavadocHelper -> JavadocForBinaryQuery
   https://github.com/apache/netbeans/blob/e8bc5c1c064d3f9c21fc00cdd1cb8e5d05a6269b/java/java.source.base/src/org/netbeans/modules/java/source/JavadocHelper.java#L772-L773


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3354313947

   sorry, I overlooked that this PR got updated, @NicolaIsotta could you rebase again to latest master? This would also produce a fresh dev build.


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#discussion_r2242568598


##########
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:
   this call will likely have to be moved back into `runUserActionTask`, since javac api is single threaded AFAIK:
   
   ```java
                               URL javadocUrl = SourceUtils.getPreferredJavadoc(element);
                               if (javadocUrl != null) {
                                   RP.post(() -> {
                                       HtmlBrowser.URLDisplayer.getDefault().showURL(javadocUrl);
                                   });
                               } else {
                                   StatusDisplayer.getDefault().setStatusText(ERR_No_Javadoc_Found(fil.getPath()));
                               }
   ```



##########
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);

Review Comment:
   `root` seems to be correct, but `cpInfo` returns some cached value which contains the outdated dependency.
   
   ```
                   System.out.println("->   "+root);
                   System.out.println("->   "+cpInfo.getClassPath(ClasspathInfo.PathKind.COMPILE));
   ```
   
   ```
   ->   AbstractFileObject@432bd603[root of /home/mbien/.m2/repository/jakarta/servlet/jakarta.servlet-api/4.0.3/jakarta.servlet-api-4.0.3.jar[org.openide.filesystems.JarFileSystem@5d21f28f]]
   ->   /home/mbien/NetBeansProjects/nb-reprorepo/performance/fields/target/test-classes:/home/mbien/NetBeansProjects/nb-reprorepo/performance/classes/target/classes:/tmp/mavenproject1/target/test-classes:/tmp/mavenproject1/target/classes:/home/mbien/NetBeansProjects/nb-reprorepo/performance/classes/target/test-classes:/home/mbien/NetBeansProjects/nb-reprorepo/performance/fields/target/classes:/home/mbien/.m2/repository/jakarta/servlet/jakarta.servlet-api/4.0.2/jakarta.servlet-api-4.0.2.jar
   
   ```
   after switch from 4.0.3 to 4.0.2.



-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] Fix "Show Javadoc" menu item for classes inside modular maven dependecies [netbeans]

Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #8642:
URL: https://github.com/apache/netbeans/pull/8642#issuecomment-3135834827

   seems to work but there is probably another problem somewhere.
   
   if you switch the dependency, it won't find the javadoc until the project is reopened or NB is restarted.
   
   try:
   ```xml
           <dependency>
               <groupId>jakarta.servlet</groupId>
               <artifactId>jakarta.servlet-api</artifactId>
               <version>4.0.2</version>
           </dependency>
   ```
   
   and open doc for `jakarta.servlet.AsyncContext` which should work
   
   now switch to:
   
   ```xml
           <dependency>
               <groupId>jakarta.servlet</groupId>
               <artifactId>jakarta.servlet-api</artifactId>
               <version>6.1.0</version>
           </dependency>
   ```
   
   and repeat and it doesn't work until project is reopened.


-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists