File tree 1 file changed +104
-0
lines changed
src/test/java/org/openrewrite/staticanalysis
1 file changed +104
-0
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import org .junit .jupiter .api .Test ;
19
19
import org .openrewrite .DocumentExample ;
20
+ import org .openrewrite .Issue ;
20
21
import org .openrewrite .Tree ;
21
22
import org .openrewrite .java .JavaParser ;
22
23
import org .openrewrite .java .style .Checkstyle ;
@@ -328,4 +329,107 @@ static void method() {
328
329
)
329
330
);
330
331
}
332
+
333
+ @ Issue ("https://github.com/openrewrite/rewrite-static-analysis/issues/315" )
334
+ @ Test
335
+ void commentsBeforeElseBlockWithNoBraces () {
336
+ rewriteRun (
337
+ //language=java
338
+ java (
339
+ """
340
+ class Test {
341
+ static void method() {
342
+ if (true) {
343
+ return;
344
+ }
345
+ /*
346
+ * else comment
347
+ */
348
+ else return;
349
+ }
350
+ }
351
+ """ ,
352
+ """
353
+ class Test {
354
+ static void method() {
355
+ if (true) {
356
+ return; // if comment
357
+ } else {
358
+ /*
359
+ * else comment
360
+ */
361
+ return;
362
+ }
363
+ }
364
+ }
365
+ """
366
+ )
367
+ );
368
+ }
369
+
370
+ @ Issue ("https://github.com/openrewrite/rewrite-static-analysis/issues/315" )
371
+ @ Test
372
+ void commentsBeforeElseBlockWithBraces () {
373
+ rewriteRun (
374
+ //language=java
375
+ java (
376
+ """
377
+ class Test {
378
+ static void method() {
379
+ if (true)
380
+ return;
381
+ // if comment
382
+ else{
383
+ return;
384
+ }
385
+ }
386
+ }
387
+ """ ,
388
+ """
389
+ class Test {
390
+ static void method() {
391
+ if (true) {
392
+ return;
393
+ // if comment
394
+ } else {
395
+ return;
396
+ }
397
+ }
398
+ }
399
+ """
400
+ )
401
+ );
402
+ }
403
+
404
+ @ Issue ("https://github.com/openrewrite/rewrite-static-analysis/issues/315" )
405
+ @ Test
406
+ void trailingCommentsElseBlock () {
407
+ rewriteRun (
408
+ //language=java
409
+ java (
410
+ """
411
+ class Test {
412
+ static void method() {
413
+ if (true) return; // if comment
414
+ else if (false) return; // else if comment
415
+ else return; // else comment
416
+ }
417
+ }
418
+ """ ,
419
+ """
420
+ class Test {
421
+ static void method() {
422
+ if (true) {
423
+ return; // comment
424
+ } else if (false) {
425
+ return; // else if comment
426
+ } else {
427
+ return; // else comment
428
+ }
429
+ }
430
+ }
431
+ """
432
+ )
433
+ );
434
+ }
331
435
}
You can’t perform that action at this time.
0 commit comments