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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
…iable definitions with assignment switches to the same variable, where feasible

PiperOrigin-RevId: 705971103
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