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

Add another broken test where the substituted code requires parens. #4871

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,88 @@ public void doTest() {
.doTest();
}

@Test
public void orderOfOperationsWhenInliningAddition() {
refactoringTestHelper
.addInputLines(
"Client.java",
"""
import com.google.errorprone.annotations.InlineMe;

public final class Client {
@Deprecated
@InlineMe(replacement = "x + y")
public int add(int x, int y) {
return x + y;
}
}
""")
.expectUnchanged()
.addInputLines(
"Caller.java",
"""
public final class Caller {
public void doTest() {
Client client = new Client();
int x = client.add(1, 2) * 3;
int y = client.add(1, 2) + 3;
}
}
""")
.addOutputLines(
"out/Caller.java",
"""
public final class Caller {
public void doTest() {
Client client = new Client();
int x = 1 + 2 * 3;
int y = 1 + 2 + 3;
}
}
""")
.doTest();
}

@Test
public void orderOfOperationsWhenInliningCasts() {
refactoringTestHelper
.addInputLines(
"Client.java",
"""
import com.google.errorprone.annotations.InlineMe;

public final class Client {
@Deprecated
@InlineMe(replacement = "(int) x")
public int cast(long x) {
return (int) x;
}
}
""")
.expectUnchanged()
.addInputLines(
"Caller.java",
"""
public final class Caller {
public void doTest() {
Client client = new Client();
int x = client.cast(1) * 10;
}
}
""")
.addOutputLines(
"out/Caller.java",
"""
public final class Caller {
public void doTest() {
Client client = new Client();
int x = (int) 1 * 10;
}
}
""")
.doTest();
}

@Test
public void orderOfOperationsWithTrailingOperand() {
refactoringTestHelper
Expand Down
Loading