classDescriptorMap used instead of classTypeMap

in JavaTypeTransformer
so 'getKotlinAnalog' now is used instead of 'unwrapPrimitive'

classTypeMap removed,
=> removed now unnecessary numberType, throwableType, etc. from JetStandardLibrary
This commit is contained in:
Svetlana Isakova
2012-07-20 16:35:00 +04:00
parent a4bb47a73f
commit 084566aac4
3 changed files with 15 additions and 151 deletions
@@ -58,9 +58,7 @@ public class JavaTypeTransformer {
private Map<String, JetType> primitiveTypesMap;
private Map<FqName, JetType> classTypesMap;
private HashMap<FqName, ClassDescriptor> classDescriptorMap;
private Map<FqName, ClassDescriptor> classDescriptorMap;
@NotNull
@@ -159,13 +157,11 @@ public class JavaTypeTransformer {
// 'L extends List<T>' in Java is a List<T> in Kotlin, not a List<T?>
boolean nullable = !EnumSet.of(SUPERTYPE_ARGUMENT, SUPERTYPE).contains(howThisTypeIsUsed);
JetType jetAnalog = getKotlinAnalog(new FqName(psiClass.getQualifiedName()));
if (jetAnalog != null) {
return TypeUtils.makeNullableAsSpecified(jetAnalog, nullable);
}
ClassDescriptor classData = getKotlinAnalog(new FqName(psiClass.getQualifiedName()));
final ClassDescriptor classData =
resolver.resolveClass(new FqName(psiClass.getQualifiedName()), DescriptorSearchRule.INCLUDE_KOTLIN);
if (classData == null) {
classData = resolver.resolveClass(new FqName(psiClass.getQualifiedName()), DescriptorSearchRule.INCLUDE_KOTLIN);
}
if (classData == null) {
return ErrorUtils.createErrorType("Unresolved java class: " + classType.getPresentableText());
}
@@ -240,52 +236,34 @@ public class JavaTypeTransformer {
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
primitiveTypesMap.put(jvmPrimitiveType.getName(), JetStandardLibrary.getInstance().getPrimitiveJetType(primitiveType));
primitiveTypesMap.put("[" + jvmPrimitiveType.getName(), JetStandardLibrary.getInstance().getPrimitiveArrayJetType(primitiveType));
primitiveTypesMap.put(jvmPrimitiveType.getWrapper().getFqName().getFqName(), JetStandardLibrary.getInstance().getNullablePrimitiveJetType(primitiveType));
primitiveTypesMap.put(jvmPrimitiveType.getWrapper().getFqName().getFqName(), JetStandardLibrary.getInstance().getNullablePrimitiveJetType(
primitiveType));
}
primitiveTypesMap.put("void", JetStandardClasses.getUnitType());
}
return primitiveTypesMap;
}
public Map<FqName, JetType> getClassTypesMap() {
if (classTypesMap == null) {
classTypesMap = new HashMap<FqName, JetType>();
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
classTypesMap.put(jvmPrimitiveType.getWrapper().getFqName(), JetStandardLibrary.getInstance().getNullablePrimitiveJetType(primitiveType));
}
classTypesMap.put(new FqName("java.lang.Object"), JetStandardClasses.getNullableAnyType());
classTypesMap.put(new FqName("java.lang.String"), JetStandardLibrary.getInstance().getNullableStringType());
classTypesMap.put(new FqName("java.lang.CharSequence"), JetStandardLibrary.getInstance().getNullableCharSequenceType());
classTypesMap.put(new FqName("java.lang.Throwable"), JetStandardLibrary.getInstance().getNullableThrowableType());
classTypesMap.put(new FqName("java.lang.Number"), JetStandardLibrary.getInstance().getNullableNumberType());
}
return classTypesMap;
}
@Nullable
public JetType getKotlinAnalog(@NotNull FqName fqName) {
return getClassTypesMap().get(fqName);
}
private Map<FqName, ClassDescriptor> getPrimitiveWrappersClassDescriptorMap() {
public Map<FqName, ClassDescriptor> getClassDescriptorMap() {
if (classDescriptorMap == null) {
classDescriptorMap = new HashMap<FqName, ClassDescriptor>();
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
classDescriptorMap.put(jvmPrimitiveType.getWrapper().getFqName(), JetStandardLibrary.getInstance().getPrimitiveClassDescriptor(primitiveType));
}
classDescriptorMap.put(new FqName("java.lang.Object"), JetStandardClasses.getAny());
classDescriptorMap.put(new FqName("java.lang.String"), JetStandardLibrary.getInstance().getString());
classDescriptorMap.put(new FqName("java.lang.CharSequence"), JetStandardLibrary.getInstance().getCharSequence());
classDescriptorMap.put(new FqName("java.lang.Throwable"), JetStandardLibrary.getInstance().getThrowable());
classDescriptorMap.put(new FqName("java.lang.Number"), JetStandardLibrary.getInstance().getNumber());
}
return classDescriptorMap;
}
@Nullable
public ClassDescriptor unwrapPrimitive(@NotNull FqName fqName) {
return getPrimitiveWrappersClassDescriptorMap().get(fqName);
public ClassDescriptor getKotlinAnalog(@NotNull FqName fqName) {
return getClassDescriptorMap().get(fqName);
}
/**
@@ -94,12 +94,8 @@ public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAd
);
this.classDescriptor = null;
if (this.classDescriptor == null && !forceReal) {
this.classDescriptor = this.javaSemanticServices.getTypeTransformer().unwrapPrimitive(ourName);
}
if (this.classDescriptor == null && ourName.equals(new FqName("java.lang.Object")) && !forceReal) {
this.classDescriptor = JetStandardClasses.getAny();
if (!forceReal) {
classDescriptor = javaSemanticServices.getTypeTransformer().getKotlinAnalog(ourName);
}
if (classDescriptor == null) {
@@ -94,28 +94,16 @@ public class JetStandardLibrary {
private ClassDescriptor arrayClass;
private ClassDescriptor iterableClass;
private ClassDescriptor comparableClass;
private ClassDescriptor volatileClass;
private ClassDescriptor throwableClass;
private JetType numberType;
private JetType nullableNumberType;
private JetType stringType;
private JetType volatileType;
private JetType nullableStringType;
private JetType charSequenceType;
private JetType nullableCharSequenceType;
private JetType nullableTuple0Type;
private JetType throwableType;
private JetType nullableThrowableType;
private JetType tuple0Type;
private EnumMap<PrimitiveType, ClassDescriptor> primitiveTypeToClass;
private EnumMap<PrimitiveType, ClassDescriptor> primitiveTypeToArrayClass;
private EnumMap<PrimitiveType, JetType> primitiveTypeToJetType;
private EnumMap<PrimitiveType, JetType> primitiveTypeToNullableJetType;
private EnumMap<PrimitiveType, JetType> primitiveTypeToArrayJetType;
private EnumMap<PrimitiveType, JetType> primitiveTypeToNullableArrayJetType;
private Map<JetType, JetType> primitiveJetTypeToJetArrayType;
private Map<JetType, JetType> jetArrayTypeToPrimitiveJetType;
@@ -174,31 +162,18 @@ public class JetStandardLibrary {
this.stringClass = (ClassDescriptor) libraryScope.getClassifier(Name.identifier("String"));
this.charSequenceClass = (ClassDescriptor) libraryScope.getClassifier(Name.identifier("CharSequence"));
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier(Name.identifier("Array"));
this.volatileClass = (ClassDescriptor) libraryScope.getClassifier(Name.identifier("volatile"));
this.throwableClass = (ClassDescriptor) libraryScope.getClassifier(Name.identifier("Throwable"));
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier(Name.identifier("Iterable"));
this.comparableClass = (ClassDescriptor) libraryScope.getClassifier(Name.identifier("Comparable"));
this.numberType = new JetTypeImpl(getNumber());
this.nullableNumberType = TypeUtils.makeNullable(numberType);
this.stringType = new JetTypeImpl(getString());
this.charSequenceType = new JetTypeImpl(getCharSequence());
this.nullableCharSequenceType = TypeUtils.makeNullable(charSequenceType);
this.nullableStringType = TypeUtils.makeNullable(stringType);
this.volatileType = new JetTypeImpl(getVolatile());
this.throwableType = new JetTypeImpl(getThrowable());
this.nullableThrowableType = TypeUtils.makeNullable(throwableType);
this.tuple0Type = new JetTypeImpl(JetStandardClasses.getTuple(0));
this.nullableTuple0Type = TypeUtils.makeNullable(tuple0Type);
primitiveTypeToClass = new EnumMap<PrimitiveType, ClassDescriptor>(PrimitiveType.class);
primitiveTypeToJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
primitiveTypeToNullableJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
primitiveTypeToArrayClass = new EnumMap<PrimitiveType, ClassDescriptor>(PrimitiveType.class);
primitiveTypeToArrayJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
primitiveTypeToNullableArrayJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
primitiveJetTypeToJetArrayType = new HashMap<JetType, JetType>();
jetArrayTypeToPrimitiveJetType = new HashMap<JetType, JetType>();
@@ -217,9 +192,7 @@ public class JetStandardLibrary {
primitiveTypeToClass.put(primitiveType, clazz);
primitiveTypeToJetType.put(primitiveType, type);
primitiveTypeToNullableJetType.put(primitiveType, TypeUtils.makeNullable(type));
primitiveTypeToArrayClass.put(primitiveType, arrayClazz);
primitiveTypeToArrayJetType.put(primitiveType, arrayType);
primitiveTypeToNullableArrayJetType.put(primitiveType, TypeUtils.makeNullable(arrayType));
primitiveJetTypeToJetArrayType.put(type, arrayType);
jetArrayTypeToPrimitiveJetType.put(arrayType, type);
}
@@ -232,7 +205,6 @@ public class JetStandardLibrary {
classDescriptors.add(stringClass);
classDescriptors.add(charSequenceClass);
classDescriptors.add(arrayClass);
classDescriptors.add(volatileClass);
classDescriptors.add(throwableClass);
classDescriptors.add(iterableClass);
classDescriptors.add(comparableClass);
@@ -369,12 +341,6 @@ public class JetStandardLibrary {
return stringType;
}
@NotNull
public JetType getCharSequenceType() {
initStdClasses();
return charSequenceType;
}
@NotNull
public JetType getByteType() {
return getPrimitiveJetType(PrimitiveType.BYTE);
@@ -418,57 +384,12 @@ public class JetStandardLibrary {
return primitiveType;
}
@NotNull
public JetType getIterableType(@NotNull JetType argument) {
return getIterableType(Variance.INVARIANT, argument);
}
@NotNull
public JetType getIterableType(@NotNull Variance projectionType, @NotNull JetType argument) {
List<TypeProjection> types = Collections.singletonList(new TypeProjection(projectionType, argument));
return new JetTypeImpl(
Collections.<AnnotationDescriptor>emptyList(),
getIterable().getTypeConstructor(),
false,
types,
getIterable().getMemberScope(types)
);
}
@NotNull
public JetType getNullableStringType() {
initStdClasses();
return nullableStringType;
}
@NotNull
public JetType getNullableCharSequenceType() {
initStdClasses();
return nullableCharSequenceType;
}
@NotNull
public JetType getThrowableType() {
initStdClasses();
return throwableType;
}
public JetType getNullableThrowableType() {
initStdClasses();
return nullableThrowableType;
}
@NotNull
public JetType getNullablePrimitiveJetType(PrimitiveType primitiveType) {
initStdClasses();
return primitiveTypeToNullableJetType.get(primitiveType);
}
public JetType getNullableTuple0Type() {
initStdClasses();
return nullableTuple0Type;
}
@NotNull
public JetType getPrimitiveArrayJetType(PrimitiveType primitiveType) {
initStdClasses();
@@ -483,27 +404,6 @@ public class JetStandardLibrary {
return primitiveJetTypeToJetArrayType.get(jetType);
}
@NotNull
public ClassDescriptor getPrimitiveArrayClassDescriptor(PrimitiveType primitiveType) {
initStdClasses();
return primitiveTypeToArrayClass.get(primitiveType);
}
@NotNull
public JetType getNullablePrimitiveArrayJetType(PrimitiveType primitiveType) {
initStdClasses();
return primitiveTypeToNullableArrayJetType.get(primitiveType);
}
public ClassDescriptor getVolatile() {
return volatileClass;
}
public JetType getVolatileType() {
return volatileType;
}
public static boolean isVolatile(PropertyDescriptor descriptor) {
List<AnnotationDescriptor> annotations = descriptor.getOriginal().getAnnotations();
if (annotations != null) {
@@ -519,14 +419,4 @@ public class JetStandardLibrary {
public JetType getTuple0Type() {
return tuple0Type;
}
public JetType getNumberType() {
initStdClasses();
return numberType;
}
public JetType getNullableNumberType() {
initStdClasses();
return nullableNumberType;
}
}