DATACMNS-1435 - Fixed Vavr Map component and value type detection.
This commit is contained in:
@@ -30,15 +30,7 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -58,14 +50,10 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
|
||||
static {
|
||||
|
||||
ClassLoader classLoader = TypeDiscoverer.class.getClassLoader();
|
||||
|
||||
Set<Class<?>> mapTypes = new HashSet<Class<?>>();
|
||||
mapTypes.add(Map.class);
|
||||
|
||||
try {
|
||||
mapTypes.add(ClassUtils.forName("javaslang.collection.Map", classLoader));
|
||||
} catch (ClassNotFoundException o_O) {}
|
||||
tryToAddClassTo("javaslang.collection.Map", mapTypes);
|
||||
tryToAddClassTo("io.vavr.collection.Map", mapTypes);
|
||||
|
||||
MAP_TYPES = Collections.unmodifiableSet(mapTypes);
|
||||
}
|
||||
@@ -583,6 +571,19 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to load the class with the given name and adds it to the given {@link Set} of classes if present.
|
||||
*
|
||||
* @param className must not be {@literal null} or empty.
|
||||
* @param classes must not be {@literal null}.
|
||||
*/
|
||||
private static final void tryToAddClassTo(String className, Set<Class<?>> classes) {
|
||||
|
||||
try {
|
||||
classes.add(ClassUtils.forName(className, TypeDiscoverer.class.getClassLoader()));
|
||||
} catch (ClassNotFoundException o_O) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* A synthetic {@link ParameterizedType}.
|
||||
*
|
||||
|
||||
@@ -386,7 +386,16 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-940
|
||||
public void detectsJavaslangMapComponentAndValueType() {
|
||||
|
||||
ClassTypeInformation<SampleMap> information = ClassTypeInformation.from(SampleMap.class);
|
||||
ClassTypeInformation<JavaslangSampleMap> information = ClassTypeInformation.from(JavaslangSampleMap.class);
|
||||
|
||||
assertThat(information.getComponentType().getType(), is(typeCompatibleWith(String.class)));
|
||||
assertThat(information.getMapValueType().getType(), is(typeCompatibleWith(Integer.class)));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1434
|
||||
public void detectsVavrMapComponentAndValueType() {
|
||||
|
||||
ClassTypeInformation<VavrSampleMap> information = ClassTypeInformation.from(VavrSampleMap.class);
|
||||
|
||||
assertThat(information.getComponentType().getType(), is(typeCompatibleWith(String.class)));
|
||||
assertThat(information.getMapValueType().getType(), is(typeCompatibleWith(Integer.class)));
|
||||
@@ -605,7 +614,9 @@ public class ClassTypeInformationUnitTests {
|
||||
|
||||
static interface SampleTraversable extends Traversable<Integer> {}
|
||||
|
||||
static interface SampleMap extends javaslang.collection.Map<String, Integer> {}
|
||||
static interface JavaslangSampleMap extends javaslang.collection.Map<String, Integer> {}
|
||||
|
||||
static interface VavrSampleMap extends io.vavr.collection.Map<String, Integer> {}
|
||||
|
||||
// DATACMNS-1138
|
||||
|
||||
|
||||
Reference in New Issue
Block a user