tech.picnic.errorprone.refasterrules.AssertJDoubleRulesRecipes Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of error-prone-contrib Show documentation
Show all versions of error-prone-contrib Show documentation
Extra Error Prone plugins by Picnic.
package tech.picnic.errorprone.refasterrules;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.search.*;
import org.openrewrite.java.template.Primitive;
import org.openrewrite.java.template.function.*;
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;
import javax.annotation.Generated;
import java.util.*;
import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
/**
* OpenRewrite recipes created for Refaster template {@code tech.picnic.errorprone.refasterrules.AssertJDoubleRules}.
*/
@SuppressWarnings("all")
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class AssertJDoubleRulesRecipes extends Recipe {
/**
* Instantiates a new instance.
*/
public AssertJDoubleRulesRecipes() {}
@Override
public String getDisplayName() {
return "`AssertJDoubleRules` Refaster recipes";
}
@Override
public String getDescription() {
return "Refaster template recipes for `tech.picnic.errorprone.refasterrules.AssertJDoubleRules`. [Source](https://error-prone.picnic.tech/refasterrules/AssertJDoubleRules).";
}
@Override
public List getRecipeList() {
return Arrays.asList(
new AbstractDoubleAssertIsCloseToWithOffsetRecipe(),
new AbstractDoubleAssertIsEqualToRecipe(),
new AbstractDoubleAssertIsNotEqualToRecipe(),
new AbstractDoubleAssertIsZeroRecipe(),
new AbstractDoubleAssertIsNotZeroRecipe(),
new AbstractDoubleAssertIsOneRecipe()
);
}
/**
* OpenRewrite recipe created for Refaster template {@code AssertJDoubleRules.AbstractDoubleAssertIsCloseToWithOffset}.
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class AbstractDoubleAssertIsCloseToWithOffsetRecipe extends Recipe {
/**
* Instantiates a new instance.
*/
public AbstractDoubleAssertIsCloseToWithOffsetRecipe() {}
@Override
public String getDisplayName() {
return "Refaster template `AssertJDoubleRules.AbstractDoubleAssertIsCloseToWithOffset`";
}
@Override
public String getDescription() {
return "Recipe created for the following Refaster template:\n```java\nstatic final class AbstractDoubleAssertIsCloseToWithOffset {\n \n @BeforeTemplate\n AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert, double n, Offset offset) {\n return doubleAssert.isEqualTo(n, offset);\n }\n \n @BeforeTemplate\n AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert, Double n, Offset offset) {\n return doubleAssert.isEqualTo(n, offset);\n }\n \n @AfterTemplate\n AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert, double n, Offset offset) {\n return doubleAssert.isCloseTo(n, offset);\n }\n}\n```\n.";
}
@Override
public TreeVisitor, ExecutionContext> getVisitor() {
JavaVisitor javaVisitor = new AbstractRefasterJavaVisitor() {
final JavaTemplate before = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isEqualTo(#{n:any(double)}, #{offset:any(org.assertj.core.data.Offset)})")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
final JavaTemplate before0 = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isEqualTo(#{n:any(java.lang.Double)}, #{offset:any(org.assertj.core.data.Offset)})")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
final JavaTemplate after = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isCloseTo(#{n:any(double)}, #{offset:any(org.assertj.core.data.Offset)})")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
@Override
public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
JavaTemplate.Matcher matcher;
if ((matcher = before.matcher(getCursor())).find()) {
return embed(
after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0), matcher.parameter(1), matcher.parameter(2)),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
if ((matcher = before0.matcher(getCursor())).find()) {
return embed(
after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0), matcher.parameter(1), matcher.parameter(2)),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
return super.visitMethodInvocation(elem, ctx);
}
};
return Preconditions.check(
Preconditions.and(
new UsesType<>("org.assertj.core.api.AbstractDoubleAssert", true),
new UsesType<>("org.assertj.core.data.Offset", true),
new UsesMethod<>("org.assertj.core.api.AbstractDoubleAssert isEqualTo(..)")
),
javaVisitor
);
}
}
/**
* OpenRewrite recipe created for Refaster template {@code AssertJDoubleRules.AbstractDoubleAssertIsEqualTo}.
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class AbstractDoubleAssertIsEqualToRecipe extends Recipe {
/**
* Instantiates a new instance.
*/
public AbstractDoubleAssertIsEqualToRecipe() {}
@Override
public String getDisplayName() {
return "Refaster template `AssertJDoubleRules.AbstractDoubleAssertIsEqualTo`";
}
@Override
public String getDescription() {
return "Recipe created for the following Refaster template:\n```java\nstatic final class AbstractDoubleAssertIsEqualTo {\n \n @BeforeTemplate\n AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert, double n) {\n return Refaster.anyOf(doubleAssert.isCloseTo(n, offset(0.0)), doubleAssert.isCloseTo(n, withPercentage(0.0)));\n }\n \n @AfterTemplate\n AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert, double n) {\n return doubleAssert.isEqualTo(n);\n }\n}\n```\n.";
}
@Override
public TreeVisitor, ExecutionContext> getVisitor() {
JavaVisitor javaVisitor = new AbstractRefasterJavaVisitor() {
final JavaTemplate before$0 = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isCloseTo(#{n:any(double)}, org.assertj.core.data.Offset.offset(0.0))")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
final JavaTemplate before$1 = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isCloseTo(#{n:any(double)}, org.assertj.core.data.Percentage.withPercentage(0.0))")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
final JavaTemplate after = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isEqualTo(#{n:any(double)})")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
@Override
public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
JavaTemplate.Matcher matcher;
if ((matcher = before$0.matcher(getCursor())).find()) {
maybeRemoveImport("org.assertj.core.data.Offset.offset");
return embed(
after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0), matcher.parameter(1)),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
if ((matcher = before$1.matcher(getCursor())).find()) {
maybeRemoveImport("org.assertj.core.data.Percentage.withPercentage");
return embed(
after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0), matcher.parameter(1)),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
return super.visitMethodInvocation(elem, ctx);
}
};
return Preconditions.check(
Preconditions.and(
new UsesType<>("org.assertj.core.api.AbstractDoubleAssert", true),
new UsesMethod<>("org.assertj.core.api.AbstractDoubleAssert isCloseTo(..)"),
Preconditions.or(
new UsesMethod<>("org.assertj.core.data.Offset offset(..)"),
new UsesMethod<>("org.assertj.core.data.Percentage withPercentage(..)")
)
),
javaVisitor
);
}
}
/**
* OpenRewrite recipe created for Refaster template {@code AssertJDoubleRules.AbstractDoubleAssertIsNotEqualTo}.
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class AbstractDoubleAssertIsNotEqualToRecipe extends Recipe {
/**
* Instantiates a new instance.
*/
public AbstractDoubleAssertIsNotEqualToRecipe() {}
@Override
public String getDisplayName() {
return "Refaster template `AssertJDoubleRules.AbstractDoubleAssertIsNotEqualTo`";
}
@Override
public String getDescription() {
return "Recipe created for the following Refaster template:\n```java\nstatic final class AbstractDoubleAssertIsNotEqualTo {\n \n @BeforeTemplate\n AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert, double n) {\n return Refaster.anyOf(doubleAssert.isNotCloseTo(n, offset(0.0)), doubleAssert.isNotCloseTo(n, withPercentage(0.0)));\n }\n \n @AfterTemplate\n AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert, double n) {\n return doubleAssert.isNotEqualTo(n);\n }\n}\n```\n.";
}
@Override
public TreeVisitor, ExecutionContext> getVisitor() {
JavaVisitor javaVisitor = new AbstractRefasterJavaVisitor() {
final JavaTemplate before$0 = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isNotCloseTo(#{n:any(double)}, org.assertj.core.data.Offset.offset(0.0))")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
final JavaTemplate before$1 = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isNotCloseTo(#{n:any(double)}, org.assertj.core.data.Percentage.withPercentage(0.0))")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
final JavaTemplate after = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isNotEqualTo(#{n:any(double)})")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
@Override
public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
JavaTemplate.Matcher matcher;
if ((matcher = before$0.matcher(getCursor())).find()) {
maybeRemoveImport("org.assertj.core.data.Offset.offset");
return embed(
after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0), matcher.parameter(1)),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
if ((matcher = before$1.matcher(getCursor())).find()) {
maybeRemoveImport("org.assertj.core.data.Percentage.withPercentage");
return embed(
after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0), matcher.parameter(1)),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
return super.visitMethodInvocation(elem, ctx);
}
};
return Preconditions.check(
Preconditions.and(
new UsesType<>("org.assertj.core.api.AbstractDoubleAssert", true),
new UsesMethod<>("org.assertj.core.api.AbstractDoubleAssert isNotCloseTo(..)"),
Preconditions.or(
new UsesMethod<>("org.assertj.core.data.Offset offset(..)"),
new UsesMethod<>("org.assertj.core.data.Percentage withPercentage(..)")
)
),
javaVisitor
);
}
}
/**
* OpenRewrite recipe created for Refaster template {@code AssertJDoubleRules.AbstractDoubleAssertIsZero}.
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class AbstractDoubleAssertIsZeroRecipe extends Recipe {
/**
* Instantiates a new instance.
*/
public AbstractDoubleAssertIsZeroRecipe() {}
@Override
public String getDisplayName() {
return "Refaster template `AssertJDoubleRules.AbstractDoubleAssertIsZero`";
}
@Override
public String getDescription() {
return "Recipe created for the following Refaster template:\n```java\nstatic final class AbstractDoubleAssertIsZero {\n \n @BeforeTemplate\n AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert) {\n return doubleAssert.isZero();\n }\n \n @AfterTemplate\n AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert) {\n return doubleAssert.isEqualTo(0);\n }\n}\n```\n.";
}
@Override
public TreeVisitor, ExecutionContext> getVisitor() {
JavaVisitor javaVisitor = new AbstractRefasterJavaVisitor() {
final JavaTemplate before = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isZero()")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
final JavaTemplate after = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isEqualTo(0)")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
@Override
public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
JavaTemplate.Matcher matcher;
if ((matcher = before.matcher(getCursor())).find()) {
return embed(
after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0)),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
return super.visitMethodInvocation(elem, ctx);
}
};
return Preconditions.check(
Preconditions.and(
new UsesType<>("org.assertj.core.api.AbstractDoubleAssert", true),
new UsesMethod<>("org.assertj.core.api.AbstractDoubleAssert isZero(..)")
),
javaVisitor
);
}
}
/**
* OpenRewrite recipe created for Refaster template {@code AssertJDoubleRules.AbstractDoubleAssertIsNotZero}.
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class AbstractDoubleAssertIsNotZeroRecipe extends Recipe {
/**
* Instantiates a new instance.
*/
public AbstractDoubleAssertIsNotZeroRecipe() {}
@Override
public String getDisplayName() {
return "Refaster template `AssertJDoubleRules.AbstractDoubleAssertIsNotZero`";
}
@Override
public String getDescription() {
return "Recipe created for the following Refaster template:\n```java\nstatic final class AbstractDoubleAssertIsNotZero {\n \n @BeforeTemplate\n AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert) {\n return doubleAssert.isNotZero();\n }\n \n @AfterTemplate\n AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert) {\n return doubleAssert.isNotEqualTo(0);\n }\n}\n```\n.";
}
@Override
public TreeVisitor, ExecutionContext> getVisitor() {
JavaVisitor javaVisitor = new AbstractRefasterJavaVisitor() {
final JavaTemplate before = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isNotZero()")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
final JavaTemplate after = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isNotEqualTo(0)")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
@Override
public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
JavaTemplate.Matcher matcher;
if ((matcher = before.matcher(getCursor())).find()) {
return embed(
after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0)),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
return super.visitMethodInvocation(elem, ctx);
}
};
return Preconditions.check(
Preconditions.and(
new UsesType<>("org.assertj.core.api.AbstractDoubleAssert", true),
new UsesMethod<>("org.assertj.core.api.AbstractDoubleAssert isNotZero(..)")
),
javaVisitor
);
}
}
/**
* OpenRewrite recipe created for Refaster template {@code AssertJDoubleRules.AbstractDoubleAssertIsOne}.
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class AbstractDoubleAssertIsOneRecipe extends Recipe {
/**
* Instantiates a new instance.
*/
public AbstractDoubleAssertIsOneRecipe() {}
@Override
public String getDisplayName() {
return "Refaster template `AssertJDoubleRules.AbstractDoubleAssertIsOne`";
}
@Override
public String getDescription() {
return "Recipe created for the following Refaster template:\n```java\nstatic final class AbstractDoubleAssertIsOne {\n \n @BeforeTemplate\n AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert) {\n return doubleAssert.isOne();\n }\n \n @AfterTemplate\n AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert) {\n return doubleAssert.isEqualTo(1);\n }\n}\n```\n.";
}
@Override
public TreeVisitor, ExecutionContext> getVisitor() {
JavaVisitor javaVisitor = new AbstractRefasterJavaVisitor() {
final JavaTemplate before = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isOne()")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
final JavaTemplate after = JavaTemplate
.builder("#{doubleAssert:any(org.assertj.core.api.AbstractDoubleAssert>)}.isEqualTo(1)")
.javaParser(JavaParser.fromJavaVersion().classpath(JavaParser.runtimeClasspath()))
.build();
@Override
public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
JavaTemplate.Matcher matcher;
if ((matcher = before.matcher(getCursor())).find()) {
return embed(
after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0)),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
return super.visitMethodInvocation(elem, ctx);
}
};
return Preconditions.check(
Preconditions.and(
new UsesType<>("org.assertj.core.api.AbstractDoubleAssert", true),
new UsesMethod<>("org.assertj.core.api.AbstractDoubleAssert isOne(..)")
),
javaVisitor
);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy