Introduce KotlinTypeFactory

This commit is contained in:
Stanislav Erokhin
2016-05-20 19:24:32 +03:00
parent 8c6dd95e3f
commit 3a451744c5
29 changed files with 136 additions and 110 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -245,7 +245,7 @@ class CollectionStubMethodGenerator(
}
private fun newType(classDescriptor: ClassDescriptor, typeArguments: List<TypeProjection>): KotlinType {
return KotlinTypeImpl.create(Annotations.EMPTY, classDescriptor, false, typeArguments)
return KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, classDescriptor, typeArguments)
}
private fun FunctionDescriptor.signature(): JvmMethodGenericSignature = typeMapper.mapSignatureWithGeneric(this, OwnerKind.IMPLEMENTATION)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
import org.jetbrains.kotlin.types.KotlinTypeImpl
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.TypeProjectionImpl
class JavaClassOnCompanionChecker : CallChecker {
@@ -41,10 +41,10 @@ class JavaClassOnCompanionChecker : CallChecker {
if (companionObject.isCompanionObject) {
val containingClass = companionObject.containingDeclaration as ClassDescriptor
val javaLangClass = actualType.constructor.declarationDescriptor as? ClassDescriptor ?: return
val expectedType = KotlinTypeImpl.create(
Annotations.EMPTY, javaLangClass, actualType.isMarkedNullable,
listOf(TypeProjectionImpl(containingClass.defaultType))
)
val arguments = listOf(TypeProjectionImpl(containingClass.defaultType))
val expectedType = KotlinTypeFactory.simpleType(Annotations.EMPTY, javaLangClass.typeConstructor, arguments,
actualType.isMarkedNullable, javaLangClass.getMemberScope(arguments))
context.trace.report(ErrorsJvm.JAVA_CLASS_ON_COMPANION.on(resolvedCall.call.callElement, actualType, expectedType))
}
}
@@ -48,11 +48,11 @@ class TypeAliasExpander(
}
return if (withAbbreviatedType) {
val abbreviatedType = KotlinTypeImpl.create(annotations,
typeAliasExpansion.descriptor.typeConstructor,
originalProjection.type.isMarkedNullable,
typeAliasExpansion.arguments,
MemberScope.Empty)
val abbreviatedType = KotlinTypeFactory.simpleType(annotations,
typeAliasExpansion.descriptor.typeConstructor,
typeAliasExpansion.arguments,
originalProjection.type.isMarkedNullable,
MemberScope.Empty)
expandedType.withAbbreviatedType(abbreviatedType)
}
@@ -317,12 +317,11 @@ class TypeResolver(
return if (scopeForTypeParameter is ErrorUtils.ErrorScope)
ErrorUtils.createErrorType("?")
else
KotlinTypeImpl.create(
annotations,
typeParameter.typeConstructor,
false,
listOf(),
scopeForTypeParameter)
KotlinTypeFactory.simpleType(annotations,
typeParameter.typeConstructor,
listOf(),
false,
scopeForTypeParameter)
}
private fun getScopeForTypeParameter(c: TypeResolutionContext, typeParameterDescriptor: TypeParameterDescriptor): MemberScope {
@@ -394,7 +393,7 @@ class TypeResolver(
" but ${collectedArgumentAsTypeProjections.size} instead of ${parameters.size} found in ${element.text}"
}
val resultingType = KotlinTypeImpl.create(annotations, classDescriptor, false, arguments)
val resultingType = KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
// We create flexible types by convention here
// This is not intended to be used in normal users' environments, only for tests and debugger etc
@@ -466,7 +465,7 @@ class TypeResolver(
}
return if (c.abbreviated) {
val abbreviatedType = KotlinTypeImpl.create(annotations, descriptor.typeConstructor, false, arguments, MemberScope.Empty)
val abbreviatedType = KotlinTypeFactory.simpleType(annotations, descriptor.typeConstructor, arguments, false, MemberScope.Empty)
type(abbreviatedType)
}
else {
@@ -78,7 +78,7 @@ fun replaceReturnTypeForCallable(type: KotlinType, given: KotlinType): KotlinTyp
fun replaceReturnTypeByUnknown(type: KotlinType) = replaceReturnTypeForCallable(type, DONT_CARE)
private fun replaceTypeArguments(type: KotlinType, newArguments: List<TypeProjection>) =
KotlinTypeImpl.create(type.annotations, type.constructor, type.isMarkedNullable, newArguments, type.memberScope)
KotlinTypeFactory.simpleType(type.annotations, type.constructor, newArguments, type.isMarkedNullable, type.memberScope)
private fun getParameterArgumentsOfCallableType(type: KotlinType) =
type.arguments.dropLast(1)
@@ -111,8 +111,8 @@ fun getErasedReceiverType(receiverParameterDescriptor: ReceiverParameterDescript
for (typeProjection in receiverType.arguments) {
fakeTypeArguments.add(TypeProjectionImpl(typeProjection.projectionKind, DONT_CARE))
}
return KotlinTypeImpl.create(receiverType.annotations, receiverType.constructor, receiverType.isMarkedNullable, fakeTypeArguments,
ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true))
return KotlinTypeFactory.simpleType(receiverType.annotations, receiverType.constructor, fakeTypeArguments,
receiverType.isMarkedNullable, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true))
}
fun isOrOverridesSynthesized(descriptor: CallableMemberDescriptor): Boolean {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,13 +17,10 @@
package org.jetbrains.kotlin.resolve.calls.inference
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.Call
import org.jetbrains.kotlin.resolve.descriptorUtil.hasOnlyInputTypesAnnotation
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeImpl
class TypeVariable(
val call: CallHandle,
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeImpl
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.SimpleType
import org.jetbrains.kotlin.types.TypeProjection
@@ -74,7 +74,7 @@ fun createFunctionType(
AnnotationsImpl(annotations + extensionFunctionAnnotation)
}
return KotlinTypeImpl.create(typeAnnotations, classDescriptor, false, arguments)
return KotlinTypeFactory.simpleNotNullType(typeAnnotations, classDescriptor, arguments)
}
fun getValueParametersCountFromFunctionType(type: KotlinType): Int {
@@ -241,7 +241,7 @@ public class CommonSupertypes {
else {
newScope = ErrorUtils.createErrorScope("A scope for common supertype which is not a normal classifier", true);
}
return KotlinTypeImpl.create(Annotations.Companion.getEMPTY(), constructor, nullable, newProjections, newScope);
return KotlinTypeFactory.simpleType(Annotations.Companion.getEMPTY(), constructor, newProjections, nullable, newScope);
}
@NotNull
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -129,11 +129,11 @@ public class TypeIntersector {
TypeConstructor constructor = new IntersectionTypeConstructor(Annotations.Companion.getEMPTY(), resultingTypes);
return KotlinTypeImpl.create(
return KotlinTypeFactory.simpleType(
Annotations.Companion.getEMPTY(),
constructor,
allNullable,
Collections.<TypeProjection>emptyList(),
allNullable,
TypeIntersectionScope.create("member scope for intersection type " + constructor, resultingTypes)
);
}
@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeImpl
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
@@ -217,9 +217,10 @@ class DoubleColonExpressionResolver(
c.trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(expression, descriptor.typeConstructor.parameters.size, descriptor))
}
KotlinTypeImpl.create(
Annotations.EMPTY, descriptor, possiblyBareType.isNullable || doubleColonExpression.hasQuestionMarks,
descriptor.typeConstructor.parameters.map(TypeUtils::makeStarProjection)
val arguments = descriptor.typeConstructor.parameters.map(TypeUtils::makeStarProjection)
KotlinTypeFactory.simpleType(
Annotations.EMPTY, descriptor.typeConstructor, arguments,
possiblyBareType.isNullable || doubleColonExpression.hasQuestionMarks, descriptor.getMemberScope(arguments)
)
}
else {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeImpl
import org.jetbrains.kotlin.types.KotlinTypeFactory
import java.util.regex.Pattern
class ConstraintSystemTestData(
@@ -64,9 +64,8 @@ class ConstraintSystemTestData(
val matcher = INTEGER_VALUE_TYPE_PATTERN.matcher(name)
if (matcher.find()) {
val number = matcher.group(1)!!
return KotlinTypeImpl.create(
Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong(), functionFoo.builtIns), false, listOf(),
MemberScope.Empty
return KotlinTypeFactory.simpleType(Annotations.EMPTY, IntegerValueTypeConstructor(number.toLong(), functionFoo.builtIns),
listOf(), false, MemberScope.Empty
)
}
return typeResolver.resolveType(