Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract source name from .class and use it to locate proper source #5152

Merged

Conversation

jtulach
Copy link
Contributor

@jtulach jtulach commented Dec 26, 2022

I am working on a code base that is mixing Scala and Java. 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.

@jtulach jtulach self-assigned this Dec 26, 2022
@jtulach jtulach added the ci:all-tests [ci] enable all tests label Dec 30, 2022
@mbien mbien added the Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) label Dec 30, 2022
@jlahoda
Copy link
Contributor

jlahoda commented Jan 1, 2023

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

@jtulach jtulach force-pushed the jtulach/ExtractSourceNameForClassFile branch from 1aa6b0f to 1ad59dc Compare January 8, 2023 16:34
Copy link
Contributor

@jlahoda jlahoda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me.

@jtulach
Copy link
Contributor Author

jtulach commented Jan 9, 2023

SourceUtilsTest was executed without error. GoToSupportFileNameTest was executed without errors. Merging.

@jtulach jtulach merged commit 2a9e190 into apache:master Jan 9, 2023
@mbien mbien added this to the NB17 milestone Jan 9, 2023
@matthiasblaesing
Copy link
Contributor

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.

@matthiasblaesing
Copy link
Contributor

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

@neilcsmith-net
Copy link
Member

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

matthiasblaesing added a commit to matthiasblaesing/netbeans that referenced this pull request Jan 11, 2023
…r source" (apache#5152)

Revert "Removing unused import"

This reverts commit 1ad59dc.

Revert "Introducing SourceUtils.findSourceFileName method that needs no reflection"

This reverts commit e7d5437.

Revert "Use the suggested names also when navigating via LSP in VSCode"

This reverts commit 7e73d76.

Revert "Extracts source name from .class and uses it to locate proper source file in ElementOpen.open"

This reverts commit 93f6c38.

Closes: apache#5266
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:all-tests [ci] enable all tests Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants