diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java index 7a8ba196c2f..c4c66400a85 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java @@ -58,9 +58,7 @@ public class JavaTypeTransformer { private Map primitiveTypesMap; - private Map classTypesMap; - private HashMap classDescriptorMap; - + private Map classDescriptorMap; @NotNull @@ -159,13 +157,11 @@ public class JavaTypeTransformer { // 'L extends List' in Java is a List in Kotlin, not a List 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 getClassTypesMap() { - if (classTypesMap == null) { - classTypesMap = new HashMap(); - 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 getPrimitiveWrappersClassDescriptorMap() { + public Map getClassDescriptorMap() { if (classDescriptorMap == null) { classDescriptorMap = new HashMap(); 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); } /** diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java index a40f32383e6..245a751d018 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java @@ -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) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java index 83246c7d0ef..d273aae3f95 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java @@ -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 primitiveTypeToClass; - private EnumMap primitiveTypeToArrayClass; private EnumMap primitiveTypeToJetType; private EnumMap primitiveTypeToNullableJetType; private EnumMap primitiveTypeToArrayJetType; - private EnumMap primitiveTypeToNullableArrayJetType; private Map primitiveJetTypeToJetArrayType; private Map 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.class); primitiveTypeToJetType = new EnumMap(PrimitiveType.class); primitiveTypeToNullableJetType = new EnumMap(PrimitiveType.class); - primitiveTypeToArrayClass = new EnumMap(PrimitiveType.class); primitiveTypeToArrayJetType = new EnumMap(PrimitiveType.class); - primitiveTypeToNullableArrayJetType = new EnumMap(PrimitiveType.class); primitiveJetTypeToJetArrayType = new HashMap(); jetArrayTypeToPrimitiveJetType = new HashMap(); @@ -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 types = Collections.singletonList(new TypeProjection(projectionType, argument)); - return new JetTypeImpl( - Collections.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 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; - } }