Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applies OpenRewrite upgrade-to-Java-11 recipes
Browse files Browse the repository at this point in the history
jqno committed Dec 24, 2024
1 parent c446886 commit 5324436
Showing 34 changed files with 73 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import nl.jqno.equalsverifier.internal.reflection.ClassProbe;
import org.junit.jupiter.api.Test;
@@ -15,11 +14,11 @@ class RecordInstanceCreatorTest {
@Test
void instanceCreator() throws NoSuchFieldException {
ClassProbe<SomeRecord> probe = ClassProbe.of(SomeRecord.class);
InstanceCreator<SomeRecord> sut = new InstanceCreator<>(probe, new ObjenesisStd());
var sut = new InstanceCreator<RecordInstanceCreatorTest.SomeRecord>(probe, new ObjenesisStd());

Field x = SomeRecord.class.getDeclaredField("x");
Field z = SomeRecord.class.getDeclaredField("z");
Map<Field, Object> values = new HashMap<>();
var values = new HashMap<Field, Object>();
values.put(x, 42);
values.put(z, "42");

6 changes: 3 additions & 3 deletions equalsverifier-core/pom.xml
Original file line number Diff line number Diff line change
@@ -123,9 +123,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${version.javax-annotation-api}</version>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${version.jakarta-annotation-api}</version>
<scope>test</scope>
</dependency>
<dependency>
Original file line number Diff line number Diff line change
@@ -410,7 +410,7 @@ private void performVerification() {
Validations.validateClassCanBeVerified(type);

Configuration<T> config = buildConfig();
Context<T> context = new Context<>(config, factoryCache, fieldCache, objenesis);
var context = new Context<T>(config, factoryCache, fieldCache, objenesis);
Validations
.validateProcessedAnnotations(
type,
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ private List<T> ensureEnoughExamples(List<T> examples) {
return examples;
}

List<T> result = new ArrayList<>();
var result = new ArrayList<T>();
result.add(subjectCreator.plain());
result.add(subjectCreator.withAllFieldsChanged());
return result;
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public FieldsChecker(Context<T> context) {

@Override
public void check() {
FieldInspector<T> inspector = new FieldInspector<>(context.getType());
var inspector = new FieldInspector<T>(context.getType());

if (!context.getClassProbe().isEqualsInheritedFromObject()) {
inspector.check(arrayFieldCheck);
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public void check() {
return;
}

FieldInspector<T> inspector = new FieldInspector<>(context.getType());
var inspector = new FieldInspector<T>(context.getType());
inspector.check(new NullPointerExceptionFieldCheck<>(context));
}
}
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator;
@@ -46,7 +45,7 @@ private void verifyRecordPrecondition(T original) {
return;
}

List<String> failedFields = new ArrayList<>();
var failedFields = new ArrayList<String>();
for (FieldProbe p : FieldIterable.of(type)) {
Method accessorMethod = getAccessorMethodFor(type, p.getField());
try {
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public void check() {
}

private List<Method> getEqualsMethods() {
List<Method> result = new ArrayList<>();
var result = new ArrayList<Method>();

for (Method method : type.getDeclaredMethods()) {
if ("equals".equals(method.getName()) && !Modifier.isStatic(method.getModifiers())) {
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ public T instantiate(Map<Field, Object> values) {
* @return A copy of the given original.
*/
public T copy(Object original) {
Map<Field, Object> values = new HashMap<>();
var values = new HashMap<Field, Object>();
for (FieldProbe p : fields(original.getClass())) {
Object value = p.getValue(original);
values.put(p.getField(), value);
@@ -57,9 +57,9 @@ public T copy(Object original) {
}

private T createRecordInstance(Map<Field, Object> values) {
List<Object> params = new ArrayList<>();
var params = new ArrayList<Object>();
traverseFields(values, (p, v) -> params.add(v));
RecordProbe<T> recordProbe = new RecordProbe<>(type);
var recordProbe = new RecordProbe<T>(type);
return recordProbe.callRecordConstructor(params);
}

Original file line number Diff line number Diff line change
@@ -201,7 +201,7 @@ private T createInstance(Map<Field, Object> givens) {
}

private Map<Field, Object> determineValues(Map<Field, Object> givens) {
Map<Field, Object> values = new HashMap<>(givens);
var values = new HashMap<Field, Object>(givens);
for (FieldProbe p : fields()) {
Field f = p.getField();
boolean fieldIsAbsent = !values.containsKey(f);
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ protected LinkedHashSet<TypeTag> cloneWith(LinkedHashSet<TypeTag> typeStack, Typ
}

protected TypeTag copyGenericTypesInto(Class<?> type, TypeTag source) {
List<TypeTag> genericTypes = new ArrayList<>();
var genericTypes = new ArrayList<TypeTag>();
for (TypeTag tag : source.getGenericTypes()) {
genericTypes.add(tag);
}
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.function.Supplier;

import nl.jqno.equalsverifier.Func;
@@ -24,8 +23,8 @@ public SimpleGenericFactory(Func<T> factory, Supplier<T> emptyFactory) {
public Tuple<T> createValues(TypeTag tag, VintageValueProvider valueProvider, LinkedHashSet<TypeTag> typeStack) {
LinkedHashSet<TypeTag> clone = cloneWith(typeStack, tag);

List<Object> redValues = new ArrayList<>();
List<Object> blueValues = new ArrayList<>();
var redValues = new ArrayList<Object>();
var blueValues = new ArrayList<Object>();

boolean useEmpty = false;
int n = tag.getType().getTypeParameters().length;
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ private ObjectAccessor<T> makeAccessor(Function<FieldProbe, Object> determineVal
}

private T callRecordConstructor(List<?> params) {
RecordProbe<T> p = new RecordProbe<>(type());
var p = new RecordProbe<T>(type());
return p.callRecordConstructor(params);
}

Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ public Iterator<FieldProbe> iterator() {
}

private List<FieldProbe> createFieldList() {
List<FieldProbe> result = new ArrayList<>();
var result = new ArrayList<FieldProbe>();

result.addAll(addFieldsFor(type));

@@ -90,8 +90,8 @@ private List<FieldProbe> createFieldList() {
}

private List<FieldProbe> addFieldsFor(Class<?> c) {
List<FieldProbe> fields = new ArrayList<>();
List<FieldProbe> statics = new ArrayList<>();
var fields = new ArrayList<FieldProbe>();
var statics = new ArrayList<FieldProbe>();

for (Field field : c.getDeclaredFields()) {
if (!field.isSynthetic()
@@ -109,7 +109,7 @@ private List<FieldProbe> addFieldsFor(Class<?> c) {
}
}

List<FieldProbe> result = new ArrayList<>();
var result = new ArrayList<FieldProbe>();
result.addAll(fields);
result.addAll(statics);
return result;
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ private static List<Class<?>> getClassesInDir(
classes = getClassesInDir(packageName + "." + f.getName(), f, mustExtend, scanRecursively);
}
else {
classes = Collections.singletonList(fileToClass(packageName, f));
classes = List.of(fileToClass(packageName, f));
}
return classes.stream();
})
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ private static TypeTag resolve(
Class<?> typeAsClass,
TypeTag enclosingType,
boolean shortCircuitRecursiveTypeBound) {
List<TypeTag> nestedTags = new ArrayList<>();
var nestedTags = new ArrayList<TypeTag>();
if (type instanceof Class) {
return processClass((Class<?>) type, nestedTags);
}
@@ -151,7 +151,7 @@ private static TypeTag processTypeVariable(

private static Map<String, TypeTag> buildLookup(TypeTag enclosingType) {
TypeVariable<?>[] typeParameters = enclosingType.getType().getTypeParameters();
Map<String, TypeTag> lookup = new HashMap<>();
var lookup = new HashMap<String, TypeTag>();
if (enclosingType.getGenericTypes().size() == 0) {
return lookup;
}
Original file line number Diff line number Diff line change
@@ -187,7 +187,7 @@ private void addEnumProperties(Object val, String name, AnnotationProperties pro
private void addArrayProperties(Object val, String name, AnnotationProperties props) {
if (val.getClass().isArray() && !val.getClass().getComponentType().isPrimitive()) {
Object[] array = (Object[]) val;
Set<String> values = new HashSet<>();
var values = new HashSet<String>();
for (Object obj : array) {
if (obj instanceof TypeDescription) {
values.add(((TypeDescription) obj).getName());
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public final class FieldNameExtractor {
private FieldNameExtractor() {}

public static <T> Set<String> extractFieldNames(Class<T> type) {
Set<String> actualFieldNames = new HashSet<>();
var actualFieldNames = new HashSet<String>();
for (FieldProbe p : FieldIterable.of(type)) {
String name = p.getName();
actualFieldNames.add(name);
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ public static <T> List<T> buildListOfAtLeastOne(T first, T... more) {
throw new IllegalArgumentException("First example is null.");
}

List<T> result = new ArrayList<>();
var result = new ArrayList<T>();
result.add(first);
addArrayElementsToList(result, more);

@@ -48,7 +48,7 @@ public static <T> List<T> buildListOfAtLeastTwo(T first, T second, T... more) {
throw new IllegalArgumentException("Second example is null.");
}

List<T> result = new ArrayList<>();
var result = new ArrayList<T>();
result.add(first);
result.add(second);
addArrayElementsToList(result, more);
@@ -76,7 +76,7 @@ private static <T> void addArrayElementsToList(List<T> list, T... more) {
* @return A list with the elements of the Iterable.
*/
public static <T> List<T> fromIterable(Iterable<T> iterable) {
List<T> result = new ArrayList<>();
var result = new ArrayList<T>();
for (T t : iterable) {
result.add(t);
}
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ private PrimitiveMappers() {}
public static final Collection<Object> ZEROS = DEFAULT_WRAPPED_VALUE_MAPPER.values();

private static Map<Class<?>, Class<?>> createPrimitiveObjectMapper() {
Map<Class<?>, Class<?>> result = new HashMap<>();
var result = new HashMap<Class<?>, Class<?>>();
result.put(boolean.class, Boolean.class);
result.put(byte.class, Byte.class);
result.put(char.class, Character.class);
@@ -28,7 +28,7 @@ private static Map<Class<?>, Class<?>> createPrimitiveObjectMapper() {
}

private static Map<Class<?>, Object> createDefaultValueMapper(boolean includeWrapped) {
Map<Class<?>, Object> result = new HashMap<>();
var result = new HashMap<Class<?>, Object>();
result.put(boolean.class, false);
result.put(byte.class, Byte.valueOf((byte) 0));
result.put(char.class, Character.valueOf((char) 0));
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ public static <T> Arguments of(Class<?> containerType) {
Class<? super T> superType = find(containingTypes, "Point");
Class<T> subType = find(containingTypes, "ColorPoint");
Class<? extends T> endpointType = find(containingTypes, "EndPoint");
Classes<T> result = new Classes<>(containerType, superType, subType, endpointType);
var result = new Classes<T>(containerType, superType, subType, endpointType);
return Arguments.of(result);
}

Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ void createSomeNodes() {
red = new Node(null);
blue = new Node(new Node(null));
redTree = new Tree(Collections.<Tree>emptyList());
blueTree = new Tree(Collections.singletonList(new Tree(Collections.<Tree>emptyList())));
blueTree = new Tree(List.of(new Tree(Collections.<Tree>emptyList())));
}

@Test
Original file line number Diff line number Diff line change
@@ -2,7 +2,10 @@

import java.time.LocalDate;
import java.time.Month;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
@@ -143,7 +146,7 @@ void succeed_whenPrefabForArrayIsOverridden() {
void succeed_whenClassContainsSomethingThatAllowsSubclassesAndASubclassIsGiven() {
EqualsVerifier
.forClass(ListContainer.class)
.withPrefabValuesForField("list", Collections.singletonList("x"), Collections.singletonList("y"))
.withPrefabValuesForField("list", List.of("x"), List.of("y"))
.verify();
}

@@ -153,7 +156,7 @@ void succeed_whenClassContainsAGenericInterfaceThatRefersToItself() {
DifficultGeneric two = new DifficultGeneric(null);
EqualsVerifier
.forClass(DifficultGeneric.class)
.withPrefabValuesForField("list", Collections.singletonList(one), Collections.singletonList(two))
.withPrefabValuesForField("list", List.of(one), List.of(two))
.verify();
}

Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ class RecursionExceptionTest {

@Test
void descriptionContainsAllTypes() {
LinkedHashSet<TypeTag> stack = new LinkedHashSet<>();
var stack = new LinkedHashSet<TypeTag>();
stack.add(new TypeTag(String.class));
stack.add(new TypeTag(Point.class));
stack.add(new TypeTag(Object.class));
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import nl.jqno.equalsverifier.internal.reflection.ClassProbe;
import org.junit.jupiter.api.Test;
@@ -17,11 +16,11 @@ class InstanceCreatorTest {
void instantiate() throws NoSuchFieldException {
ClassProbe<SomeClass> probe = ClassProbe.of(SomeClass.class);
Objenesis objenesis = new ObjenesisStd();
InstanceCreator<SomeClass> sut = new InstanceCreator<>(probe, objenesis);
var sut = new InstanceCreator<InstanceCreatorTest.SomeClass>(probe, objenesis);

Field x = SomeClass.class.getDeclaredField("x");
Field z = SomeClass.class.getDeclaredField("z");
Map<Field, Object> values = new HashMap<>();
var values = new HashMap<Field, Object>();
values.put(x, 42);
values.put(z, "42");

@@ -36,7 +35,7 @@ void instantiate() throws NoSuchFieldException {
void copy() throws NoSuchFieldException {
ClassProbe<SomeSubClass> probe = ClassProbe.of(SomeSubClass.class);
Objenesis objenesis = new ObjenesisStd();
InstanceCreator<SomeSubClass> sut = new InstanceCreator<>(probe, objenesis);
var sut = new InstanceCreator<InstanceCreatorTest.SomeSubClass>(probe, objenesis);

SomeClass original = new SomeClass(42, 1337, "yeah");
SomeSubClass copy = sut.copy(original);
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ void createMapOfOneElementEnumKey() {
}

private <K, V> Map<K, V> mapOf(K key, V value) {
Map<K, V> result = new HashMap<>();
var result = new HashMap<K, V>();
result.put(key, value);
return result;
}
Loading

0 comments on commit 5324436

Please sign in to comment.