- Notifications
You must be signed in to change notification settings - Fork 38.9k
Use switch expressions in SpEL's CodeFlow #29020
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
Conversation
| @r331 Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
| @r331 Thank you for signing the Contributor License Agreement! |
| case 'J' -> mv.visitInsn(I2L); | ||
| case 'I' -> { //nop | ||
| } | ||
| default -> throw new IllegalStateException("Unexpected value: " + targetDescriptor); |
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 stackTop information is no longer present in the exception message.
| default -> throw new IllegalStateException("Unexpected value: " + targetDescriptor); | |
| default -> throw new IllegalStateException("Cannot get from " + stackTop + " to " + targetDescriptor); |
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.
Thanks! Nice catch!
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.
Glad to be of help!
sbrannen left a comment
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.
Hi @r331,
Congratulations on submitting your first PR for the Spring Framework! 👍
The switch expression changes look good.
I left a few comments which I will address when merging the PR, so there's no need to update this PR.
| | ||
| /** | ||
| * Name of the class being generated. Typically used when generating code | ||
| * Name of the class being generated. Typically, used when generating code |
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.
That was grammatically correct as it was. "Typically" is an adverb modifying the verb "used".
| */ | ||
| public static void insertUnboxNumberInsns( | ||
| MethodVisitor mv, char targetDescriptor, @Nullable String stackDescriptor) { | ||
| |
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.
Please refrain from deleting blank lines intentionally inserted by the original authors.
| } | ||
| else { | ||
| throw new IllegalStateException("Cannot get from " + stackTop + " to " + targetDescriptor); | ||
| if (!CodeFlow.isPrimitive(stackDescriptor)) return; |
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.
In Spring Framework, we do not use single-line if-statements.
| case "char" -> "C"; | ||
| case "long" -> "J"; | ||
| case "void" -> "V"; | ||
| default -> throw new IllegalStateException("Unexpected value: " + name); |
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'd use the same exception message here that you use below: "Unknown primitive type: " + name.
CodeFlow | @r331, for future reference please ensure that you always run a full local build before submitting a PR. For example, this PR actually fails the build due to Checkstyle violations. |
On the way to Spring 6 and java 17 - refactoring the class CodeFlow. Instead of if-else, I added more readable switch expressions.