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 @@ -25,9 +25,10 @@
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaAtomicsNewReference extends Recipe {
private static final MethodMatcher NEW_ATOMIC_REFERENCE = new MethodMatcher("com.google.common.util.concurrent.Atomics newReference(..)");

Expand All @@ -43,7 +44,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaDirectExecutor extends Recipe {
private static final MethodMatcher DIRECT_EXECUTOR = new MethodMatcher("com.google.common.util.concurrent.MoreExecutors directExecutor()");

Expand All @@ -43,7 +44,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.TypeUtils;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaListsNewArrayList extends Recipe {
private static final MethodMatcher NEW_ARRAY_LIST = new MethodMatcher("com.google.common.collect.Lists newArrayList()");
private static final MethodMatcher NEW_ARRAY_LIST_ITERABLE = new MethodMatcher("com.google.common.collect.Lists newArrayList(java.lang.Iterable)");
Expand All @@ -46,7 +47,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.TypeUtils;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaListsNewCopyOnWriteArrayList extends Recipe {
private static final MethodMatcher NEW_ARRAY_LIST = new MethodMatcher("com.google.common.collect.Lists newCopyOnWriteArrayList()");
private static final MethodMatcher NEW_ARRAY_LIST_ITERABLE = new MethodMatcher("com.google.common.collect.Lists newCopyOnWriteArrayList(java.lang.Iterable)");
Expand All @@ -45,7 +46,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.TypeUtils;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaListsNewLinkedList extends Recipe {
private static final MethodMatcher NEW_LINKED_LIST = new MethodMatcher("com.google.common.collect.Lists newLinkedList()");
private static final MethodMatcher NEW_LINKED_LIST_ITERABLE = new MethodMatcher("com.google.common.collect.Lists newLinkedList(java.lang.Iterable)");
Expand All @@ -45,7 +46,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaMapsNewHashMap extends Recipe {
private static final MethodMatcher NEW_HASH_MAP = new MethodMatcher("com.google.common.collect.Maps newHashMap()");
private static final MethodMatcher NEW_HASH_MAP_WITH_MAP = new MethodMatcher("com.google.common.collect.Maps newHashMap(java.util.Map)");
Expand All @@ -44,7 +45,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaMapsNewLinkedHashMap extends Recipe {
private static final MethodMatcher NEW_LINKED_HASH_MAP = new MethodMatcher("com.google.common.collect.Maps newLinkedHashMap()");
private static final MethodMatcher NEW_LINKED_HASH_MAP_WITH_MAP = new MethodMatcher("com.google.common.collect.Maps newLinkedHashMap(java.util.Map)");
Expand All @@ -44,7 +45,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaMapsNewTreeMap extends Recipe {
private static final MethodMatcher NEW_TREE_MAP = new MethodMatcher("com.google.common.collect.Maps newTreeMap()");
private static final MethodMatcher NEW_TREE_MAP_WITH_COMPARATOR = new MethodMatcher("com.google.common.collect.Maps newTreeMap(java.util.Comparator)");
Expand All @@ -45,7 +46,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import static java.util.Collections.nCopies;

public class NoGuavaPrimitiveAsList extends Recipe {

Expand Down Expand Up @@ -59,7 +59,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation elem, Executi
maybeRemoveImport("com.google.common.primitives.Bytes");
maybeAddImport("java.util.Arrays");

String args = String.join(",", Collections.nCopies(elem.getArguments().size(), "#{any()}"));
String args = String.join(",", nCopies(elem.getArguments().size(), "#{any()}"));
return JavaTemplate
.builder("Arrays.asList(" + args + ')')
.imports("java.util.Arrays")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaSetsNewConcurrentHashSet extends Recipe {
private static final MethodMatcher NEW_HASH_SET = new MethodMatcher("com.google.common.collect.Sets newConcurrentHashSet()");

Expand All @@ -43,7 +44,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.TypeUtils;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.Collections.singleton;
import static java.util.stream.Collectors.joining;

public class NoGuavaSetsNewHashSet extends Recipe {
private static final MethodMatcher NEW_HASH_SET = new MethodMatcher("com.google.common.collect.Sets newHashSet(..)");
Expand All @@ -45,7 +46,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand All @@ -71,7 +72,7 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
.apply(getCursor(), method.getCoordinates().replace(), method.getArguments().get(0));
}
maybeAddImport("java.util.Arrays");
JavaTemplate newHashSetVarargs = JavaTemplate.builder("new HashSet<>(Arrays.asList(" + method.getArguments().stream().map(a -> "#{any()}").collect(Collectors.joining(",")) + "))")
JavaTemplate newHashSetVarargs = JavaTemplate.builder("new HashSet<>(Arrays.asList(" + method.getArguments().stream().map(a -> "#{any()}").collect(joining(",")) + "))")
.contextSensitive()
.imports("java.util.Arrays")
.imports("java.util.HashSet")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.TypeUtils;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class NoGuavaSetsNewLinkedHashSet extends Recipe {
private static final MethodMatcher NEW_LINKED_HASH_SET = new MethodMatcher("com.google.common.collect.Sets newLinkedHashSet()");
private static final MethodMatcher NEW_LINKED_HASH_SET_ITERABLE = new MethodMatcher("com.google.common.collect.Sets newLinkedHashSet(java.lang.Iterable)");
Expand All @@ -46,7 +47,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.search.UsesMethod;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

public class PreferJavaStringJoin extends Recipe {

static final MethodMatcher JOIN_METHOD_MATCHER = new MethodMatcher("com.google.common.base.Joiner join(..)");
Expand All @@ -41,7 +42,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("guava");
return singleton("guava");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.TypeUtils;

import java.util.Collections;
import java.util.Set;

import static java.util.Collections.singleton;

@EqualsAndHashCode(callSuper = false)
@Value
public class ReplaceFileInOrOutputStreamFinalizeWithClose extends Recipe {
Expand All @@ -53,7 +54,7 @@ public String getDescription() {

@Override
public Set<String> getTags() {
return Collections.singleton("JDK-8212050");
return singleton("JDK-8212050");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import static java.util.Collections.singletonList;

public class ApplicationPathWildcardNoLongerAccepted extends Recipe {
@Override
Expand Down Expand Up @@ -61,15 +61,15 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct
String value = literal.getValue().toString();
if (value.endsWith("/*")) {
String newValue = "\"" + value.substring(0, value.length() - 2) + "\"";
return a.withArguments(Collections.singletonList(assig.withAssignment(literal.withValue(newValue).withValueSource(newValue))));
return a.withArguments(singletonList(assig.withAssignment(literal.withValue(newValue).withValueSource(newValue))));
}
} // Should we handle constants?
} else if (it instanceof J.Literal) {
J.Literal literal = (J.Literal) it;
String value = literal.getValue().toString();
if (value.endsWith("/*")) {
String newValue = "\"" + value.substring(0, value.length() - 2) + "\"";
return a.withArguments(Collections.singletonList(((J.Literal) it).withValue(newValue).withValueSource(newValue)));
return a.withArguments(singletonList(((J.Literal) it).withValue(newValue).withValueSource(newValue)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;

import java.util.Collections;
import java.util.List;

import static java.util.Collections.nCopies;

public class UpdateBeanManagerMethods extends Recipe {
@Override
public String getDisplayName() {
Expand Down Expand Up @@ -66,7 +67,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
args[arguments.size()] = arguments.get(0);

String template = "#{any(jakarta.enterprise.inject.spi.BeanManager)}.getEvent()" +
".select(" + String.join(", ", Collections.nCopies(arguments.size() - 1, "#{any(java.lang.annotation.Annotation)}")) + ')' +
".select(" + String.join(", ", nCopies(arguments.size() - 1, "#{any(java.lang.annotation.Annotation)}")) + ')' +
".fire(#{any(jakarta.enterprise.inject.spi.BeforeBeanDiscovery)})";
return JavaTemplate.builder(template)
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "jakarta.enterprise.cdi-api-3.0.0-M4"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import org.openrewrite.java.tree.JavaType;

import java.util.*;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

@EqualsAndHashCode(callSuper = false)
@Value
Expand Down Expand Up @@ -67,7 +68,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
.flatMap(Collection::stream)
.map(var -> var.getName().getFieldType())
.filter(Objects::nonNull)
.collect(Collectors.toList());
.collect(toList());
return super.visitClassDeclaration(classDecl, ctx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;

@EqualsAndHashCode(callSuper = false)
@Value
public class RemoveTemporalAnnotation extends Recipe {
Expand Down Expand Up @@ -74,13 +76,13 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
JAVA_SQL_TIMESTAMP,
JAVA_SQL_TIME,
JAVA_SQL_DATE
).collect(Collectors.toSet());
).collect(toSet());
// Combinations of TemporalType and java.sql classes that do not need removal
Map<String, String> doNotRemove = Stream.of(new String[][]{
{"DATE", JAVA_SQL_TIMESTAMP},
{"TIME", JAVA_SQL_TIMESTAMP},
{"TIMESTAMP", JAVA_SQL_DATE}
}).collect(Collectors.toMap(data -> data[0], data -> data[1]));
}).collect(toMap(data -> data[0], data -> data[1]));
// TODO: maybe future recipe to handle these by creating a converter class
// https://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/OpenJPA/Mappings#.40Temporal_on_java.sql.Date.2FTime.2FTimestamp_fields

Expand Down
Loading
Loading