You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/12/26 11:25:03 UTC

[GitHub] [netbeans] jtulach opened a new pull request, #5152: Extract source name from .class and use it to locate proper source

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

   I am working on a code base that is mixing [Scala and Java](https://github.com/enso-org/enso/tree/develop/engine/runtime). Often Java sources are referencing Scala classes. I'd like the NetBeans IDE to work with it a bit. Luckily there is information in every `.class` file about the name of the source file it comes from. This PR extracts that information and passes it to `ElementOpen.open` to use it in case regular search method used for Java sources fails.
   
   With this PR I am able to jump from `.java` file to `.scala` file when Ctrl-Click on a class name.


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


[GitHub] [netbeans] matthiasblaesing commented on pull request #5152: Extract source name from .class and use it to locate proper source

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on PR #5152:
URL: https://github.com/apache/netbeans/pull/5152#issuecomment-1377994581

   This breaks java code editing! Steps to reproduce:
   
   1. Create a clone of the JNA repository. In a directory of your choosing run `git clone https://github.com/java-native-access/jna.git`
   2. In your NetBeans Source Tree go to the last commit before your merge: `git checkout c07ee007fd18`
   3. Ensure directory is clean: `git clean -f -x -d`
   4. Build: `ant`
   5. Run tryme: `ant tryme`
   6. Open the JNA NetBeans project from the folder you cloned in step 1.
   7. Open test file NativeLibraryTest.java (Package com.sun.jna), go to line 91, right click on `disposeAll`, choose  Navigate -> Goto Source
   8. Observe, that you are taken to the Method `disposeAll` in `NativeLibrary.java`
   9. Close NetBeans
   10. Checkout your merge commit: `git checkout 2a9e190afaf799bd0c126f0ffc6c70c9f0f9a305`
   11. Build: `ant`
   12. Run tryme: `ant tryme`
   13. Repeat Step 7
   14. Observe, that you are **not** taken to the source, but an exception is reported:
   ```
   java.lang.NullPointerException
   	at org.netbeans.api.java.source.SourceUtils$Match.apply(SourceUtils.java:686)
   	at org.netbeans.api.java.source.SourceUtils.findMatchingChild(SourceUtils.java:631)
   	at org.netbeans.api.java.source.SourceUtils.findSourceForBinary(SourceUtils.java:614)
   	at org.netbeans.api.java.source.SourceUtils.getFile(SourceUtils.java:582)
   	at org.netbeans.api.java.source.ui.ElementOpen.getOpenInfo(ElementOpen.java:444)
   	at org.netbeans.api.java.source.ui.ElementOpen.open(ElementOpen.java:125)
   	at org.netbeans.api.java.source.ui.ElementOpen.open(ElementOpen.java:120)
   	at org.netbeans.modules.editor.java.GoToSupport$7.open(GoToSupport.java:1263)
   	at org.netbeans.modules.editor.java.GoToSupport.performGoToImpl(GoToSupport.java:285)
   	at org.netbeans.modules.editor.java.GoToSupport.access$100(GoToSupport.java:125)
   	at org.netbeans.modules.editor.java.GoToSupport$3.run(GoToSupport.java:224)
   	at org.netbeans.modules.progress.ui.RunOffEDTImpl$1.run(RunOffEDTImpl.java:146)
   	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
   	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
   	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
   	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
   Caused: org.openide.util.RequestProcessor$SlowItem
   	at org.openide.util.RequestProcessor.post(RequestProcessor.java:395)
   	at org.netbeans.modules.progress.ui.RunOffEDTImpl.runOffEventDispatchThreadImpl(RunOffEDTImpl.java:140)
   	at org.netbeans.modules.progress.ui.RunOffEDTImpl.runOffEventDispatchThread(RunOffEDTImpl.java:83)
   	at org.netbeans.api.progress.BaseProgressUtils.runOffEventDispatchThread(BaseProgressUtils.java:90)
   	at org.netbeans.api.progress.ProgressUtils.runOffEventDispatchThread(ProgressUtils.java:68)
   	at org.netbeans.modules.editor.java.GoToSupport.performGoTo(GoToSupport.java:221)
   	at org.netbeans.modules.editor.java.GoToSupport.goTo(GoToSupport.java:389)
   	at org.netbeans.modules.editor.java.JavaKit$JavaGoToSourceAction.actionPerformed(JavaKit.java:731)
   	at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:322)
   	at org.netbeans.spi.editor.AbstractEditorAction.actionPerformed(AbstractEditorAction.java:445)
   	at org.netbeans.modules.editor.lib2.actions.PresenterUpdater.actionPerformed(PresenterUpdater.java:385)
   	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
   	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
   	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
   	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
   	at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:369)
   	at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1020)
   	at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1064)
   	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6635)
   	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
   	at java.desktop/java.awt.Component.processEvent(Component.java:6400)
   	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
   	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
   	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
   	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
   	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
   	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
   	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
   	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
   	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
   	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
   	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
   	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
   	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
   	at java.base/java.security.AccessController.doPrivileged(Native Method)
   	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
   	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
   	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
   	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
   	at java.base/java.security.AccessController.doPrivileged(Native Method)
   	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
   	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
   	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:136)
   	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
   	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
   	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
   	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
   	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
   [catch] at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
   ```
   
   As we are nearing code freeze, it would be good to fix this quickly. Thank you.


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


[GitHub] [netbeans] jtulach merged pull request #5152: Extract source name from .class and use it to locate proper source

Posted by GitBox <gi...@apache.org>.
jtulach merged PR #5152:
URL: https://github.com/apache/netbeans/pull/5152


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


[GitHub] [netbeans] jtulach commented on a diff in pull request #5152: Extract source name from .class and use it to locate proper source

Posted by GitBox <gi...@apache.org>.
jtulach commented on code in PR #5152:
URL: https://github.com/apache/netbeans/pull/5152#discussion_r1057432670


##########
java/java.editor/src/org/netbeans/modules/editor/java/GoToSupport.java:
##########
@@ -1193,47 +1204,60 @@ private void dumpArguments(List<? extends VariableElement> list, List<? extends
 
                 addSpace = true;
             }
-                
+
             result.append(')');
         }
 
         private void dumpThrows(List<? extends TypeMirror> list) {
             if (list.isEmpty()) {
                 return ;
             }
-            
+
             boolean addSpace = false;
-            
+
             result.append(" throws ");
-            
+
             for (TypeMirror t : list) {
                 if (addSpace) {
                     result.append(", ");
                 }
-                
+
                 result.append(getTypeName(info, t, true));
-                
+
                 addSpace = true;
             }
         }
-            
+
     }
-    
+
     private static String getTypeName(CompilationInfo info, TypeMirror t, boolean fqn) {
         return translate(Utilities.getTypeName(info, t, fqn).toString());
     }
-    
+
     private static String[] c = new String[] {"&", "<", ">", "\n", "\""}; // NOI18N
     private static String[] tags = new String[] {"&amp;", "&lt;", "&gt;", "<br>", "&quot;"}; // NOI18N
-    
+
     private static String translate(String input) {
         for (int cntr = 0; cntr < c.length; cntr++) {
             input = input.replace(c[cntr], tags[cntr]);
         }
-        
+
         return input;
     }
-    
+
+    static String findFileName(Element resolved) {

Review Comment:
   What's the right way to do this without reflection, @jlahoda?



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


[GitHub] [netbeans] matthiasblaesing commented on pull request #5152: Extract source name from .class and use it to locate proper source

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on PR #5152:
URL: https://github.com/apache/netbeans/pull/5152#issuecomment-1378009688

   Issue was filed as: #5152. There is also additional information with debug info.


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


[GitHub] [netbeans] jtulach commented on pull request #5152: Extract source name from .class and use it to locate proper source

Posted by GitBox <gi...@apache.org>.
jtulach commented on PR #5152:
URL: https://github.com/apache/netbeans/pull/5152#issuecomment-1375282635

   [SourceUtilsTest](https://github.com/apache/netbeans/actions/runs/3867982672/jobs/6598845149#step:25:2790) was executed without error. [GoToSupportFileNameTest](https://github.com/apache/netbeans/actions/runs/3867982672/jobs/6598845149#step:43:308) was executed without errors. Merging.


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


[GitHub] [netbeans] jlahoda commented on pull request #5152: Extract source name from .class and use it to locate proper source

Posted by GitBox <gi...@apache.org>.
jlahoda commented on PR #5152:
URL: https://github.com/apache/netbeans/pull/5152#issuecomment-1368377752

   Overall, seems reasonable to me. I guess I'd suggest to add a method to return a "source file name" into `SourceUtils`.


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


[GitHub] [netbeans] neilcsmith-net commented on pull request #5152: Extract source name from .class and use it to locate proper source

Posted by GitBox <gi...@apache.org>.
neilcsmith-net commented on PR #5152:
URL: https://github.com/apache/netbeans/pull/5152#issuecomment-1378640770

   @matthiasblaesing only glanced at this, but from the priority you've given the issue, IMO you should open a revert PR above that can be merged if the fix is not in place by Jan 17th.  We shouldn't branch with this problem.
   
   Also, issue filed is #5266 :wink:


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


[GitHub] [netbeans] jlahoda commented on a diff in pull request #5152: Extract source name from .class and use it to locate proper source

Posted by GitBox <gi...@apache.org>.
jlahoda commented on code in PR #5152:
URL: https://github.com/apache/netbeans/pull/5152#discussion_r1059718006


##########
java/java.editor/src/org/netbeans/modules/editor/java/GoToSupport.java:
##########
@@ -1193,47 +1204,60 @@ private void dumpArguments(List<? extends VariableElement> list, List<? extends
 
                 addSpace = true;
             }
-                
+
             result.append(')');
         }
 
         private void dumpThrows(List<? extends TypeMirror> list) {
             if (list.isEmpty()) {
                 return ;
             }
-            
+
             boolean addSpace = false;
-            
+
             result.append(" throws ");
-            
+
             for (TypeMirror t : list) {
                 if (addSpace) {
                     result.append(", ");
                 }
-                
+
                 result.append(getTypeName(info, t, true));
-                
+
                 addSpace = true;
             }
         }
-            
+
     }
-    
+
     private static String getTypeName(CompilationInfo info, TypeMirror t, boolean fqn) {
         return translate(Utilities.getTypeName(info, t, fqn).toString());
     }
-    
+
     private static String[] c = new String[] {"&", "<", ">", "\n", "\""}; // NOI18N
     private static String[] tags = new String[] {"&amp;", "&lt;", "&gt;", "<br>", "&quot;"}; // NOI18N
-    
+
     private static String translate(String input) {
         for (int cntr = 0; cntr < c.length; cntr++) {
             input = input.replace(c[cntr], tags[cntr]);
         }
-        
+
         return input;
     }
-    
+
+    static String findFileName(Element resolved) {

Review Comment:
   I suspect the best way would be to add an API method somewhere into java.source.base, returning a "source file name" for Elements that originate in a classfile - presumably, it could suggest it returns the value of the attribute. Or, vaguely speak about some "source file name", which could work for all Elements, whether form class or from source.
   
   `ElementUtilities` would normally be a fine place for a well-defined method, but I suspect this method may be a bit vague (and possibly single-purpose), so `SourceUtils` would sound better for a method like 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


[GitHub] [netbeans] jtulach commented on a diff in pull request #5152: Extract source name from .class and use it to locate proper source

Posted by GitBox <gi...@apache.org>.
jtulach commented on code in PR #5152:
URL: https://github.com/apache/netbeans/pull/5152#discussion_r1064114006


##########
java/java.editor/src/org/netbeans/modules/editor/java/GoToSupport.java:
##########
@@ -1193,47 +1204,60 @@ private void dumpArguments(List<? extends VariableElement> list, List<? extends
 
                 addSpace = true;
             }
-                
+
             result.append(')');
         }
 
         private void dumpThrows(List<? extends TypeMirror> list) {
             if (list.isEmpty()) {
                 return ;
             }
-            
+
             boolean addSpace = false;
-            
+
             result.append(" throws ");
-            
+
             for (TypeMirror t : list) {
                 if (addSpace) {
                     result.append(", ");
                 }
-                
+
                 result.append(getTypeName(info, t, true));
-                
+
                 addSpace = true;
             }
         }
-            
+
     }
-    
+
     private static String getTypeName(CompilationInfo info, TypeMirror t, boolean fqn) {
         return translate(Utilities.getTypeName(info, t, fqn).toString());
     }
-    
+
     private static String[] c = new String[] {"&", "<", ">", "\n", "\""}; // NOI18N
     private static String[] tags = new String[] {"&amp;", "&lt;", "&gt;", "<br>", "&quot;"}; // NOI18N
-    
+
     private static String translate(String input) {
         for (int cntr = 0; cntr < c.length; cntr++) {
             input = input.replace(c[cntr], tags[cntr]);
         }
-        
+
         return input;
     }
-    
+
+    static String findFileName(Element resolved) {

Review Comment:
   [e7d5437](https://github.com/apache/netbeans/pull/5152/commits/e7d543795366b9fc817b50973a698aa2e7ba4b26) introduces `SourceUtils.findSourceFileName` method.



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