Skip to content

Modernize to Java 17 switch expression. #2816

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,16 @@ public void activate(SearchOptions searchOption) {
}

switch (searchOption) {
case GLOBAL:
unsetSearchScope();
break;
case FORWARD:
case INCREMENTAL:
if (shouldInitIncrementalBaseLocation()) {
resetIncrementalBaseLocation();
case GLOBAL -> unsetSearchScope();
case FORWARD, INCREMENTAL -> {
if (shouldInitIncrementalBaseLocation()) {
resetIncrementalBaseLocation();
}
}
// $CASES-OMITTED$
default -> {
// No action needed; keeping an explicit default for clarity
}
break;
// $CASES-OMITTED$
default:
break;
}
}

Expand Down Expand Up @@ -131,19 +129,12 @@ private void resetStatus() {

@Override
public boolean isAvailable(SearchOptions searchOption) {
switch (searchOption) {
case REGEX:
return isTargetSupportingRegEx;
case WHOLE_WORD:
return !isAvailableAndActive(SearchOptions.REGEX) && isWord(findString);
case INCREMENTAL:
case CASE_SENSITIVE:
case FORWARD:
case GLOBAL:
case WRAP:
default:
return true;
}
return switch (searchOption) {
case REGEX -> isTargetSupportingRegEx;
case WHOLE_WORD -> !isAvailableAndActive(SearchOptions.REGEX) && isWord(findString);
case INCREMENTAL, CASE_SENSITIVE, FORWARD, GLOBAL, WRAP -> true;
default -> true;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,12 @@ public String visit(ReplaceAllStatus status) {
@Override
public String visit(FindStatus status) {
FindStatus.StatusCode messageCode = status.getMessageCode();
String message;
switch (messageCode) {
case NO_MATCH:
message = FindReplaceMessages.FindReplace_Status_noMatch_label;
break;
case WRAPPED:
message = FindReplaceMessages.FindReplace_Status_wrapped_label;
break;
case READONLY:
message = FindReplaceMessages.FindReplaceDialog_read_only;
break;
default:
message = ""; //$NON-NLS-1$
}

return message;
return switch (messageCode) {
case NO_MATCH -> FindReplaceMessages.FindReplace_Status_noMatch_label;
case WRAPPED -> FindReplaceMessages.FindReplace_Status_wrapped_label;
case READONLY -> FindReplaceMessages.FindReplaceDialog_read_only;
default -> ""; //$NON-NLS-1$
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,49 +232,53 @@ private class CustomFocusOrder {

private final Listener replaceBarToSearchBarAndTools = e -> {
switch (e.detail) {
case SWT.TRAVERSE_TAB_NEXT:
e.doit = false;
searchBar.getDropDownTool().getFirstControl().forceFocus();
break;
case SWT.TRAVERSE_TAB_PREVIOUS:
e.doit = false;
searchBar.getTextBar().forceFocus();
break;
default:
// Proceed as normal
case SWT.TRAVERSE_TAB_NEXT -> {
e.doit = false;
searchBar.getDropDownTool().getFirstControl().forceFocus();
}
case SWT.TRAVERSE_TAB_PREVIOUS -> {
e.doit = false;
searchBar.getTextBar().forceFocus();
}
default -> {
// Proceed as normal
}
}
};

private final Listener searchToolsToReplaceBar = e -> {
switch (e.detail) {
case SWT.TRAVERSE_TAB_PREVIOUS:
e.doit = false;
replaceBar.forceFocus();
break;
default:
// Proceed as normal
case SWT.TRAVERSE_TAB_PREVIOUS -> {
e.doit = false;
replaceBar.forceFocus();
}
default -> {
// Proceed as normal
}
}
};

private final Listener closeToolsToReplaceTools = e -> {
switch (e.detail) {
case SWT.TRAVERSE_TAB_NEXT:
e.doit = false;
replaceBar.getDropDownTool().getFirstControl().forceFocus();
break;
default:
// Proceed as normal
case SWT.TRAVERSE_TAB_NEXT -> {
e.doit = false;
replaceBar.getDropDownTool().getFirstControl().forceFocus();
}
default -> {
// Proceed as normal
}
}
};

private final Listener replaceToolsToCloseTools = e -> {
switch (e.detail) {
case SWT.TRAVERSE_TAB_PREVIOUS:
e.doit = false;
closeTools.getFirstControl().forceFocus();
break;
default:
// Proceed as normal
case SWT.TRAVERSE_TAB_PREVIOUS -> {
e.doit = false;
closeTools.getFirstControl().forceFocus();
}
default -> {
// Proceed as normal
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,20 @@ public DiffRegion(QuickDiffRangeDifference difference, int offset, List<QuickDif
public String getType() {
// we return unknown for unchanged regions to avoid
// them getting displayed.
switch (getChangeType()) {
case CHANGED:
return switch (getChangeType()) {
case CHANGED -> {
int r= fDifference.rightLength();
int l= fDifference.leftLength();
int c= Math.min(r, l);
if (c == 0 && r - l < 0)
return "org.eclipse.ui.workbench.texteditor.quickdiffDeletion"; //$NON-NLS-1$
yield "org.eclipse.ui.workbench.texteditor.quickdiffDeletion"; //$NON-NLS-1$
else
return "org.eclipse.ui.workbench.texteditor.quickdiffChange"; //$NON-NLS-1$
case ADDED:
return "org.eclipse.ui.workbench.texteditor.quickdiffAddition"; //$NON-NLS-1$
case UNCHANGED:
return "org.eclipse.ui.workbench.texteditor.quickdiffUnchanged"; //$NON-NLS-1$
default:
return TYPE_UNKNOWN;
}
yield "org.eclipse.ui.workbench.texteditor.quickdiffChange"; //$NON-NLS-1$
}
case ADDED -> "org.eclipse.ui.workbench.texteditor.quickdiffAddition"; //$NON-NLS-1$
case UNCHANGED -> "org.eclipse.ui.workbench.texteditor.quickdiffUnchanged"; //$NON-NLS-1$
default -> TYPE_UNKNOWN;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4041,19 +4041,16 @@ protected void installCodeMiningProviders() {
* @since 3.4
*/
private EnrichMode convertEnrichModePreference(int mode) {
switch (mode) {
case -1:
return null;
case 0:
return EnrichMode.AFTER_DELAY;
case 1:
return EnrichMode.IMMEDIATELY;
case 2:
return EnrichMode.ON_CLICK;
default:
return switch (mode) {
case -1 -> null;
case 0 -> EnrichMode.AFTER_DELAY;
case 1 -> EnrichMode.IMMEDIATELY;
case 2 -> EnrichMode.ON_CLICK;
default -> {
Assert.isLegal(false);
return null;
}
yield null;
}
};
}

/**
Expand Down Expand Up @@ -4537,25 +4534,22 @@ protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {

if (property != null) {
switch (property) {
case PREFERENCE_COLOR_FOREGROUND:
case PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT:
case PREFERENCE_COLOR_BACKGROUND:
case PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT:
case PREFERENCE_COLOR_SELECTION_FOREGROUND:
case PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT:
case PREFERENCE_COLOR_SELECTION_BACKGROUND:
case PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT:
initializeViewerColors(fSourceViewer);
break;
case PREFERENCE_COLOR_FIND_SCOPE:
initializeFindScopeColor(fSourceViewer);
break;
case PREFERENCE_USE_CUSTOM_CARETS:
case PREFERENCE_WIDE_CARET:
updateCaret();
break;
default:
break;
case PREFERENCE_COLOR_FOREGROUND,
PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT,
PREFERENCE_COLOR_BACKGROUND,
PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT,
PREFERENCE_COLOR_SELECTION_FOREGROUND,
PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT,
PREFERENCE_COLOR_SELECTION_BACKGROUND,
PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT ->
initializeViewerColors(fSourceViewer);
case PREFERENCE_COLOR_FIND_SCOPE -> initializeFindScopeColor(fSourceViewer);
case PREFERENCE_USE_CUSTOM_CARETS,
PREFERENCE_WIDE_CARET ->
updateCaret();
default -> {
// No action needed
}
}
}

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

IStatusField field= getStatusField(category);
if (field != null) {

String text= null;

switch (category) {
case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION:
text= getCursorPosition();
break;
case ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE:
text= isEditorInputReadOnly() ? fReadOnlyLabel : fWritableLabel;
break;
case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE:
InsertMode mode= getInsertMode();
if (fIsOverwriting)
text= fOverwriteModeLabel;
else if (INSERT == mode)
text= fInsertModeLabel;
else if (SMART_INSERT == mode)
text= fSmartInsertModeLabel;
break;
default:
break;
}

String text = switch (category) {
case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION ->
getCursorPosition();
case ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE ->
isEditorInputReadOnly() ? fReadOnlyLabel : fWritableLabel;
case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE -> {
InsertMode mode = getInsertMode();
if (fIsOverwriting)
yield fOverwriteModeLabel;
else if (INSERT == mode)
yield fInsertModeLabel;
else if (SMART_INSERT == mode)
yield fSmartInsertModeLabel;
else
yield null;
}
default -> null;
};
field.setText(text == null ? fErrorLabel : text);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,15 @@ public DeleteLineAction(ITextEditor editor, int type, boolean copyToClipboard) {
* @since 3.5
*/
private static String getPrefix(int type, boolean copyToClipboard) {
switch (type) {
case WHOLE:
return copyToClipboard ? "Editor.CutLine." : "Editor.DeleteLine."; //$NON-NLS-1$ //$NON-NLS-2$
case TO_BEGINNING:
return copyToClipboard ? "Editor.CutLineToBeginning." : "Editor.DeleteLineToBeginning."; //$NON-NLS-1$ //$NON-NLS-2$
case TO_END:
return copyToClipboard ? "Editor.CutLineToEnd." : "Editor.DeleteLineToEnd."; //$NON-NLS-1$ //$NON-NLS-2$
default:
return switch (type) {
case WHOLE -> copyToClipboard ? "Editor.CutLine." : "Editor.DeleteLine."; //$NON-NLS-1$ //$NON-NLS-2$
case TO_BEGINNING -> copyToClipboard ? "Editor.CutLineToBeginning." : "Editor.DeleteLineToBeginning."; //$NON-NLS-1$ //$NON-NLS-2$
case TO_END -> copyToClipboard ? "Editor.CutLineToEnd." : "Editor.DeleteLineToEnd."; //$NON-NLS-1$ //$NON-NLS-2$
default -> {
Assert.isLegal(false);
return ""; //$NON-NLS-1$
}
yield ""; //$NON-NLS-1$
}
};
}

/**
Expand Down
Loading
Loading