-
Notifications
You must be signed in to change notification settings - Fork 143
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
Code cleanup : modernize switch expressions #934
Conversation
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could those 2 lines be joined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed the changes.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addresses the changes
newCursor = switch (cursorOrientation) { | ||
case SWT.UP -> new Cursor(display, SWT.CURSOR_SIZENS); | ||
case SWT.DOWN -> new Cursor(display, SWT.CURSOR_SIZENS); | ||
case SWT.LEFT -> new Cursor(display, SWT.CURSOR_SIZEWE); | ||
case SWT.RIGHT -> new Cursor(display, SWT.CURSOR_SIZEWE); | ||
case SWT.LEFT | SWT.UP -> new Cursor(display, SWT.CURSOR_SIZENWSE); | ||
case SWT.RIGHT | SWT.DOWN -> new Cursor(display, SWT.CURSOR_SIZENWSE); | ||
case SWT.LEFT | SWT.DOWN -> new Cursor(display, SWT.CURSOR_SIZENESW); | ||
case SWT.RIGHT | SWT.UP -> new Cursor(display, SWT.CURSOR_SIZENESW); | ||
default -> new Cursor(display, SWT.CURSOR_SIZEALL); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be something like
Cursor newCursor = new Cursor(display, switch (cursorOrientation) {
case SWT.UP, SWT.DOWN -> SWT.CURSOR_SIZENS;
case SWT.LEFT, SWT.RIGHT -> SWT.CURSOR_SIZEWE;
case (SWT.LEFT | SWT.UP), (SWT.RIGHT | SWT.DOWN ) -> new Cursor(display, SWT.CURSOR_SIZENWSE);
...
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed the changes.
case NEAREST -> imageData.scaledTo (scaledWidth, scaledHeight); | ||
default -> imageData.scaledTo (scaledWidth, scaledHeight); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default
should be sufficient t cover both cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed the changes
case JCS_GRAYSCALE: | ||
yield 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not case JCS_GRAYSCALE -> 1;
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I applied your changes I was getting this error "mixing of different case semantics is not allowed". I converted all the cases into one single format. Not sure if I did it right. Can you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ->
syntax must be used on all fields; it's not allowed to mix case X: ...
and case Y -> ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have addressed that way.
OutputStream os = null; | ||
switch (loader.compression) { | ||
case 0: | ||
os = new DeflaterOutputStream(baos, new Deflater(NO_COMPRESSION)); | ||
break; | ||
case 1: | ||
os = new DeflaterOutputStream(baos, new Deflater(BEST_SPEED)); | ||
break; | ||
case 3: | ||
os = new DeflaterOutputStream(baos, new Deflater(BEST_COMPRESSION)); | ||
break; | ||
default: | ||
os = new DeflaterOutputStream(baos, new Deflater(DEFAULT_COMPRESSION)); | ||
break; | ||
} | ||
os = switch (loader.compression) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those lines could be joined,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even better
OutputStream os = new DeflaterOutputStream(baos, switch (loader.compression) {
case 0 -> NO_COMPRESSION;
case 1 -> BEST_SPEED;
case 3 -> BEST_COMPRESSION;
default -> DEFAULT_COMPRESSION;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed the changes.
Thank you! |
Code cleanup : modernize switch expressions