Skip to content

Commit

Permalink
Format JavaTemplateTest.addAnnotation to minimize review bot spam
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Nov 11, 2024
1 parent fda000b commit 7e61807
Showing 1 changed file with 60 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,32 @@ class JavaTemplateTest implements RewriteTest {

@Test
void addAnnotation() {
rewriteRun(
spec -> spec.recipe(toRecipe(() -> new JavaIsoVisitor<>() {
private final JavaTemplate template = JavaTemplate.builder("@SuppressWarnings({\"ALL\"})")
.build();
@Override
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext executionContext) {
J.ClassDeclaration cd = classDecl;
if(!cd.getLeadingAnnotations().isEmpty()) {
return cd;
}
cd = template.apply(updateCursor(cd), cd.getCoordinates().addAnnotation(comparing(J.Annotation::getSimpleName)));
return cd;
}
})),
java(
"""
public class A {
}
""",
"""
@SuppressWarnings({"ALL"})
public class A {
}
"""
)
);
rewriteRun(
spec -> spec.recipe(toRecipe(() -> new JavaIsoVisitor<>() {
private final JavaTemplate template = JavaTemplate.builder("@SuppressWarnings({\"ALL\"})").build();

@Override
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) {
J.ClassDeclaration cd = classDecl;
if (!cd.getLeadingAnnotations().isEmpty()) {
return cd;
}
cd = template.apply(updateCursor(cd), cd.getCoordinates().addAnnotation(comparing(J.Annotation::getSimpleName)));
return cd;
}
})),
java(
"""
public class A {
}
""",
"""
@SuppressWarnings({"ALL"})
public class A {
}
"""
)
);
}

@Issue("https://github.com/openrewrite/rewrite/issues/2090")
Expand Down Expand Up @@ -370,7 +370,7 @@ class T {
void m() {
hashCode();
}
void m2() {
hashCode();
}
Expand Down Expand Up @@ -594,7 +594,7 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
"""
import java.math.BigDecimal;
import java.math.RoundingMode;
class A {
void m() {
StringBuilder sb = new StringBuilder();
Expand All @@ -605,7 +605,7 @@ void m() {
"""
import java.math.BigDecimal;
import java.math.RoundingMode;
class A {
void m() {
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -793,20 +793,20 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
class A {
public enum Type {
One;
public Type(String t) {
}
String t;
public static Type fromType(String type) {
return null;
}
}
public A(Type type) {}
public A() {}
public void method(Type type) {
new A(type);
}
Expand All @@ -816,20 +816,20 @@ public void method(Type type) {
class A {
public enum Type {
One;
public Type(String t) {
}
String t;
public static Type fromType(String type) {
return null;
}
}
public A(Type type) {}
public A() {}
public void method(Type type) {
new A();
}
Expand Down Expand Up @@ -861,7 +861,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
java(
"""
package abc;
public class ArrayHelper {
public static Object[] of(Object... objects){ return null;}
}
Expand All @@ -871,7 +871,7 @@ public class ArrayHelper {
"""
import abc.ArrayHelper;
import java.util.Arrays;
class A {
Object[] o = new Object[] {
ArrayHelper.of(1, 2, 3)
Expand All @@ -881,7 +881,7 @@ class A {
"""
import abc.ArrayHelper;
import java.util.Arrays;
class A {
Object[] o = new Object[] {
Arrays.asList(1, 2, 3)
Expand Down Expand Up @@ -937,7 +937,7 @@ public J visitBinary(J.Binary binary, ExecutionContext ctx) {
java(
"""
import java.util.Collection;
class Test {
void doSomething(Collection<Object> c) {
assert c.size() > 0;
Expand All @@ -946,7 +946,7 @@ void doSomething(Collection<Object> c) {
""",
"""
import java.util.Collection;
class Test {
void doSomething(Collection<Object> c) {
assert !c.isEmpty();
Expand All @@ -971,13 +971,13 @@ public J visitBinary(J.Binary binary, ExecutionContext ctx) {
"""
enum Outer {
A, B;
enum Inner {
C, D
}
private final String s;
Outer() {
s = "a" + "b";
}
Expand All @@ -986,13 +986,13 @@ enum Inner {
"""
enum Outer {
A, B;
enum Inner {
C, D
}
private final String s;
Outer() {
s = "ab";
}
Expand Down Expand Up @@ -1156,7 +1156,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
"""
import java.util.Map;
import org.junit.jupiter.api.Assertions;
class T {
void m(String one, Map<String, ?> map) {
Assertions.assertEquals(one, map.get("one"));
Expand All @@ -1165,9 +1165,9 @@ void m(String one, Map<String, ?> map) {
""",
"""
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
class T {
void m(String one, Map<String, ?> map) {
assertThat(map.get("one")).isEqualTo(one);
Expand Down Expand Up @@ -1212,7 +1212,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
import java.util.Objects;
import java.util.Map;
import java.util.HashMap;
class T {
void m() {
Map<String, ?> map = new HashMap<>();
Expand All @@ -1223,10 +1223,10 @@ void m() {
"""
import java.util.Objects;
import java.util.Map;
import static java.util.Objects.requireNonNull;
import java.util.HashMap;
class T {
void m() {
Map<String, ?> map = new HashMap<>();
Expand Down Expand Up @@ -1254,13 +1254,13 @@ public J visitVariableDeclarations(J.VariableDeclarations multiVariable, Executi
java(
"""
interface Test {
String a;
}
""",
"""
interface Test {
String a();
}
"""
Expand All @@ -1275,13 +1275,13 @@ void finalMethodParameter() {
java(
"""
import org.jetbrains.annotations.NotNull;
class A {
String testMethod(@NotNull final String test) {}
}
""", """
import lombok.NonNull;
class A {
String testMethod(@NonNull final String test) {}
}
Expand Down

0 comments on commit 7e61807

Please sign in to comment.