Skip to content

Conversation

@r331
Copy link
Contributor

@r331 r331 commented Aug 26, 2022

On the way to Spring 6 and java 17 - refactoring the class CodeFlow. Instead of if-else, I added more readable switch expressions.

@pivotal-cla
Copy link

@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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 26, 2022
@pivotal-cla
Copy link

@r331 Thank you for signing the Contributor License Agreement!

case 'J' -> mv.visitInsn(I2L);
case 'I' -> { //nop
}
default -> throw new IllegalStateException("Unexpected value: " + targetDescriptor);

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.

Suggested change
default -> throw new IllegalStateException("Unexpected value: " + targetDescriptor);
default -> throw new IllegalStateException("Cannot get from " + stackTop + " to " + targetDescriptor);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Nice catch!

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 sbrannen self-assigned this Jan 31, 2023
@sbrannen sbrannen added type: task A general task in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 31, 2023
@sbrannen sbrannen added this to the 6.0.5 milestone Jan 31, 2023
Copy link
Member

@sbrannen sbrannen left a 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
Copy link
Member

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) {

Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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.

@sbrannen sbrannen changed the title Refactor CodeFlow class. Replace if else with switch expression. Use switch expressions in SpEL's CodeFlow Jan 31, 2023
@sbrannen
Copy link
Member

sbrannen commented Feb 2, 2023

@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.

[ant:checkstyle] [ERROR] /Users/xyz/spring-framework/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java:349:17: 'if' construct must use '{}'s. [NeedBraces] [ant:checkstyle] [ERROR] /Users/xyz/spring-framework/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java:371: Line has leading space characters; indentation should be performed with tabs only. [RegexpSinglelineJava] [ant:checkstyle] [ERROR] /Users/xyz/spring-framework/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java:382: Line has leading space characters; indentation should be performed with tabs only. [RegexpSinglelineJava] [ant:checkstyle] [ERROR] /Users/xyz/spring-framework/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java:393: Line has leading space characters; indentation should be performed with tabs only. [RegexpSinglelineJava] 
sbrannen added a commit to sbrannen/spring-framework that referenced this pull request Feb 2, 2023
@sbrannen sbrannen closed this in dcda127 Feb 2, 2023
@sbrannen
Copy link
Member

sbrannen commented Feb 2, 2023

This has been merged into main in dcda127 and revised in bc583ea.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task

5 participants