Simplify JvmPrimitiveType, PrimitiveType
Delete utility methods from interfaces, move once-used methods to where they're used
This commit is contained in:
committed by
Alexander Udalov
parent
1578d891cb
commit
73b867d1e5
-64
@@ -16,13 +16,9 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum JvmPrimitiveType {
|
||||
BOOLEAN(PrimitiveType.BOOLEAN, "boolean", "java.lang.Boolean", Type.BOOLEAN_TYPE),
|
||||
CHAR(PrimitiveType.CHAR, "char", "java.lang.Character", Type.CHAR_TYPE),
|
||||
@@ -38,25 +34,12 @@ public enum JvmPrimitiveType {
|
||||
private final String name;
|
||||
private final JvmClassName wrapper;
|
||||
private final Type asmType;
|
||||
private final char jvmLetter;
|
||||
private final Type asmArrayType;
|
||||
private final JvmClassName iterator;
|
||||
|
||||
private JvmPrimitiveType(PrimitiveType primitiveType, String name, String wrapperClassName, Type asmType) {
|
||||
this.primitiveType = primitiveType;
|
||||
this.name = name;
|
||||
this.wrapper = JvmClassName.byFqNameWithoutInnerClasses(wrapperClassName);
|
||||
this.asmType = asmType;
|
||||
this.jvmLetter = asmType.getDescriptor().charAt(0);
|
||||
this.asmArrayType = makeArrayType(asmType);
|
||||
this.iterator = JvmClassName.byFqNameWithoutInnerClasses("jet." + primitiveType.getTypeName() + "Iterator");
|
||||
}
|
||||
|
||||
private static Type makeArrayType(Type type) {
|
||||
StringBuilder sb = new StringBuilder(2);
|
||||
sb.append('[');
|
||||
sb.append(type.getDescriptor());
|
||||
return Type.getType(sb.toString());
|
||||
}
|
||||
|
||||
public PrimitiveType getPrimitiveType() {
|
||||
@@ -74,51 +57,4 @@ public enum JvmPrimitiveType {
|
||||
public Type getAsmType() {
|
||||
return asmType;
|
||||
}
|
||||
|
||||
public Type getAsmArrayType() {
|
||||
return asmArrayType;
|
||||
}
|
||||
|
||||
public JvmClassName getIterator() {
|
||||
return iterator;
|
||||
}
|
||||
|
||||
public char getJvmLetter() {
|
||||
return jvmLetter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class MapByAsmTypeHolder {
|
||||
private static final Map<Integer, JvmPrimitiveType> map;
|
||||
|
||||
static {
|
||||
map = new HashMap<Integer, JvmPrimitiveType>();
|
||||
for (JvmPrimitiveType jvmPrimitiveType : values()) {
|
||||
map.put(jvmPrimitiveType.getAsmType().getSort(), jvmPrimitiveType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JvmPrimitiveType getByAsmType(Type type) {
|
||||
return MapByAsmTypeHolder.map.get(type.getSort());
|
||||
}
|
||||
|
||||
|
||||
private static class MapByWrapperAsmTypeHolder {
|
||||
private static final Map<Type, JvmPrimitiveType> map;
|
||||
|
||||
static {
|
||||
map = new HashMap<Type, JvmPrimitiveType>();
|
||||
for (JvmPrimitiveType jvmPrimitiveType : values()) {
|
||||
map.put(jvmPrimitiveType.getWrapper().getAsmType(), jvmPrimitiveType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JvmPrimitiveType getByWrapperAsmType(Type type) {
|
||||
return MapByWrapperAsmTypeHolder.map.get(type);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-7
@@ -66,14 +66,11 @@ public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
String name = jvmPrimitiveType.getName();
|
||||
register(jvmPrimitiveType.getWrapper().getFqName(), builtIns.getPrimitiveClassDescriptor(primitiveType));
|
||||
}
|
||||
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
primitiveTypesMap.put(jvmPrimitiveType.getName(), KotlinBuiltIns.getInstance().getPrimitiveJetType(primitiveType));
|
||||
primitiveTypesMap.put("[" + jvmPrimitiveType.getName(), KotlinBuiltIns.getInstance().getPrimitiveArrayJetType(primitiveType));
|
||||
primitiveTypesMap.put(jvmPrimitiveType.getWrapper().getFqName().asString(), KotlinBuiltIns.getInstance().getNullablePrimitiveJetType(
|
||||
primitiveTypesMap.put(name, builtIns.getPrimitiveJetType(primitiveType));
|
||||
primitiveTypesMap.put("[" + name, builtIns.getPrimitiveArrayJetType(primitiveType));
|
||||
primitiveTypesMap.put(jvmPrimitiveType.getWrapper().getFqName().asString(), builtIns.getNullablePrimitiveJetType(
|
||||
primitiveType));
|
||||
}
|
||||
primitiveTypesMap.put("void", KotlinBuiltIns.getInstance().getUnitType());
|
||||
|
||||
+9
-7
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -52,15 +53,16 @@ public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
|
||||
}
|
||||
|
||||
private void initPrimitives() {
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
FqName className = jvmPrimitiveType.getPrimitiveType().getClassName();
|
||||
|
||||
register(className, jvmPrimitiveType.getAsmType());
|
||||
registerNullable(className, jvmPrimitiveType.getWrapper().getAsmType());
|
||||
}
|
||||
FqName builtInsFqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME;
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
register(primitiveType.getArrayClassName(), jvmPrimitiveType.getAsmArrayType());
|
||||
Type asmType = jvmPrimitiveType.getAsmType();
|
||||
FqName fqName = builtInsFqName.child(primitiveType.getTypeName());
|
||||
|
||||
register(fqName, asmType);
|
||||
registerNullable(fqName, jvmPrimitiveType.getWrapper().getAsmType());
|
||||
|
||||
register(builtInsFqName.child(primitiveType.getArrayTypeName()), Type.getType("[" + asmType.getDescriptor()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user