Skip to content

Commit

Permalink
Code cleanup : modernize switch expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
elsazac committed Dec 12, 2023
1 parent 7c78245 commit 1f87ad2
Show file tree
Hide file tree
Showing 14 changed files with 887 additions and 1,137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1671,20 +1671,15 @@ id getAttributedStringForRangeParameterizedAttribute(id parameter, int childID)
int style = ts.underlineStyle;
NSString attribute = OS.NSAccessibilityUnderlineTextAttribute;
NSNumber styleObj = null;
switch (style) {
case SWT.UNDERLINE_SINGLE:
styleObj = NSNumber.numberWithInt(OS.kAXUnderlineStyleSingle);
break;
case SWT.UNDERLINE_DOUBLE:
styleObj = NSNumber.numberWithInt(OS.kAXUnderlineStyleDouble);
break;
case SWT.UNDERLINE_SQUIGGLE:
styleObj = switch (style) {
case SWT.UNDERLINE_SINGLE -> NSNumber.numberWithInt(OS.kAXUnderlineStyleSingle);
case SWT.UNDERLINE_DOUBLE -> NSNumber.numberWithInt(OS.kAXUnderlineStyleDouble);
case SWT.UNDERLINE_SQUIGGLE -> {
attribute = OS.NSAccessibilityMisspelledTextAttribute;
styleObj = NSNumber.numberWithBool(true);
break;
default:
styleObj = NSNumber.numberWithInt(OS.kAXUnderlineStyleNone);
yield NSNumber.numberWithBool(true);
}
default -> NSNumber.numberWithInt(OS.kAXUnderlineStyleNone);
};

attribString.addAttribute(attribute, styleObj, attributeRange);
}
Expand Down Expand Up @@ -1722,18 +1717,12 @@ id getAttributedStringForRangeParameterizedAttribute(id parameter, int childID)
NSMutableDictionary paragraphDict = NSMutableDictionary.dictionaryWithCapacity(3);
int osAlignment = 0;
// FIXME: Doesn't account for right-to-left text?
switch (docAttributes.alignment) {
case SWT.CENTER:
osAlignment = OS.NSTextAlignmentCenter;
break;
case SWT.RIGHT:
osAlignment = OS.NSTextAlignmentRight;
break;
case SWT.LEFT:
default:
osAlignment = OS.NSTextAlignmentLeft;
break;
}
osAlignment = switch (docAttributes.alignment) {
case SWT.CENTER -> OS.NSTextAlignmentCenter;
case SWT.RIGHT -> OS.NSTextAlignmentRight;
case SWT.LEFT -> OS.NSTextAlignmentLeft;
default -> OS.NSTextAlignmentLeft;
};
paragraphDict.setValue(NSNumber.numberWithInt(osAlignment), NSString.stringWith("AXTextAlignment"));
range.location = 0;
attribString.addAttribute(NSString.stringWith("AXParagraphStyle"), paragraphDict, range);
Expand Down
Loading

0 comments on commit 1f87ad2

Please sign in to comment.