Skip to content

Commit edfda4f

Browse files
committed
Initial Tests
1 parent 205d158 commit edfda4f

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

src/test/java/org/openrewrite/staticanalysis/NeedBracesTest.java

+104
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.junit.jupiter.api.Test;
1919
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.Issue;
2021
import org.openrewrite.Tree;
2122
import org.openrewrite.java.JavaParser;
2223
import org.openrewrite.java.style.Checkstyle;
@@ -328,4 +329,107 @@ static void method() {
328329
)
329330
);
330331
}
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+
}
331435
}

0 commit comments

Comments
 (0)