Introduce KotlinTypeFactory
This commit is contained in:
@@ -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)
|
||||
|
||||
+6
-6
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
+5
-4
@@ -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 {
|
||||
|
||||
+4
-5
@@ -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(
|
||||
|
||||
+1
-4
@@ -195,10 +195,7 @@ class LazyJavaClassDescriptor(
|
||||
parameter -> TypeProjectionImpl(Variance.INVARIANT, parameter.defaultType)
|
||||
}
|
||||
|
||||
return KotlinTypeImpl.create(
|
||||
Annotations.EMPTY, classDescriptor,
|
||||
/* nullable =*/ false, parametersAsTypeProjections
|
||||
)
|
||||
return KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, classDescriptor, parametersAsTypeProjections)
|
||||
}
|
||||
|
||||
private fun getPurelyImplementsFqNameFromAnnotation(): FqName? {
|
||||
|
||||
+2
-3
@@ -106,9 +106,8 @@ internal object RawSubstitution : TypeSubstitution() {
|
||||
val arguments = listOf(
|
||||
TypeProjectionImpl(componentTypeProjection.projectionKind, eraseType(componentTypeProjection.type))
|
||||
)
|
||||
return KotlinTypeImpl.create(
|
||||
type.annotations, type.constructor, type.isMarkedNullable, arguments,
|
||||
(type.constructor.declarationDescriptor as ClassDescriptor).getMemberScope(arguments)
|
||||
return KotlinTypeFactory.simpleType(type.annotations, type.constructor, arguments,
|
||||
type.isMarkedNullable, (type.constructor.declarationDescriptor as ClassDescriptor).getMemberScope(arguments)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -730,24 +730,14 @@ public abstract class KotlinBuiltIns {
|
||||
@NotNull
|
||||
public SimpleType getArrayType(@NotNull Variance projectionType, @NotNull KotlinType argument) {
|
||||
List<TypeProjectionImpl> types = Collections.singletonList(new TypeProjectionImpl(projectionType, argument));
|
||||
return KotlinTypeImpl.create(
|
||||
Annotations.Companion.getEMPTY(),
|
||||
getArray(),
|
||||
false,
|
||||
types
|
||||
);
|
||||
return KotlinTypeFactory.simpleNotNullType(Annotations.Companion.getEMPTY(), getArray(), types);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SimpleType getEnumType(@NotNull SimpleType argument) {
|
||||
Variance projectionType = Variance.INVARIANT;
|
||||
List<TypeProjectionImpl> types = Collections.singletonList(new TypeProjectionImpl(projectionType, argument));
|
||||
return KotlinTypeImpl.create(
|
||||
Annotations.Companion.getEMPTY(),
|
||||
getEnum(),
|
||||
false,
|
||||
types
|
||||
);
|
||||
return KotlinTypeFactory.simpleNotNullType(Annotations.Companion.getEMPTY(), getEnum(), types);
|
||||
}
|
||||
|
||||
@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.
|
||||
@@ -65,7 +65,7 @@ class ReflectionTypes(module: ModuleDescriptor) {
|
||||
}
|
||||
|
||||
val arguments = listOf(TypeProjectionImpl(Variance.INVARIANT, type))
|
||||
return KotlinTypeImpl.create(annotations, descriptor, false, arguments)
|
||||
return KotlinTypeFactory.simpleNotNullType(annotations, descriptor, arguments)
|
||||
}
|
||||
|
||||
fun getKFunctionType(
|
||||
@@ -82,7 +82,7 @@ class ReflectionTypes(module: ModuleDescriptor) {
|
||||
return classDescriptor.defaultType
|
||||
}
|
||||
|
||||
return KotlinTypeImpl.create(annotations, classDescriptor, false, arguments)
|
||||
return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
|
||||
}
|
||||
|
||||
fun getKPropertyType(annotations: Annotations, receiverType: KotlinType?, returnType: KotlinType, mutable: Boolean): KotlinType {
|
||||
@@ -107,7 +107,7 @@ class ReflectionTypes(module: ModuleDescriptor) {
|
||||
arguments.add(TypeProjectionImpl(receiverType))
|
||||
}
|
||||
arguments.add(TypeProjectionImpl(returnType))
|
||||
return KotlinTypeImpl.create(annotations, classDescriptor, false, arguments)
|
||||
return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -130,10 +130,8 @@ class ReflectionTypes(module: ModuleDescriptor) {
|
||||
|
||||
fun createKPropertyStarType(module: ModuleDescriptor): KotlinType? {
|
||||
val kPropertyClass = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.kProperty) ?: return null
|
||||
return KotlinTypeImpl.create(
|
||||
Annotations.EMPTY, kPropertyClass, false,
|
||||
listOf(StarProjectionImpl(kPropertyClass.typeConstructor.parameters.single()))
|
||||
)
|
||||
return KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, kPropertyClass,
|
||||
listOf(StarProjectionImpl(kPropertyClass.typeConstructor.parameters.single())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ class FunctionClassDescriptor(
|
||||
TypeProjectionImpl(it.defaultType)
|
||||
}
|
||||
|
||||
result.add(KotlinTypeImpl.create(Annotations.EMPTY, descriptor, false, arguments))
|
||||
result.add(KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, descriptor, arguments))
|
||||
}
|
||||
|
||||
// Add unnumbered base class, e.g. Function for Function{n}, KFunction for KFunction{n}
|
||||
|
||||
+2
-2
@@ -68,9 +68,9 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
||||
this.defaultType = storageManager.createLazyValue(new Function0<SimpleType>() {
|
||||
@Override
|
||||
public SimpleType invoke() {
|
||||
return KotlinTypeImpl.create(
|
||||
return KotlinTypeFactory.simpleType(
|
||||
Annotations.Companion.getEMPTY(),
|
||||
getTypeConstructor(), false, Collections.<TypeProjection>emptyList(),
|
||||
getTypeConstructor(), Collections.<TypeProjection>emptyList(), false,
|
||||
new LazyScopeAdapter(storageManager.createLazyValue(
|
||||
new Function0<MemberScope>() {
|
||||
@Override
|
||||
|
||||
+1
-6
@@ -132,12 +132,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
@Override
|
||||
public SimpleType getDefaultType() {
|
||||
List<TypeProjection> typeProjections = TypeUtils.getDefaultTypeProjections(getTypeConstructor().getParameters());
|
||||
return KotlinTypeImpl.create(
|
||||
getAnnotations(),
|
||||
this,
|
||||
false,
|
||||
typeProjections
|
||||
);
|
||||
return KotlinTypeFactory.simpleNotNullType(getAnnotations(), this, typeProjections);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ class CapturedType(
|
||||
private val delegateType = run {
|
||||
val scope = ErrorUtils.createErrorScope(
|
||||
"No member resolution should be done on captured type, it used only during constraint system resolution", true)
|
||||
KotlinTypeImpl.create(Annotations.EMPTY, CapturedTypeConstructor(typeProjection), false, listOf(), scope)
|
||||
KotlinTypeFactory.simpleType(Annotations.EMPTY, CapturedTypeConstructor(typeProjection), listOf(), false, scope)
|
||||
}
|
||||
|
||||
override fun getDelegate(): KotlinType = delegateType
|
||||
|
||||
@@ -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.
|
||||
@@ -99,9 +99,8 @@ class IntegerValueTypeConstant(
|
||||
}
|
||||
}
|
||||
|
||||
val unknownIntegerType = KotlinTypeImpl.create(
|
||||
Annotations.EMPTY, typeConstructor, false, emptyList<TypeProjection>(),
|
||||
ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true)
|
||||
val unknownIntegerType = KotlinTypeFactory.simpleType(Annotations.EMPTY, typeConstructor, emptyList<TypeProjection>(),
|
||||
false, ErrorUtils.createErrorScope("Scope for number value type (" + typeConstructor.toString() + ")", true)
|
||||
)
|
||||
|
||||
fun getType(expectedType: KotlinType): KotlinType = TypeUtils.getPrimitiveNumberType(typeConstructor, expectedType)
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
|
||||
object KotlinTypeFactory {
|
||||
|
||||
@JvmStatic
|
||||
fun simpleType(
|
||||
annotations: Annotations,
|
||||
constructor: TypeConstructor,
|
||||
arguments: List<TypeProjection>,
|
||||
nullable: Boolean,
|
||||
memberScope: MemberScope
|
||||
): SimpleType = KotlinTypeImpl.create(annotations, constructor, nullable, arguments, memberScope)
|
||||
|
||||
@JvmStatic
|
||||
fun simpleNotNullType(
|
||||
annotations: Annotations,
|
||||
descriptor: ClassDescriptor,
|
||||
arguments: List<TypeProjection>
|
||||
): SimpleType = KotlinTypeImpl.create(annotations, descriptor.typeConstructor, false, arguments, descriptor.getMemberScope(arguments))
|
||||
|
||||
@JvmStatic
|
||||
fun simpleType(
|
||||
baseType: SimpleType,
|
||||
annotations: Annotations = baseType.annotations,
|
||||
constructor: TypeConstructor = baseType.constructor,
|
||||
arguments: List<TypeProjection> = baseType.arguments,
|
||||
nullable: Boolean = baseType.isMarkedNullable,
|
||||
memberScope: MemberScope = baseType.memberScope
|
||||
): SimpleType = simpleType(annotations, constructor, arguments, nullable, memberScope)
|
||||
}
|
||||
@@ -30,6 +30,8 @@ private constructor(
|
||||
) : AbstractKotlinType(), SimpleType {
|
||||
|
||||
companion object {
|
||||
|
||||
@Deprecated("", ReplaceWith("KotlinTypeFactory.simpleType(annotations, constructor, arguments, nullable, memberScope)", "org.jetbrains.kotlin.types.KotlinTypeFactory"))
|
||||
@JvmStatic fun create(annotations: Annotations,
|
||||
constructor: TypeConstructor,
|
||||
nullable: Boolean,
|
||||
@@ -51,6 +53,7 @@ private constructor(
|
||||
return KotlinTypeImpl(annotations, constructor, nullable, arguments, memberScope)
|
||||
}
|
||||
|
||||
@Deprecated("", ReplaceWith("KotlinTypeFactory.simpleType(annotations, descriptor, arguments, nullable)", "org.jetbrains.kotlin.types.KotlinTypeFactory"))
|
||||
@JvmStatic fun create(annotations: Annotations,
|
||||
descriptor: ClassDescriptor,
|
||||
nullable: Boolean,
|
||||
|
||||
@@ -250,11 +250,11 @@ public class TypeUtils {
|
||||
}
|
||||
TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor();
|
||||
List<TypeProjection> arguments = getDefaultTypeProjections(typeConstructor.getParameters());
|
||||
return KotlinTypeImpl.create(
|
||||
return KotlinTypeFactory.simpleType(
|
||||
Annotations.Companion.getEMPTY(),
|
||||
typeConstructor,
|
||||
false,
|
||||
arguments,
|
||||
false,
|
||||
unsubstitutedMemberScope
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -58,12 +58,11 @@ fun KotlinType.approximateFlexibleTypes(preferNotNull: Boolean = false): KotlinT
|
||||
|
||||
return approximation
|
||||
}
|
||||
return KotlinTypeImpl.create(
|
||||
annotations,
|
||||
constructor,
|
||||
isMarkedNullable,
|
||||
arguments.map { it.substitute { type -> type.approximateFlexibleTypes(preferNotNull = true) } },
|
||||
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
|
||||
return KotlinTypeFactory.simpleType(annotations,
|
||||
constructor,
|
||||
arguments.map { it.substitute { type -> type.approximateFlexibleTypes(preferNotNull = true) } },
|
||||
isMarkedNullable,
|
||||
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.idea.util.toFuzzyType
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
|
||||
@@ -100,7 +100,7 @@ object KeywordValues {
|
||||
|
||||
if (qualifierType != null) {
|
||||
val kClassDescriptor = resolutionFacade.getFrontendService(ReflectionTypes::class.java).kClass
|
||||
val classLiteralType = KotlinTypeImpl.create(Annotations.EMPTY, kClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val classLiteralType = KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, kClassDescriptor, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val kClassTypes = listOf(classLiteralType.toFuzzyType(emptyList()))
|
||||
val kClassMatcher = { info: ExpectedInfo -> kClassTypes.matchExpectedInfo(info) }
|
||||
consumer.consume("class", kClassMatcher, SmartCompletionItemPriority.CLASS_LITERAL) {
|
||||
@@ -112,7 +112,7 @@ object KeywordValues {
|
||||
.singleOrNull() as? ClassDescriptor
|
||||
|
||||
if (javaLangClassDescriptor != null) {
|
||||
val javaLangClassType = KotlinTypeImpl.create(Annotations.EMPTY, javaLangClassDescriptor, false, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val javaLangClassType = KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, javaLangClassDescriptor, listOf(TypeProjectionImpl(qualifierType)))
|
||||
val javaClassTypes = listOf(javaLangClassType.toFuzzyType(emptyList()))
|
||||
val javaClassMatcher = { info: ExpectedInfo -> javaClassTypes.matchExpectedInfo(info) }
|
||||
consumer.consume("class", javaClassMatcher, SmartCompletionItemPriority.CLASS_LITERAL) {
|
||||
|
||||
+2
-2
@@ -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.
|
||||
@@ -312,7 +312,7 @@ class TypeInstantiationItems(
|
||||
private val tail: Tail?) : InheritanceItemsSearcher {
|
||||
|
||||
private val baseHasTypeArgs = classDescriptor.declaredTypeParameters.isNotEmpty()
|
||||
private val expectedType = KotlinTypeImpl.create(Annotations.EMPTY, classDescriptor, false, typeArgs)
|
||||
private val expectedType = KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, classDescriptor, typeArgs)
|
||||
private val expectedFuzzyType = expectedType.toFuzzyType(freeParameters)
|
||||
|
||||
override fun search(nameFilter: (String) -> Boolean, consumer: (LookupElement) -> Unit) {
|
||||
|
||||
+1
-1
@@ -251,7 +251,7 @@ internal fun KotlinType.substitute(substitution: KotlinTypeSubstitution, varianc
|
||||
val (projection, typeParameter) = pair
|
||||
TypeProjectionImpl(Variance.INVARIANT, projection.type.substitute(substitution, typeParameter.variance))
|
||||
}
|
||||
return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, newArguments, memberScope)
|
||||
return KotlinTypeFactory.simpleType(annotations, constructor, newArguments, isMarkedNullable, memberScope)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -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.
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessT
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtForExpression
|
||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
@@ -51,11 +51,11 @@ object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactor
|
||||
|
||||
val returnJetTypeParameterType = TypeProjectionImpl(returnJetTypeParameterTypes[0])
|
||||
val returnJetTypeArguments = Collections.singletonList(returnJetTypeParameterType)
|
||||
val newReturnJetType = KotlinTypeImpl.create(returnJetType.annotations,
|
||||
returnJetType.constructor,
|
||||
returnJetType.isMarkedNullable,
|
||||
returnJetTypeArguments,
|
||||
returnJetType.memberScope)
|
||||
val newReturnJetType = KotlinTypeFactory.simpleType(returnJetType.annotations,
|
||||
returnJetType.constructor,
|
||||
returnJetTypeArguments,
|
||||
returnJetType.isMarkedNullable,
|
||||
returnJetType.memberScope)
|
||||
val returnType = TypeInfo(newReturnJetType, Variance.OUT_VARIANCE)
|
||||
return FunctionInfo(OperatorNameConventions.ITERATOR.asString(), iterableType, returnType, isOperator = true)
|
||||
}
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.StarProjectionImpl
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
|
||||
@@ -65,8 +65,8 @@ internal fun genPropertyForWidget(
|
||||
if (defaultType.constructor.parameters.isEmpty())
|
||||
defaultType
|
||||
else
|
||||
KotlinTypeImpl.create(Annotations.EMPTY, classDescriptor, false,
|
||||
defaultType.constructor.parameters.map { StarProjectionImpl(it) })
|
||||
KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, classDescriptor,
|
||||
defaultType.constructor.parameters.map { StarProjectionImpl(it) })
|
||||
} ?: context.viewType
|
||||
|
||||
return genProperty(resolvedWidget.widget.id, receiverType, type, packageFragmentDescriptor, sourceEl, resolvedWidget.errorType)
|
||||
|
||||
Reference in New Issue
Block a user