Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
new MethodMatcher(ecfqn + " equals(" + ecfqn + ")").matches(m, enclosingClass)) {

if (!service(AnnotationService.class).matches(getCursor(), OVERRIDE_ANNOTATION)) {
m = JavaTemplate.builder("@Override").build()
.apply(updateCursor(m),
m.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName)));
m = JavaTemplate.apply("@Override", updateCursor(m), m.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName)));
}

/*
Expand All @@ -97,10 +95,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
*/
J.VariableDeclarations.NamedVariable oldParamName = ((J.VariableDeclarations) m.getParameters().get(0)).getVariables().get(0);
String paramName = "obj".equals(oldParamName.getSimpleName()) ? "other" : "obj";
m = JavaTemplate.builder("Object #{}").build()
.apply(updateCursor(m),
m.getCoordinates().replaceParameters(),
paramName);
m = JavaTemplate.apply("Object #{}", updateCursor(m), m.getCoordinates().replaceParameters(), paramName);

/*
* We'll prepend this type-check and type-cast to the beginning of the existing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ public J.Binary visitBinary(J.Binary binary, ExecutionContext ctx) {

J.MethodInvocation m = (J.MethodInvocation) b.getLeft();
Cursor cursor = new Cursor(getCursor(), b.getLeft());
b = b.withLeft(JavaTemplate.builder("#{any(java.lang.String)}, #{any(int)}").build()
.apply(cursor,
m.getCoordinates().replaceArguments(),
m.getArguments().get(0),
b.getRight()));
b = b.withLeft(JavaTemplate.apply("#{any(java.lang.String)}, #{any(int)}", cursor, m.getCoordinates().replaceArguments(), m.getArguments().get(0), b.getRight()));

b = b.withRight(new J.Literal(
Tree.randomId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public J visitBinary(J.Binary binary, ExecutionContext ctx) {
boolean isGreaterThanOrEqualToZero = asBinary.getOperator() == J.Binary.Type.GreaterThanOrEqual && "0".equals(valueSource);
if (isGreaterThanNegativeOne || isGreaterThanOrEqualToZero) {
Cursor cursor = new Cursor(updateCursor(asBinary), asBinary.getLeft());
j = JavaTemplate.builder("#{any()}.contains(#{any()})").build()
.apply(cursor, mi.getCoordinates().replace(), mi.getSelect(), mi.getArguments().get(0))
j = JavaTemplate.apply("#{any()}.contains(#{any()})", cursor, mi.getCoordinates().replace(), mi.getSelect(), mi.getArguments().get(0))
.withPrefix(asBinary.getPrefix());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
}
return l;
}
return JavaTemplate.builder("String.valueOf(#{any()})").build()
.apply(new Cursor(getCursor(), arg), arg.getCoordinates().replace(), arg);
return JavaTemplate.apply("String.valueOf(#{any()})", new Cursor(getCursor(), arg), arg.getCoordinates().replace(), arg);
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ public J visitMethodInvocation(MethodInvocation method, ExecutionContext ctx) {
FieldAccess fieldAccessPart = (FieldAccess) method.getSelect();
// upcast to type J, so J.MethodInvocation can be replaced by J.InstanceOf
JavaCoordinates coordinates = method.getCoordinates().replace();
J updated = JavaTemplate.builder("#{any()} instanceof Object")
.build()
.apply(getCursor(), coordinates, objectExpression);
J updated = JavaTemplate.apply("#{any()} instanceof Object", getCursor(), coordinates, objectExpression);
updated = mapInstanceOf(updated,
instanceOf -> instanceOf.withClazz(fieldAccessPart.getTarget().withPrefix(instanceOf.getClazz().getPrefix())));
return maybeAutoFormat(method, updated, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ private List<Expression> adjustExpressions(J.MethodInvocation method, List<Expre
if (arg instanceof J.Literal) {
return toStringLiteral((J.Literal) arg);
}
return JavaTemplate.builder("String.valueOf(#{any()})").build()
.apply(getCursor(), method.getCoordinates().replace(), arg)
return JavaTemplate.apply("String.valueOf(#{any()})", getCursor(), method.getCoordinates().replace(), arg)
.withPrefix(arg.getPrefix());
}
} else if (!(arg instanceof J.Identifier || arg instanceof J.Literal || arg instanceof J.MethodInvocation)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ public J visitBinary(J.Binary binary, ExecutionContext ctx) {
// Avoid breaking symmetry in chained String concatenations
!(binary.getRight() instanceof J.Binary) &&
!(getCursor().getParentTreeCursor().getValue() instanceof J.Binary)) {
return JavaTemplate.builder("String.valueOf(#{any()})")
.build()
.apply(getCursor(),
binary.getCoordinates().replace(),
binary.getRight() instanceof J.Parentheses ?
((J.Parentheses<?>) binary.getRight()).getTree() : binary.getRight())
return JavaTemplate.apply("String.valueOf(#{any()})", getCursor(), binary.getCoordinates().replace(), binary.getRight() instanceof J.Parentheses ?
((J.Parentheses<?>) binary.getRight()).getTree() : binary.getRight())
.withPrefix(binary.getPrefix());
}
return super.visitBinary(binary, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ public J visitBinary(J.Binary binary, ExecutionContext ctx) {
}

// General fallback: A <= B → A < B + 1
return JavaTemplate.builder("#{any()} < #{any()} + 1").build()
.apply(getCursor(), binary.getCoordinates().replace(),
binary.getLeft(), binary.getRight());
return JavaTemplate.apply("#{any()} < #{any()} + 1", getCursor(), binary.getCoordinates().replace(), binary.getLeft(), binary.getRight());
}

private J.@Nullable Binary tryAdjustRight(J.Binary binary, J.Binary rightArith) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
J.MethodInvocation mi = super.visitMethodInvocation(method, ctx);
if (removeAll.matches(mi) && !returnValueIsUsed()) {
mi = JavaTemplate.builder("#{any(java.util.Collection)}.forEach(#{any(java.util.Set)}::remove)")
.build()
.apply(updateCursor(mi), mi.getCoordinates().replace(), mi.getArguments().get(0), mi.getSelect());
mi = JavaTemplate.apply("#{any(java.util.Collection)}.forEach(#{any(java.util.Set)}::remove)", updateCursor(mi), mi.getCoordinates().replace(), mi.getArguments().get(0), mi.getSelect());
}
return mi;
}
Expand Down
Loading