Commit 12106ab 1 parent 0bc6e8a commit 12106ab Copy full SHA for 12106ab
File tree 1 file changed +82
-0
lines changed
core/src/test/java/com/google/errorprone/bugpatterns/inlineme
1 file changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -1192,6 +1192,88 @@ public void doTest() {
1192
1192
.doTest ();
1193
1193
}
1194
1194
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
+
1195
1277
@ Test
1196
1278
public void orderOfOperationsWithTrailingOperand () {
1197
1279
refactoringTestHelper
You can’t perform that action at this time.
0 commit comments