Skip to content

Commit 12106ab

Browse files
graememorganError Prone Team
authored and
Error Prone Team
committed
Add another broken test where the substituted code requires parens.
This feels like a nice complementary test to the other precedence-backed ones. PiperOrigin-RevId: 733295242
1 parent 0bc6e8a commit 12106ab

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

core/src/test/java/com/google/errorprone/bugpatterns/inlineme/InlinerTest.java

+82
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,88 @@ public void doTest() {
11921192
.doTest();
11931193
}
11941194

1195+
@Test
1196+
public void orderOfOperationsWhenInliningAddition() {
1197+
refactoringTestHelper
1198+
.addInputLines(
1199+
"Client.java",
1200+
"""
1201+
import com.google.errorprone.annotations.InlineMe;
1202+
1203+
public final class Client {
1204+
@Deprecated
1205+
@InlineMe(replacement = "x + y")
1206+
public int add(int x, int y) {
1207+
return x + y;
1208+
}
1209+
}
1210+
""")
1211+
.expectUnchanged()
1212+
.addInputLines(
1213+
"Caller.java",
1214+
"""
1215+
public final class Caller {
1216+
public void doTest() {
1217+
Client client = new Client();
1218+
int x = client.add(1, 2) * 3;
1219+
int y = client.add(1, 2) + 3;
1220+
}
1221+
}
1222+
""")
1223+
.addOutputLines(
1224+
"out/Caller.java",
1225+
"""
1226+
public final class Caller {
1227+
public void doTest() {
1228+
Client client = new Client();
1229+
int x = 1 + 2 * 3;
1230+
int y = 1 + 2 + 3;
1231+
}
1232+
}
1233+
""")
1234+
.doTest();
1235+
}
1236+
1237+
@Test
1238+
public void orderOfOperationsWhenInliningCasts() {
1239+
refactoringTestHelper
1240+
.addInputLines(
1241+
"Client.java",
1242+
"""
1243+
import com.google.errorprone.annotations.InlineMe;
1244+
1245+
public final class Client {
1246+
@Deprecated
1247+
@InlineMe(replacement = "(int) x")
1248+
public int cast(long x) {
1249+
return (int) x;
1250+
}
1251+
}
1252+
""")
1253+
.expectUnchanged()
1254+
.addInputLines(
1255+
"Caller.java",
1256+
"""
1257+
public final class Caller {
1258+
public void doTest() {
1259+
Client client = new Client();
1260+
int x = client.cast(1) * 10;
1261+
}
1262+
}
1263+
""")
1264+
.addOutputLines(
1265+
"out/Caller.java",
1266+
"""
1267+
public final class Caller {
1268+
public void doTest() {
1269+
Client client = new Client();
1270+
int x = (int) 1 * 10;
1271+
}
1272+
}
1273+
""")
1274+
.doTest();
1275+
}
1276+
11951277
@Test
11961278
public void orderOfOperationsWithTrailingOperand() {
11971279
refactoringTestHelper

0 commit comments

Comments
 (0)