Skip to content
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

[StatementSwitchToExpressionSwitch] Combine immediately-preceding variable definitions with assignment switches to the same variable, where feasible #4730

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

copybara-service[bot]
Copy link
Contributor

@copybara-service copybara-service bot commented Dec 17, 2024

[StatementSwitchToExpressionSwitch] Combine immediately-preceding variable definitions with assignment switches to the same variable, where feasible

Copy link
Contributor

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Just some drive-by comments.

assignmentSwitchAnalysisState.assignmentTargetOptional(),
variableTreeOptional.get());

System.out.println("XXX compatibleVariableDeclaration: " + compatibleVariableDeclaration);
Copy link
Contributor

Choose a reason for hiding this comment

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

Likely to also be caught by Google-internal code review, but: I assume these stdout print statements are meant to be dropped before the PR is merged 👀

Comment on lines 913 to 919
if (precedingStatements.get(precedingStatements.size() - 1) instanceof VariableTree
&& precedingStatements.get(precedingStatements.size() - 2) instanceof VariableTree) {

VariableTree variableTree1 =
(VariableTree) precedingStatements.get(precedingStatements.size() - 1);
VariableTree variableTree2 =
(VariableTree) precedingStatements.get(precedingStatements.size() - 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (precedingStatements.get(precedingStatements.size() - 1) instanceof VariableTree
&& precedingStatements.get(precedingStatements.size() - 2) instanceof VariableTree) {
VariableTree variableTree1 =
(VariableTree) precedingStatements.get(precedingStatements.size() - 1);
VariableTree variableTree2 =
(VariableTree) precedingStatements.get(precedingStatements.size() - 2);
if (precedingStatements.get(precedingStatements.size() - 1) instanceof VariableTree variableTree1
&& precedingStatements.get(precedingStatements.size() - 2) instanceof VariableTree variableTree2) {

(A similar simplification is possible below.)

@copybara-service copybara-service bot force-pushed the test_705971103 branch 8 times, most recently from 9351dd6 to 4006d62 Compare December 18, 2024 21:59
@copybara-service copybara-service bot changed the title [StatementSwitchToExpressionSwitch] Combine immediately-preceding uninitialized variable with assignment via assignment switch [StatementSwitchToExpressionSwitch] Combine immediately-preceding variable definitions with assignment via assignment switch, where feasible Dec 18, 2024
@copybara-service copybara-service bot force-pushed the test_705971103 branch 17 times, most recently from 90071a9 to 6bb99a7 Compare December 20, 2024 01:19
@copybara-service copybara-service bot changed the title [StatementSwitchToExpressionSwitch] Combine immediately-preceding variable definitions with assignment via assignment switch, where feasible [StatementSwitchToExpressionSwitch] Combine immediately-preceding variable definitions with assignment switches to the same variable, where feasible Dec 20, 2024
@copybara-service copybara-service bot force-pushed the test_705971103 branch 4 times, most recently from 15e308b to 5ce3954 Compare January 8, 2025 18:53
…iable definitions with assignment switches to the same variable, where feasible

PiperOrigin-RevId: 713355872
@copybara-service copybara-service bot merged commit 1a14c75 into master Jan 8, 2025
1 check passed
@copybara-service copybara-service bot deleted the test_705971103 branch January 8, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants