Skip to content

Commit 8bb2889

Browse files
committed
Modernize to Java 17 switch expression.Added default case.
1 parent 328646d commit 8bb2889

13 files changed

+208
-291
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogic.java

+15-24
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,16 @@ public void activate(SearchOptions searchOption) {
7878
}
7979

8080
switch (searchOption) {
81-
case GLOBAL:
82-
unsetSearchScope();
83-
break;
84-
case FORWARD:
85-
case INCREMENTAL:
86-
if (shouldInitIncrementalBaseLocation()) {
87-
resetIncrementalBaseLocation();
81+
case GLOBAL -> unsetSearchScope();
82+
case FORWARD, INCREMENTAL -> {
83+
if (shouldInitIncrementalBaseLocation()) {
84+
resetIncrementalBaseLocation();
85+
}
86+
}
87+
// $CASES-OMITTED$
88+
default -> {
89+
// No action needed; keeping an explicit default for clarity
8890
}
89-
break;
90-
// $CASES-OMITTED$
91-
default:
92-
break;
9391
}
9492
}
9593

@@ -131,19 +129,12 @@ private void resetStatus() {
131129

132130
@Override
133131
public boolean isAvailable(SearchOptions searchOption) {
134-
switch (searchOption) {
135-
case REGEX:
136-
return isTargetSupportingRegEx;
137-
case WHOLE_WORD:
138-
return !isAvailableAndActive(SearchOptions.REGEX) && isWord(findString);
139-
case INCREMENTAL:
140-
case CASE_SENSITIVE:
141-
case FORWARD:
142-
case GLOBAL:
143-
case WRAP:
144-
default:
145-
return true;
146-
}
132+
return switch (searchOption) {
133+
case REGEX -> isTargetSupportingRegEx;
134+
case WHOLE_WORD -> !isAvailableAndActive(SearchOptions.REGEX) && isWord(findString);
135+
case INCREMENTAL, CASE_SENSITIVE, FORWARD, GLOBAL, WRAP -> true;
136+
default -> true;
137+
};
147138
}
148139

149140
@Override

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicMessageGenerator.java

+6-16
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,12 @@ public String visit(ReplaceAllStatus status) {
4141
@Override
4242
public String visit(FindStatus status) {
4343
FindStatus.StatusCode messageCode = status.getMessageCode();
44-
String message;
45-
switch (messageCode) {
46-
case NO_MATCH:
47-
message = FindReplaceMessages.FindReplace_Status_noMatch_label;
48-
break;
49-
case WRAPPED:
50-
message = FindReplaceMessages.FindReplace_Status_wrapped_label;
51-
break;
52-
case READONLY:
53-
message = FindReplaceMessages.FindReplaceDialog_read_only;
54-
break;
55-
default:
56-
message = ""; //$NON-NLS-1$
57-
}
58-
59-
return message;
44+
return switch (messageCode) {
45+
case NO_MATCH -> FindReplaceMessages.FindReplace_Status_noMatch_label;
46+
case WRAPPED -> FindReplaceMessages.FindReplace_Status_wrapped_label;
47+
case READONLY -> FindReplaceMessages.FindReplaceDialog_read_only;
48+
default -> ""; //$NON-NLS-1$
49+
};
6050
}
6151

6252
@Override

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java

+32-28
Original file line numberDiff line numberDiff line change
@@ -232,49 +232,53 @@ private class CustomFocusOrder {
232232

233233
private final Listener replaceBarToSearchBarAndTools = e -> {
234234
switch (e.detail) {
235-
case SWT.TRAVERSE_TAB_NEXT:
236-
e.doit = false;
237-
searchBar.getDropDownTool().getFirstControl().forceFocus();
238-
break;
239-
case SWT.TRAVERSE_TAB_PREVIOUS:
240-
e.doit = false;
241-
searchBar.getTextBar().forceFocus();
242-
break;
243-
default:
244-
// Proceed as normal
235+
case SWT.TRAVERSE_TAB_NEXT -> {
236+
e.doit = false;
237+
searchBar.getDropDownTool().getFirstControl().forceFocus();
238+
}
239+
case SWT.TRAVERSE_TAB_PREVIOUS -> {
240+
e.doit = false;
241+
searchBar.getTextBar().forceFocus();
242+
}
243+
default -> {
244+
// Proceed as normal
245+
}
245246
}
246247
};
247248

248249
private final Listener searchToolsToReplaceBar = e -> {
249250
switch (e.detail) {
250-
case SWT.TRAVERSE_TAB_PREVIOUS:
251-
e.doit = false;
252-
replaceBar.forceFocus();
253-
break;
254-
default:
255-
// Proceed as normal
251+
case SWT.TRAVERSE_TAB_PREVIOUS -> {
252+
e.doit = false;
253+
replaceBar.forceFocus();
254+
}
255+
default -> {
256+
// Proceed as normal
257+
}
256258
}
257259
};
258260

259261
private final Listener closeToolsToReplaceTools = e -> {
260262
switch (e.detail) {
261-
case SWT.TRAVERSE_TAB_NEXT:
262-
e.doit = false;
263-
replaceBar.getDropDownTool().getFirstControl().forceFocus();
264-
break;
265-
default:
266-
// Proceed as normal
263+
case SWT.TRAVERSE_TAB_NEXT -> {
264+
e.doit = false;
265+
replaceBar.getDropDownTool().getFirstControl().forceFocus();
266+
}
267+
default -> {
268+
// Proceed as normal
269+
}
267270
}
268271
};
269272

270273
private final Listener replaceToolsToCloseTools = e -> {
271274
switch (e.detail) {
272-
case SWT.TRAVERSE_TAB_PREVIOUS:
273-
e.doit = false;
274-
closeTools.getFirstControl().forceFocus();
275-
break;
276-
default:
277-
// Proceed as normal
275+
case SWT.TRAVERSE_TAB_PREVIOUS -> {
276+
e.doit = false;
277+
closeTools.getFirstControl().forceFocus();
278+
}
279+
default -> {
280+
// Proceed as normal
281+
}
278282
}
279283
};
280284

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/quickdiff/DiffRegion.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,20 @@ public DiffRegion(QuickDiffRangeDifference difference, int offset, List<QuickDif
6262
public String getType() {
6363
// we return unknown for unchanged regions to avoid
6464
// them getting displayed.
65-
switch (getChangeType()) {
66-
case CHANGED:
65+
return switch (getChangeType()) {
66+
case CHANGED -> {
6767
int r= fDifference.rightLength();
6868
int l= fDifference.leftLength();
6969
int c= Math.min(r, l);
7070
if (c == 0 && r - l < 0)
71-
return "org.eclipse.ui.workbench.texteditor.quickdiffDeletion"; //$NON-NLS-1$
71+
yield "org.eclipse.ui.workbench.texteditor.quickdiffDeletion"; //$NON-NLS-1$
7272
else
73-
return "org.eclipse.ui.workbench.texteditor.quickdiffChange"; //$NON-NLS-1$
74-
case ADDED:
75-
return "org.eclipse.ui.workbench.texteditor.quickdiffAddition"; //$NON-NLS-1$
76-
case UNCHANGED:
77-
return "org.eclipse.ui.workbench.texteditor.quickdiffUnchanged"; //$NON-NLS-1$
78-
default:
79-
return TYPE_UNKNOWN;
80-
}
73+
yield "org.eclipse.ui.workbench.texteditor.quickdiffChange"; //$NON-NLS-1$
74+
}
75+
case ADDED -> "org.eclipse.ui.workbench.texteditor.quickdiffAddition"; //$NON-NLS-1$
76+
case UNCHANGED -> "org.eclipse.ui.workbench.texteditor.quickdiffUnchanged"; //$NON-NLS-1$
77+
default -> TYPE_UNKNOWN;
78+
};
8179
}
8280

8381
@Override

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java

+43-54
Original file line numberDiff line numberDiff line change
@@ -4041,19 +4041,16 @@ protected void installCodeMiningProviders() {
40414041
* @since 3.4
40424042
*/
40434043
private EnrichMode convertEnrichModePreference(int mode) {
4044-
switch (mode) {
4045-
case -1:
4046-
return null;
4047-
case 0:
4048-
return EnrichMode.AFTER_DELAY;
4049-
case 1:
4050-
return EnrichMode.IMMEDIATELY;
4051-
case 2:
4052-
return EnrichMode.ON_CLICK;
4053-
default:
4044+
return switch (mode) {
4045+
case -1 -> null;
4046+
case 0 -> EnrichMode.AFTER_DELAY;
4047+
case 1 -> EnrichMode.IMMEDIATELY;
4048+
case 2 -> EnrichMode.ON_CLICK;
4049+
default -> {
40544050
Assert.isLegal(false);
4055-
return null;
4056-
}
4051+
yield null;
4052+
}
4053+
};
40574054
}
40584055

40594056
/**
@@ -4537,25 +4534,22 @@ protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
45374534

45384535
if (property != null) {
45394536
switch (property) {
4540-
case PREFERENCE_COLOR_FOREGROUND:
4541-
case PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT:
4542-
case PREFERENCE_COLOR_BACKGROUND:
4543-
case PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT:
4544-
case PREFERENCE_COLOR_SELECTION_FOREGROUND:
4545-
case PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT:
4546-
case PREFERENCE_COLOR_SELECTION_BACKGROUND:
4547-
case PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT:
4548-
initializeViewerColors(fSourceViewer);
4549-
break;
4550-
case PREFERENCE_COLOR_FIND_SCOPE:
4551-
initializeFindScopeColor(fSourceViewer);
4552-
break;
4553-
case PREFERENCE_USE_CUSTOM_CARETS:
4554-
case PREFERENCE_WIDE_CARET:
4555-
updateCaret();
4556-
break;
4557-
default:
4558-
break;
4537+
case PREFERENCE_COLOR_FOREGROUND,
4538+
PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT,
4539+
PREFERENCE_COLOR_BACKGROUND,
4540+
PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT,
4541+
PREFERENCE_COLOR_SELECTION_FOREGROUND,
4542+
PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT,
4543+
PREFERENCE_COLOR_SELECTION_BACKGROUND,
4544+
PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT ->
4545+
initializeViewerColors(fSourceViewer);
4546+
case PREFERENCE_COLOR_FIND_SCOPE -> initializeFindScopeColor(fSourceViewer);
4547+
case PREFERENCE_USE_CUSTOM_CARETS,
4548+
PREFERENCE_WIDE_CARET ->
4549+
updateCaret();
4550+
default -> {
4551+
// No action needed
4552+
}
45594553
}
45604554
}
45614555

@@ -6692,29 +6686,24 @@ protected void updateStatusField(String category) {
66926686

66936687
IStatusField field= getStatusField(category);
66946688
if (field != null) {
6695-
6696-
String text= null;
6697-
6698-
switch (category) {
6699-
case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION:
6700-
text= getCursorPosition();
6701-
break;
6702-
case ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE:
6703-
text= isEditorInputReadOnly() ? fReadOnlyLabel : fWritableLabel;
6704-
break;
6705-
case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE:
6706-
InsertMode mode= getInsertMode();
6707-
if (fIsOverwriting)
6708-
text= fOverwriteModeLabel;
6709-
else if (INSERT == mode)
6710-
text= fInsertModeLabel;
6711-
else if (SMART_INSERT == mode)
6712-
text= fSmartInsertModeLabel;
6713-
break;
6714-
default:
6715-
break;
6716-
}
6717-
6689+
String text = switch (category) {
6690+
case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION ->
6691+
getCursorPosition();
6692+
case ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE ->
6693+
isEditorInputReadOnly() ? fReadOnlyLabel : fWritableLabel;
6694+
case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE -> {
6695+
InsertMode mode = getInsertMode();
6696+
if (fIsOverwriting)
6697+
yield fOverwriteModeLabel;
6698+
else if (INSERT == mode)
6699+
yield fInsertModeLabel;
6700+
else if (SMART_INSERT == mode)
6701+
yield fSmartInsertModeLabel;
6702+
else
6703+
yield null;
6704+
}
6705+
default -> null;
6706+
};
67186707
field.setText(text == null ? fErrorLabel : text);
67196708
}
67206709
}

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DeleteLineAction.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,15 @@ public DeleteLineAction(ITextEditor editor, int type, boolean copyToClipboard) {
118118
* @since 3.5
119119
*/
120120
private static String getPrefix(int type, boolean copyToClipboard) {
121-
switch (type) {
122-
case WHOLE:
123-
return copyToClipboard ? "Editor.CutLine." : "Editor.DeleteLine."; //$NON-NLS-1$ //$NON-NLS-2$
124-
case TO_BEGINNING:
125-
return copyToClipboard ? "Editor.CutLineToBeginning." : "Editor.DeleteLineToBeginning."; //$NON-NLS-1$ //$NON-NLS-2$
126-
case TO_END:
127-
return copyToClipboard ? "Editor.CutLineToEnd." : "Editor.DeleteLineToEnd."; //$NON-NLS-1$ //$NON-NLS-2$
128-
default:
121+
return switch (type) {
122+
case WHOLE -> copyToClipboard ? "Editor.CutLine." : "Editor.DeleteLine."; //$NON-NLS-1$ //$NON-NLS-2$
123+
case TO_BEGINNING -> copyToClipboard ? "Editor.CutLineToBeginning." : "Editor.DeleteLineToBeginning."; //$NON-NLS-1$ //$NON-NLS-2$
124+
case TO_END -> copyToClipboard ? "Editor.CutLineToEnd." : "Editor.DeleteLineToEnd."; //$NON-NLS-1$ //$NON-NLS-2$
125+
default -> {
129126
Assert.isLegal(false);
130-
return ""; //$NON-NLS-1$
131-
}
127+
yield ""; //$NON-NLS-1$
128+
}
129+
};
132130
}
133131

134132
/**

0 commit comments

Comments
 (0)