DATACMNS-1322 - Add support for Kotlin's copy(…) method.

We now support updating of immutable Kotlin data objects by creating new copies through Kotlin's copy method that is generated along with data classes and immutable properties.

data class DataClassKt(val id: String) {
}

data class ExtendedDataClassKt(val id: String, val name: String) {
}
This commit is contained in:
Mark Paluch
2018-05-22 16:08:49 +02:00
committed by Oliver Gierke
parent 80db17d6ba
commit 79119000bb
8 changed files with 559 additions and 97 deletions

View File

@@ -405,6 +405,49 @@ public class ReflectionUtils {
return !parameter.getParameterType().isPrimitive();
}
/**
* Get default value for a primitive type.
*
* @param type must not be {@literal null}.
* @return boxed primitive default value.
*/
public static Object getPrimitiveDefault(Class<?> type) {
if (type == Byte.TYPE || type == Byte.class) {
return (byte) 0;
}
if (type == Short.TYPE || type == Short.class) {
return (short) 0;
}
if (type == Integer.TYPE || type == Integer.class) {
return 0;
}
if (type == Long.TYPE || type == Long.class) {
return 0L;
}
if (type == Float.TYPE || type == Float.class) {
return 0F;
}
if (type == Double.TYPE || type == Double.class) {
return 0D;
}
if (type == Character.TYPE || type == Character.class) {
return '\u0000';
}
if (type == Boolean.TYPE) {
return Boolean.FALSE;
}
throw new IllegalArgumentException(String.format("Primitive type %s not supported!", type));
}
/**
* Reflection utility methods specific to Kotlin reflection.
*/