|
15 | 15 | */
|
16 | 16 | package org.openrewrite.staticanalysis;
|
17 | 17 |
|
18 |
| -import org.junit.jupiter.api.Disabled; |
19 | 18 | import org.junit.jupiter.api.Nested;
|
20 | 19 | import org.junit.jupiter.api.Test;
|
21 | 20 | import org.openrewrite.DocumentExample;
|
@@ -141,293 +140,6 @@ void foo(Object s) {
|
141 | 140 | @Nested
|
142 | 141 | class ReplaceConstantMethodArg {
|
143 | 142 |
|
144 |
| - @Issue("https://github.com/openrewrite/rewrite-static-analysis/pull/398") |
145 |
| - @Test |
146 |
| - void one() { |
147 |
| - rewriteRun( |
148 |
| - // language=java |
149 |
| - java( |
150 |
| - """ |
151 |
| - public class Constants { |
152 |
| - public static final String FOO = null; |
153 |
| - } |
154 |
| - class A { |
155 |
| - private boolean isFoo(String foo) { |
156 |
| - foo = null; |
157 |
| - return foo.contentEquals(Constants.FOO); |
158 |
| - } |
159 |
| - } |
160 |
| - """, |
161 |
| - """ |
162 |
| - public class Constants { |
163 |
| - public static final String FOO = null; |
164 |
| - } |
165 |
| - class A { |
166 |
| - private boolean isFoo(String foo) { |
167 |
| - foo = null; |
168 |
| - return Constants.FOO.contentEquals(foo); |
169 |
| - } |
170 |
| - } |
171 |
| - """ |
172 |
| - ) |
173 |
| - ); |
174 |
| - } |
175 |
| - |
176 |
| - @Test |
177 |
| - void chainedMethodCalls() { |
178 |
| - // language=java |
179 |
| - rewriteRun( |
180 |
| - java( |
181 |
| - """ |
182 |
| - package c; |
183 |
| - public class Constants { |
184 |
| - public static final String FOO = null; |
185 |
| - } |
186 |
| - """ |
187 |
| - ), |
188 |
| - java( |
189 |
| - """ |
190 |
| - class Foo { |
191 |
| - String getFooType() { |
192 |
| - return "FOO"; |
193 |
| - } |
194 |
| - Foo getFOO() { |
195 |
| - return this; |
196 |
| - } |
197 |
| - } |
198 |
| - """ |
199 |
| - ), |
200 |
| - java( |
201 |
| - """ |
202 |
| - import static c.Constants.FOO; |
203 |
| - class A { |
204 |
| - boolean filterFoo(final Foo foo) { |
205 |
| - return foo.getFOO().getFooType().contentEquals(FOO); |
206 |
| - } |
207 |
| - } |
208 |
| - """, |
209 |
| - """ |
210 |
| - import static c.Constants.FOO; |
211 |
| - class A { |
212 |
| - boolean filterFoo(final Foo foo) { |
213 |
| - return FOO.contentEquals(foo.getFOO().getFooType()); |
214 |
| - } |
215 |
| - } |
216 |
| - """ |
217 |
| - ) |
218 |
| - ); |
219 |
| - } |
220 |
| - |
221 |
| - @Test |
222 |
| - void staticImport() { |
223 |
| - rewriteRun( |
224 |
| - // language=java |
225 |
| - java( |
226 |
| - """ |
227 |
| - package c; |
228 |
| - public class Constants { |
229 |
| - public static final String FOO = null; |
230 |
| - } |
231 |
| - """ |
232 |
| - ), |
233 |
| - // language=java |
234 |
| - java( |
235 |
| - """ |
236 |
| - import static c.Constants.FOO; |
237 |
| - class A { |
238 |
| - private boolean isFoo(String foo) { |
239 |
| - return foo.contentEquals(FOO); |
240 |
| - } |
241 |
| - } |
242 |
| - """, |
243 |
| - """ |
244 |
| - import static c.Constants.FOO; |
245 |
| - class A { |
246 |
| - private boolean isFoo(String foo) { |
247 |
| - return FOO.contentEquals(foo); |
248 |
| - } |
249 |
| - } |
250 |
| - """ |
251 |
| - ) |
252 |
| - ); |
253 |
| - } |
254 |
| - |
255 |
| - @Test |
256 |
| - void multiple() { |
257 |
| - rewriteRun( |
258 |
| - //language=java |
259 |
| - java( |
260 |
| - """ |
261 |
| - public class Constants { |
262 |
| - public static final String FOO = null; |
263 |
| - } |
264 |
| - class A { |
265 |
| - private boolean isFoo(String foo, String bar) { |
266 |
| - return foo.equals(Constants.FOO) |
267 |
| - || bar.contentEquals(Constants.FOO); |
268 |
| - } |
269 |
| - } |
270 |
| - """, |
271 |
| - """ |
272 |
| - public class Constants { |
273 |
| - public static final String FOO = null; |
274 |
| - } |
275 |
| - class A { |
276 |
| - private boolean isFoo(String foo, String bar) { |
277 |
| - return Constants.FOO.equals(foo) |
278 |
| - || Constants.FOO.contentEquals(bar); |
279 |
| - } |
280 |
| - } |
281 |
| - """ |
282 |
| - ) |
283 |
| - ); |
284 |
| - } |
285 |
| - |
286 |
| - @Test |
287 |
| - void generics() { |
288 |
| - rewriteRun( |
289 |
| - //language=java |
290 |
| - java( |
291 |
| - """ |
292 |
| - import java.util.List; |
293 |
| - public class Constants { |
294 |
| - public static final String FOO = null; |
295 |
| - } |
296 |
| - class A { |
297 |
| - private <T> void r(T e) { |
298 |
| - e.toString().equals(Constants.FOO); |
299 |
| - } |
300 |
| - } |
301 |
| - """, |
302 |
| - """ |
303 |
| - import java.util.List; |
304 |
| - public class Constants { |
305 |
| - public static final String FOO = null; |
306 |
| - } |
307 |
| - class A { |
308 |
| - private <T> void r(T e) { |
309 |
| - Constants.FOO.equals(e.toString()); |
310 |
| - } |
311 |
| - } |
312 |
| - """ |
313 |
| - ) |
314 |
| - ); |
315 |
| - } |
316 |
| - |
317 |
| - @Test |
318 |
| - void lambda() { |
319 |
| - rewriteRun( |
320 |
| - //language=java |
321 |
| - java( |
322 |
| - """ |
323 |
| - import java.util.List; |
324 |
| - public class Constants { |
325 |
| - public static final String FOO = null; |
326 |
| - } |
327 |
| - class A { |
328 |
| - private void isFoo(List<Object> list) { |
329 |
| - list.stream().filter(c -> c.toString().contentEquals(Constants.FOO)); |
330 |
| - } |
331 |
| - } |
332 |
| - """, |
333 |
| - """ |
334 |
| - import java.util.List; |
335 |
| - public class Constants { |
336 |
| - public static final String FOO = null; |
337 |
| - } |
338 |
| - class A { |
339 |
| - private void isFoo(List<Object> list) { |
340 |
| - list.stream().filter(c -> Constants.FOO.contentEquals(c.toString())); |
341 |
| - } |
342 |
| - } |
343 |
| - """ |
344 |
| - ) |
345 |
| - ); |
346 |
| - } |
347 |
| - |
348 |
| - @Test |
349 |
| - @Disabled("Not yet supported") |
350 |
| - void lambdaGenerics() { |
351 |
| - rewriteRun( |
352 |
| - //language=java |
353 |
| - java( |
354 |
| - """ |
355 |
| - import java.util.List; |
356 |
| - public class Constants { |
357 |
| - public static final String FOO = null; |
358 |
| - } |
359 |
| - class C { |
360 |
| - boolean c(String k) { |
361 |
| - return true; |
362 |
| - } |
363 |
| -
|
364 |
| - Object get(String k) { |
365 |
| - return null; |
366 |
| - } |
367 |
| -
|
368 |
| - void r(String k, String v) { |
369 |
| - } |
370 |
| - } |
371 |
| - class A { |
372 |
| - private <T extends C> void rr(List<String> f, T e) { |
373 |
| - f.stream() |
374 |
| - .filter(fn -> e.c(fn)) |
375 |
| - .forEach(fn -> e.get(fn).equals(Constants.FOO)); |
376 |
| - } |
377 |
| - } |
378 |
| - """, |
379 |
| - """ |
380 |
| - import java.util.List; |
381 |
| - public class Constants { |
382 |
| - public static final String FOO = null; |
383 |
| - } |
384 |
| - class C { |
385 |
| - boolean c(String k) { |
386 |
| - return true; |
387 |
| - } |
388 |
| -
|
389 |
| - Object get(String k) { |
390 |
| - return null; |
391 |
| - } |
392 |
| -
|
393 |
| - void r(String k, String v) { |
394 |
| - } |
395 |
| - } |
396 |
| - class A { |
397 |
| - private <T extends C> void rr(List<String> f, T e) { |
398 |
| - f.stream() |
399 |
| - .filter(fn -> e.c(fn)) |
400 |
| - .forEach(fn -> Constants.FOO.equals(e.get(fn))); |
401 |
| - } |
402 |
| - } |
403 |
| - """ |
404 |
| - ) |
405 |
| - ); |
406 |
| - } |
407 |
| - |
408 |
| - @Test |
409 |
| - void nonStaticNonFinalNoChange() { |
410 |
| - rewriteRun( |
411 |
| - // language=java |
412 |
| - java( |
413 |
| - """ |
414 |
| - public class Constants { |
415 |
| - public final String FOO = null; |
416 |
| - public static String BAR = null; |
417 |
| - } |
418 |
| - class A { |
419 |
| - private boolean isFoo(String foo) { |
420 |
| - return foo.contentEquals(new Constants().FOO); |
421 |
| - } |
422 |
| - private boolean isBar(String bar) { |
423 |
| - return bar.contentEquals(Constants.BAR); |
424 |
| - } |
425 |
| - } |
426 |
| - """ |
427 |
| - ) |
428 |
| - ); |
429 |
| - } |
430 |
| - |
431 | 143 | @Test
|
432 | 144 | @Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/434")
|
433 | 145 | void missingWhitespace() {
|
|
0 commit comments