Somewhat simplify mapping of JVM primitive types
This commit is contained in:
+17
-8
@@ -20,10 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public enum JvmPrimitiveType {
|
||||
BOOLEAN(PrimitiveType.BOOLEAN, "boolean", "Z", "java.lang.Boolean"),
|
||||
@@ -38,14 +35,17 @@ public enum JvmPrimitiveType {
|
||||
|
||||
private static final Set<FqName> WRAPPERS_CLASS_NAMES;
|
||||
private static final Map<String, JvmPrimitiveType> TYPE_BY_NAME;
|
||||
private static final Map<PrimitiveType, JvmPrimitiveType> TYPE_BY_PRIMITIVE_TYPE;
|
||||
|
||||
static {
|
||||
WRAPPERS_CLASS_NAMES = new HashSet<FqName>();
|
||||
TYPE_BY_NAME = new HashMap<String, JvmPrimitiveType>();
|
||||
TYPE_BY_PRIMITIVE_TYPE = new EnumMap<PrimitiveType, JvmPrimitiveType>(PrimitiveType.class);
|
||||
|
||||
for (JvmPrimitiveType primitiveType : values()) {
|
||||
WRAPPERS_CLASS_NAMES.add(primitiveType.getWrapperFqName());
|
||||
TYPE_BY_NAME.put(primitiveType.getName(), primitiveType);
|
||||
for (JvmPrimitiveType type : values()) {
|
||||
WRAPPERS_CLASS_NAMES.add(type.getWrapperFqName());
|
||||
TYPE_BY_NAME.put(type.getName(), type);
|
||||
TYPE_BY_PRIMITIVE_TYPE.put(type.getPrimitiveType(), type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,16 @@ public enum JvmPrimitiveType {
|
||||
|
||||
@NotNull
|
||||
public static JvmPrimitiveType get(@NotNull String name) {
|
||||
return TYPE_BY_NAME.get(name);
|
||||
JvmPrimitiveType result = TYPE_BY_NAME.get(name);
|
||||
if (result == null) {
|
||||
throw new AssertionError("Non-primitive type name passed: " + name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JvmPrimitiveType get(@NotNull PrimitiveType type) {
|
||||
return TYPE_BY_PRIMITIVE_TYPE.get(type);
|
||||
}
|
||||
|
||||
private final PrimitiveType primitiveType;
|
||||
|
||||
Reference in New Issue
Block a user