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

Find/Replace overlay: move components into internal package #2013

Merged

Conversation

Wittmaxi
Copy link

@Wittmaxi Wittmaxi commented Jul 1, 2024

moves helper classes for the find/replace overlay into an internal package.

@Wittmaxi
Copy link
Author

Wittmaxi commented Jul 1, 2024

Extracted from #1990

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

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

Wouldn't it make sense to also move the FindReplaceOverlay to the org.eclipse.ui.internal.findandreplace.overlay package? Then the other classes could remain package protected, as they are only supposed to be used by the overlay class (and not any other class in the bundle).

@Wittmaxi
Copy link
Author

Wittmaxi commented Jul 1, 2024

@HeikoKlare
grafik

FindReplaceOverlay uses package-private methods of StatusTextEditor and for now, I don't want to touch StatusTextEditor. Also, since the Dialog is also in ui.texteditor, I believe it is best if (for now!) we keep the Overlay in ui.texteditor

@laeubi
Copy link
Contributor

laeubi commented Jul 1, 2024

@Wittmaxi by the way a good way to decouple things is usually using the Eclipse Adapters (e.g. implements IAdaptable) that way one often can get access to some things (e.g. a SourceViewer) by doing

Adapters.adapt(whatever, SourceViewer.class)

without need to call any methods directly on the target.

@HeikoKlare
Copy link
Contributor

I see. Then, however, I am not sure about the value of the proposed refactoring. What's the pain point in keeping the classes where they currently are? In particular, placing the overlay class in a different package than its first-time usage popup and it's images provider class does not look sound to me.

@Wittmaxi
Copy link
Author

Wittmaxi commented Jul 1, 2024

@HeikoKlare I am fine with moving these specific classes back. The reason I want to refactor these classes is that I am expecting many helper classes for the Overlay (For example in the PR adding a search-history) which are not really related to the texteditor-ui.
I understand that by putting the overlay away from it's helpers we reduce cohesion. I will try to use @laeubi 's advice using the adapters to call methods of the SourceViewer

@HeikoKlare
Copy link
Contributor

The reason I want to refactor these classes is that I am expecting many helper classes for the Overlay (For example in the PR adding a search-history) which are not really related to the texteditor-ui.

Thanks for the explanation. Now I understand.

Following the advice from @laeubi sounds good! The following should probably already do the trick:

   Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget();

@Wittmaxi
Copy link
Author

Wittmaxi commented Jul 1, 2024

@HeikoKlare yes! This works :)

Copy link
Contributor

github-actions bot commented Jul 1, 2024

Test Results

 1 815 files  ±0   1 815 suites  ±0   1h 35m 28s ⏱️ - 1m 15s
 7 663 tests ±0   7 435 ✅ ±0  228 💤 ±0  0 ❌ ±0 
24 150 runs  ±0  23 401 ✅ ±0  749 💤 ±0  0 ❌ ±0 

Results for commit 4276de4. ± Comparison against base commit 769d5d1.

This pull request removes 16 and adds 16 tests. Note that renamed tests count towards both.
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testActivateDialogWithSelectionActive
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testActivateWholeWordsAndSearchForTwoWords
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testCantOpenReplaceDialogInReadOnlyEditor
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testChangeInputForIncrementalSearch
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testDirectionalSearchButtons
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testDisableWholeWordIfNotWord
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testDisableWholeWordIfRegEx
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testFindWithWholeWordEnabledWithMultipleWords
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testIncrementalSearchUpdatesAfterChangingOptions
org.eclipse.ui.workbench.texteditor.tests.FindReplaceOverlayTest ‑ testInitialButtonState
…
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testActivateDialogWithSelectionActive
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testActivateWholeWordsAndSearchForTwoWords
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testCantOpenReplaceDialogInReadOnlyEditor
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testChangeInputForIncrementalSearch
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testDirectionalSearchButtons
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testDisableWholeWordIfNotWord
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testDisableWholeWordIfRegEx
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testFindWithWholeWordEnabledWithMultipleWords
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testIncrementalSearchUpdatesAfterChangingOptions
org.eclipse.ui.internal.findandreplace.overlay.FindReplaceOverlayTest ‑ testInitialButtonState
…

♻️ This comment has been updated with latest results.

@HeikoKlare
Copy link
Contributor

  Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget();

Access should of course be made via Adapters. Sorry for the "inadequate" proposal:

   Control targetWidget = Adapters.adapt(textEditor, ITextViewer.class).getTextWidget();

@Wittmaxi
Copy link
Author

Wittmaxi commented Jul 1, 2024

@HeikoKlare what is the difference between your proposals and why use the second one instead of the first one? The first one already works perfectly!

@Wittmaxi Wittmaxi force-pushed the MW_move_into_overlay_package branch 2 times, most recently from 11f8e14 to 529474b Compare July 1, 2024 11:44
@HeikoKlare
Copy link
Contributor

Maybe in this case it is even fine to call getAdapter() directly. The Javadoc states:
image

I guess the reason is that there may be more adapters than delivered by getAdapters() (as there is an adapter manager that is also queried by Adapters.adapt()). In addition, you can call Adapters.adapt() for objects of which you do not know whether they implement IAdaptable or not. But none of these cases applies here.
@laeubi do you see a reason for using Adapters.adapt() instead of directly calling IAdaptable.getAdapter() in this case?

@Wittmaxi Wittmaxi force-pushed the MW_move_into_overlay_package branch from 529474b to 4674cdf Compare July 1, 2024 12:56
@laeubi
Copy link
Contributor

laeubi commented Jul 1, 2024

@laeubi do you see a reason for using Adapters.adapt() instead of directly calling IAdaptable.getAdapter() in this case?

Adapters.adapt() is just more general form and you don't need to bother if it implements IAdaptable, is null and so on ... but its not forbidden to call IAdaptable directly. Beside that there is a convenient Adapters#of that even returns an Optional ...

moves helper classes for the find/replace overlay into an internal
package.
@Wittmaxi Wittmaxi force-pushed the MW_move_into_overlay_package branch from 4674cdf to 1253061 Compare July 1, 2024 14:46
This moves the test classes for the find/replace functionality, in
particular the ones for the find/replace overlay, to the packages
according to those of the production classes.
@HeikoKlare HeikoKlare merged commit 15d2e1d into eclipse-platform:master Jul 1, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants