diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index 76cc501a9b1..b942b394a0f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -934,7 +934,12 @@ public class KotlinBuiltIns { return isAny(getFqName(descriptor)); } + public static boolean isAny(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES.any); + } + public static boolean isBoolean(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._boolean); } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt index 299ed81ccb9..1941987366b 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt @@ -41,6 +41,7 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.* +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull @@ -331,7 +332,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, //TODO: IMO it's not good that Any is to be added manually if (superClasses.all { it.kind == ClassKind.INTERFACE }) { - superClasses += KotlinBuiltIns.getInstance().any + superClasses += classDescriptor.builtIns.any } if (!isNoQualifierContext()) { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ExpectedInfos.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ExpectedInfos.kt index c2305b706af..ec214d98c92 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ExpectedInfos.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ExpectedInfos.kt @@ -421,7 +421,7 @@ class ExpectedInfos( private fun calculateForIf(expressionWithType: JetExpression): Collection? { val ifExpression = (expressionWithType.getParent() as? JetContainerNode)?.getParent() as? JetIfExpression ?: return null return when (expressionWithType) { - ifExpression.getCondition() -> listOf(ExpectedInfo(KotlinBuiltIns.getInstance().getBooleanType(), null, Tail.RPARENTH)) + ifExpression.getCondition() -> listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, Tail.RPARENTH)) ifExpression.getThen() -> calculate(ifExpression).map { ExpectedInfo(it.filter, it.expectedName, Tail.ELSE) } @@ -492,14 +492,14 @@ class ExpectedInfos( return listOf(ExpectedInfo(subjectType, null, null)) } else { - return listOf(ExpectedInfo(KotlinBuiltIns.getInstance().getBooleanType(), null, null)) + return listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, null)) } } private fun calculateForExclOperand(expressionWithType: JetExpression): Collection? { val prefixExpression = expressionWithType.getParent() as? JetPrefixExpression ?: return null if (prefixExpression.getOperationToken() != JetTokens.EXCL) return null - return listOf(ExpectedInfo(KotlinBuiltIns.getInstance().getBooleanType(), null, null)) + return listOf(ExpectedInfo(resolutionFacade.moduleDescriptor.builtIns.booleanType, null, null)) } private fun calculateForInitializer(expressionWithType: JetExpression): Collection? { @@ -574,7 +574,7 @@ class ExpectedInfos( val leftOperandType = binaryExpression.left?.let { bindingContext.getType(it) } ?: return null val scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expressionWithType)!! - val detector = TypesWithContainsDetector(scope, leftOperandType, resolutionFacade.ideService()) + val detector = TypesWithContainsDetector(scope, leftOperandType, resolutionFacade) val byTypeFilter = object : ByTypeFilter { override fun matchingSubstitutor(descriptorType: FuzzyType): TypeSubstitutor? { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt index 4152ab7d193..7c254eb6ad3 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypesWithContainsDetector.kt @@ -16,10 +16,11 @@ package org.jetbrains.kotlin.idea.completion.smart -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.idea.completion.HeuristicSignatures +import org.jetbrains.kotlin.idea.resolve.ResolutionFacade +import org.jetbrains.kotlin.idea.resolve.ideService import org.jetbrains.kotlin.idea.util.FuzzyType import org.jetbrains.kotlin.idea.util.nullability import org.jetbrains.kotlin.incremental.components.NoLookupLocation @@ -28,16 +29,17 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.TypeNullability -import java.util.HashMap +import java.util.* class TypesWithContainsDetector( private val scope: JetScope, private val argumentType: JetType, - private val heuristicSignatures: HeuristicSignatures + private val resolutionFacade: ResolutionFacade ) { private val cache = HashMap() private val containsName = Name.identifier("contains") - private val booleanType = KotlinBuiltIns.getInstance().getBooleanType() + private val booleanType = resolutionFacade.moduleDescriptor.builtIns.booleanType + private val heuristicSignatures = resolutionFacade.ideService() private val typesWithExtensionContains: Collection = scope.getFunctions(containsName, NoLookupLocation.FROM_IDE) .filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggester.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggester.kt index 0c184a5fe8e..9795048a3a6 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggester.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinNameSuggester.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.JetTypeChecker +import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmart import java.util.* import java.util.regex.Pattern @@ -134,7 +135,7 @@ public object KotlinNameSuggester { private fun MutableCollection.addNamesByType(type: JetType, validator: (String) -> Boolean) { var type = TypeUtils.makeNotNullable(type) // wipe out '?' - val builtIns = KotlinBuiltIns.getInstance() + val builtIns = type.builtIns val typeChecker = JetTypeChecker.DEFAULT if (ErrorUtils.containsErrorType(type)) return @@ -166,7 +167,7 @@ public object KotlinNameSuggester { addName("s", validator) } else if (KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type)) { - val elementType = KotlinBuiltIns.getInstance().getArrayElementType(type) + val elementType = builtIns.getArrayElementType(type) if (typeChecker.equalTypes(builtIns.getBooleanType(), elementType)) { addName("booleans", validator) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt index 9a66e53ab6a..5b7f8de9515 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertAssertToIfWithThrowIntention.kt @@ -88,7 +88,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention 1 && valParameters[1].getType() != KotlinBuiltIns.getInstance().getAnyType() + return valParameters.size() > 1 && !KotlinBuiltIns.isAny(valParameters[1].type) } private fun simplifyConditionIfPossible(ifExpression: JetIfExpression) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt index a0323b94d5c..6898e29b48b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertFunctionToPropertyIntention.kt @@ -50,6 +50,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.types.typeUtil.supertypes import java.util.* @@ -112,12 +113,13 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention null type.getConstructor().isDenotable() -> type else -> type.supertypes().firstOrNull { it.getConstructor().isDenotable() } - } ?: KotlinBuiltIns.getInstance().getNullableAnyType() + } ?: functionDescriptor.builtIns.nullableAnyType callable.typeFqNameToAdd = IdeDescriptorRenderers.SOURCE_CODE.renderType(typeToInsert) } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToExpressionBodyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToExpressionBodyIntention.kt index 949f1e107ce..554b354d815 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToExpressionBodyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToExpressionBodyIntention.kt @@ -66,7 +66,7 @@ public class ConvertToExpressionBodyIntention : JetSelfTargetingOffsetIndependen if (!declaration.hasDeclaredReturnType() && declaration is JetNamedFunction) { val valueType = value.analyze().getType(value) if (valueType == null || !KotlinBuiltIns.isUnit(valueType)) { - declaration.setType(KotlinBuiltIns.getInstance().getUnitType()) + declaration.setType(KotlinBuiltIns.FQ_NAMES.unit.asString(), shortenReferences = true) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt index 584046d2c1d..26c50ef7234 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt @@ -105,7 +105,7 @@ public class SpecifyTypeExplicitlyIntention : JetSelfTargetingIntention functionClassTypeParameters = new LinkedList(); for (TypeProjection typeProjection: functionLiteralType.getArguments()) { functionClassTypeParameters.add(typeProjection.getType()); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionReturnTypeFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionReturnTypeFix.java index 664f8792ff7..fe02281df48 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionReturnTypeFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionReturnTypeFix.java @@ -26,6 +26,7 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; +import org.jetbrains.kotlin.descriptors.CallableDescriptor; import org.jetbrains.kotlin.descriptors.FunctionDescriptor; import org.jetbrains.kotlin.diagnostics.Diagnostic; import org.jetbrains.kotlin.idea.JetBundle; @@ -42,6 +43,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils; import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsPackage; +import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.types.ErrorUtils; import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.checker.JetTypeChecker; @@ -51,6 +53,7 @@ import java.util.List; import static org.jetbrains.kotlin.diagnostics.Errors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH; import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns; public class ChangeFunctionReturnTypeFix extends JetIntentionAction { private final JetType type; @@ -162,10 +165,11 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction BindingContext context = ResolutionUtils.analyze(expression); ResolvedCall resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, expression); if (resolvedCall == null) return null; + FunctionDescriptor hasNextDescriptor = resolvedCall.getCandidateDescriptor(); JetFunction hasNextFunction = (JetFunction) DescriptorToSourceUtils - .descriptorToDeclaration(resolvedCall.getCandidateDescriptor()); + .descriptorToDeclaration(hasNextDescriptor); if (hasNextFunction != null) { - return new ChangeFunctionReturnTypeFix(hasNextFunction, KotlinBuiltIns.getInstance().getBooleanType()); + return new ChangeFunctionReturnTypeFix(hasNextFunction, getBuiltIns(hasNextDescriptor).getBooleanType()); } else return null; } @@ -183,9 +187,10 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction BindingContext context = ResolutionUtils.analyze(expression); ResolvedCall resolvedCall = CallUtilPackage.getResolvedCall(expression, context); if (resolvedCall == null) return null; - PsiElement compareTo = DescriptorToSourceUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor()); + CallableDescriptor compareToDescriptor = resolvedCall.getCandidateDescriptor(); + PsiElement compareTo = DescriptorToSourceUtils.descriptorToDeclaration(compareToDescriptor); if (!(compareTo instanceof JetFunction)) return null; - return new ChangeFunctionReturnTypeFix((JetFunction) compareTo, KotlinBuiltIns.getInstance().getIntType()); + return new ChangeFunctionReturnTypeFix((JetFunction) compareTo, getBuiltIns(compareToDescriptor).getIntType()); } }; } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.java index 8f84f6f143d..1994528b863 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionSignatureFix.java @@ -43,6 +43,7 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetValVar; import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.resolve.BindingContext; +import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode; import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.checker.JetTypeChecker; @@ -123,7 +124,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction { if (!declaration.hasInitializer() && containingElement is JetBlockExpression) { val defaultValueType = typeCandidates[callableInfo.returnTypeInfo]!!.firstOrNull()?.theType - ?: KotlinBuiltIns.getInstance().getAnyType() - val defaultValue = CodeInsightUtils.defaultInitializer(defaultValueType) ?: "null" + val defaultValue = defaultValueType?.let {CodeInsightUtils.defaultInitializer(it) } ?: "null" val initializer = declaration.setInitializer(JetPsiFactory(declaration).createExpression(defaultValue))!! val range = initializer.getTextRange() selectionModel.setSelection(range.getStartOffset(), range.getEndOffset()) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableInfo.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableInfo.kt index c61780f73b8..4298ac2124d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableInfo.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableInfo.kt @@ -50,22 +50,22 @@ abstract class TypeInfo(val variance: Variance) { context = builder.currentFileContext, module = builder.currentFileModule, pseudocode = builder.pseudocode - ).flatMap { it.getPossibleSupertypes(variance) } + ).flatMap { it.getPossibleSupertypes(variance, builder) } } class ByTypeReference(val typeReference: JetTypeReference, variance: Variance): TypeInfo(variance) { override fun getPossibleTypes(builder: CallableBuilder): List = - builder.currentFileContext[BindingContext.TYPE, typeReference].getPossibleSupertypes(variance) + builder.currentFileContext[BindingContext.TYPE, typeReference].getPossibleSupertypes(variance, builder) } class ByType(val theType: JetType, variance: Variance): TypeInfo(variance) { override fun getPossibleTypes(builder: CallableBuilder): List = - theType.getPossibleSupertypes(variance) + theType.getPossibleSupertypes(variance, builder) } class ByReceiverType(variance: Variance): TypeInfo(variance) { override fun getPossibleTypes(builder: CallableBuilder): List = - (builder.placement as CallablePlacement.WithReceiver).receiverTypeCandidate.theType.getPossibleSupertypes(variance) + (builder.placement as CallablePlacement.WithReceiver).receiverTypeCandidate.theType.getPossibleSupertypes(variance, builder) } abstract class DelegatingTypeInfo(val delegate: TypeInfo): TypeInfo(delegate.variance) { @@ -87,8 +87,10 @@ abstract class TypeInfo(val variance: Variance) { open val possibleNamesFromExpression: Array get() = ArrayUtil.EMPTY_STRING_ARRAY abstract fun getPossibleTypes(builder: CallableBuilder): List - protected fun JetType?.getPossibleSupertypes(variance: Variance): List { - if (this == null || ErrorUtils.containsErrorType(this)) return Collections.singletonList(KotlinBuiltIns.getInstance().getAnyType()) + protected fun JetType?.getPossibleSupertypes(variance: Variance, callableBuilder: CallableBuilder): List { + if (this == null || ErrorUtils.containsErrorType(this)) { + return Collections.singletonList(callableBuilder.currentFileModule.builtIns.anyType) + } val single = Collections.singletonList(this) return when (variance) { Variance.IN_VARIANCE -> single + supertypes() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt index 579927e8f80..190642a77d9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable import com.intellij.openapi.project.Project import com.intellij.psi.PsiClass import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.diagnostics.Diagnostic @@ -38,12 +37,13 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getCall import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.scopes.receivers.Qualifier import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf -import java.util.Collections +import java.util.* sealed class CreateCallableFromCallActionFactory( extensionsEnabled: Boolean = true @@ -180,7 +180,7 @@ sealed class CreateCallableFromCallActionFactory( if ((klass !is JetClass && klass !is PsiClass) || !klass.canRefactor()) return null val expectedType = context[BindingContext.EXPECTED_EXPRESSION_TYPE, expression.getQualifiedExpressionForSelectorOrThis()] - ?: KotlinBuiltIns.getInstance().nullableAnyType + ?: classDescriptor!!.builtIns.nullableAnyType if (!classDescriptor!!.defaultType.isSubtypeOf(expectedType)) return null val parameters = expression.getParameterInfos() diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegationCallActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegationCallActionFactory.kt index 7b2e3c6dcb0..d302e778328 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegationCallActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegationCallActionFactory.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.psi.JetClass import org.jetbrains.kotlin.psi.JetConstructorDelegationCall import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.Variance object CreateConstructorFromDelegationCallActionFactory : CreateCallableMemberFromUsageFactory() { @@ -57,7 +58,7 @@ object CreateConstructorFromDelegationCallActionFactory : CreateCallableMemberFr } if (!(targetClass.canRefactor() && (targetClass is JetClass || targetClass is PsiClass))) return null - val anyType = KotlinBuiltIns.getInstance().nullableAnyType + val anyType = classDescriptor.builtIns.nullableAnyType val parameters = element.valueArguments.map { ParameterInfo( it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE), diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegatorToSuperCallActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegatorToSuperCallActionFactory.kt index db42472afcc..4466fdf1d3b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegatorToSuperCallActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegatorToSuperCallActionFactory.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.psi.JetClass import org.jetbrains.kotlin.psi.JetDelegatorToSuperCall import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.Variance object CreateConstructorFromDelegatorToSuperCallActionFactory : CreateCallableMemberFromUsageFactory() { @@ -50,7 +51,7 @@ object CreateConstructorFromDelegatorToSuperCallActionFactory : CreateCallableMe val targetClass = DescriptorToSourceUtilsIde.getAnyDeclaration(project, superClassDescriptor) ?: return null if (!(targetClass.canRefactor() && (targetClass is JetClass || targetClass is PsiClass))) return null - val anyType = KotlinBuiltIns.getInstance().nullableAnyType + val anyType = superClassDescriptor.builtIns.nullableAnyType val parameters = element.valueArguments.map { ParameterInfo( it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE), diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateIteratorFunctionActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateIteratorFunctionActionFactory.kt index 38c15f8bef8..96f76351a76 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateIteratorFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateIteratorFunctionActionFactory.kt @@ -43,10 +43,11 @@ object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactor val iterableExpr = element.loopRange ?: return null val variableExpr: JetExpression = ((element.loopParameter ?: element.multiParameter) ?: return null) as JetExpression val iterableType = TypeInfo(iterableExpr, Variance.IN_VARIANCE) - val returnJetType = KotlinBuiltIns.getInstance().iterator.defaultType - val analysisResult = file.analyzeFullyAndGetResult() - val returnJetTypeParameterTypes = variableExpr.guessTypes(analysisResult.bindingContext, analysisResult.moduleDescriptor) + val (bindingContext, moduleDescriptor) = file.analyzeFullyAndGetResult() + + val returnJetType = moduleDescriptor.builtIns.iterator.defaultType + val returnJetTypeParameterTypes = variableExpr.guessTypes(bindingContext, moduleDescriptor) if (returnJetTypeParameterTypes.size() != 1) return null val returnJetTypeParameterType = TypeProjectionImpl(returnJetTypeParameterTypes[0]) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreatePropertyDelegateAccessorsActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreatePropertyDelegateAccessorsActionFactory.kt index 3c698a0c9f2..342989ce155 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreatePropertyDelegateAccessorsActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreatePropertyDelegateAccessorsActionFactory.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.psi.JetExpression import org.jetbrains.kotlin.psi.JetProperty import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.Variance object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUsageFactory() { @@ -43,8 +44,6 @@ object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUs fun isApplicableForAccessor(accessor: PropertyAccessorDescriptor?): Boolean = accessor != null && context[BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, accessor] == null - val builtIns = KotlinBuiltIns.getInstance() - val property = element.getNonStrictParentOfType() ?: return emptyList() val propertyDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, property] as? PropertyDescriptor ?: return emptyList() @@ -53,6 +52,7 @@ object CreatePropertyDelegateAccessorsActionFactory : CreateCallableMemberFromUs val propertyType = propertyDescriptor.type val accessorReceiverType = TypeInfo(element, Variance.IN_VARIANCE) + val builtIns = propertyDescriptor.builtIns val thisRefParam = ParameterInfo(TypeInfo(propertyReceiver?.type ?: builtIns.nullableNothingType, Variance.IN_VARIANCE)) val metadataParam = ParameterInfo(TypeInfo(builtIns.propertyMetadata.defaultType, Variance.IN_VARIANCE)) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromCallWithConstructorCalleeActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromCallWithConstructorCalleeActionFactory.kt index b54d8735b80..ac67b2b1771 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromCallWithConstructorCalleeActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromCallWithConstructorCalleeActionFactory.kt @@ -20,6 +20,7 @@ import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.ParameterInfo import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo import org.jetbrains.kotlin.psi.* @@ -58,14 +59,14 @@ public object CreateClassFromCallWithConstructorCalleeActionFactory : CreateClas val typeRef = callee.typeReference ?: return null val userType = typeRef.typeElement as? JetUserType ?: return null - val context = userType.analyze() + val (context, module) = userType.analyzeAndGetResult() val qualifier = userType.qualifier?.referenceExpression val qualifierDescriptor = qualifier?.let { context[BindingContext.REFERENCE_TARGET, it] } val targetParent = getTargetParentByQualifier(file, qualifier != null, qualifierDescriptor) ?: return null - val anyType = KotlinBuiltIns.getInstance().nullableAnyType + val anyType = module.builtIns.nullableAnyType val valueArguments = element.valueArguments val defaultParamName = if (valueArguments.size() == 1) "value" else null val parameterInfos = valueArguments.map { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromConstructorCallActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromConstructorCallActionFactory.kt index 1a61079c1a5..a3eab12da5a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromConstructorCallActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromConstructorCallActionFactory.kt @@ -82,7 +82,7 @@ public object CreateClassFromConstructorCallActionFactory: CreateClassFromUsageF val valueArguments = callExpr.valueArguments val defaultParamName = if (inAnnotationEntry && valueArguments.size() == 1) "value" else null - val anyType = KotlinBuiltIns.getInstance().nullableAnyType + val anyType = moduleDescriptor.builtIns.nullableAnyType val parameterInfos = valueArguments.map { ParameterInfo( it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE), diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt index affd376104d..2bf737e6d07 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo import org.jetbrains.kotlin.psi.JetConstructorCalleeExpression @@ -63,13 +64,13 @@ public object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFa val file = element.containingFile as? JetFile ?: return null - val context = element.analyze() + val (context, module) = element.analyzeAndGetResult() val qualifier = element.qualifier?.referenceExpression val qualifierDescriptor = qualifier?.let { context[BindingContext.REFERENCE_TARGET, it] } val targetParent = getTargetParentByQualifier(file, qualifier != null, qualifierDescriptor) ?: return null - val anyType = KotlinBuiltIns.getInstance().anyType + val anyType = module.builtIns.anyType return ClassInfo( name = name, diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByNamedArgumentActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByNamedArgumentActionFactory.kt index f075615ea6a..2d84bc6cbf8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByNamedArgumentActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByNamedArgumentActionFactory.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns public object CreateParameterByNamedArgumentActionFactory: CreateParameterFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): JetValueArgument? { @@ -47,7 +48,7 @@ public object CreateParameterByNamedArgumentActionFactory: CreateParameterFromUs val callable = DescriptorToSourceUtilsIde.getAnyDeclaration(callElement.project, functionDescriptor) ?: return null if (!((callable is JetFunction || callable is JetClass) && callable.canRefactor())) return null - val anyType = KotlinBuiltIns.getInstance().anyType + val anyType = functionDescriptor.builtIns.anyType val paramType = argumentExpression?.guessTypes(context, result.moduleDescriptor)?.let { when (it.size()) { 0 -> anyType diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt index 5a7000c1d8f..2d2ebb4e83e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt @@ -58,12 +58,13 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory? { val result = (diagnostic.psiFile as? JetFile)?.analyzeFullyAndGetResult() ?: return null val context = result.bindingContext + val moduleDescriptor = result.moduleDescriptor val varExpected = element.getAssignmentByLHS() != null - val paramType = element.getExpressionForTypeGuess().guessTypes(context, result.moduleDescriptor).let { + val paramType = element.getExpressionForTypeGuess().guessTypes(context, moduleDescriptor).let { when (it.size()) { - 0 -> KotlinBuiltIns.getInstance().anyType + 0 -> moduleDescriptor.builtIns.anyType 1 -> it.first() else -> return null } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt index 88c6b33f029..5c6179f9d91 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractableAnalysisUtil.kt @@ -616,13 +616,14 @@ private fun ExtractionData.inferParametersInfo( resolvedCall: ResolvedCall<*>?, useSmartCastsIfPossible: Boolean ): JetType { + val builtIns = originalDescriptor.builtIns return when { extractFunctionRef -> { originalDescriptor as FunctionDescriptor - KotlinBuiltIns.getInstance().getFunctionType(Annotations.EMPTY, - originalDescriptor.getExtensionReceiverParameter()?.getType(), - originalDescriptor.getValueParameters().map { it.getType() }, - originalDescriptor.getReturnType() ?: originalDescriptor.builtIns.defaultReturnType) + builtIns.getFunctionType(Annotations.EMPTY, + originalDescriptor.getExtensionReceiverParameter()?.getType(), + originalDescriptor.getValueParameters().map { it.getType() }, + originalDescriptor.getReturnType() ?: builtIns.defaultReturnType) } parameterExpression != null -> (if (useSmartCastsIfPossible) bindingContext[BindingContext.SMARTCAST, parameterExpression] else null) @@ -643,7 +644,7 @@ private fun ExtractionData.inferParametersInfo( } receiverToExtract.exists() -> receiverToExtract.getType() else -> null - } ?: originalDescriptor.builtIns.defaultParameterType + } ?: builtIns.defaultParameterType } for (refInfo in getBrokenReferencesInfo(createTemporaryCodeBlock())) { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt index 6158e0d6d16..20e9d77c1b2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt @@ -52,6 +52,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.isFlexible +import org.jetbrains.kotlin.types.typeUtil.builtIns import java.util.ArrayList import java.util.Collections import java.util.HashMap @@ -636,7 +637,7 @@ fun ExtractionGeneratorConfiguration.generateDeclaration( } if (declaration.getTypeReference() != null) { - declaration.getTypeReference()?.debugTypeInfo = KotlinBuiltIns.getInstance().getAnyType() + declaration.getTypeReference()?.debugTypeInfo = descriptor.returnType.builtIns.anyType } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterMethodUsageProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterMethodUsageProcessor.kt index d57c07985de..946b6344a60 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterMethodUsageProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterMethodUsageProcessor.kt @@ -44,6 +44,7 @@ import org.jetbrains.kotlin.idea.search.declarationsSearch.searchOverriders import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import java.util.Collections public class KotlinIntroduceParameterMethodUsageProcessor : IntroduceParameterMethodUsagesProcessor { @@ -70,7 +71,7 @@ public class KotlinIntroduceParameterMethodUsageProcessor : IntroduceParameterMe val defaultValueForCall = (data.getParameterInitializer().getExpression()!! as? PsiExpression)?.let { it.j2k() } changeInfo.addParameter(JetParameterInfo(callableDescriptor = psiMethodDescriptor, name = data.getParameterName(), - type = KotlinBuiltIns.getInstance().getAnyType(), + type = psiMethodDescriptor.builtIns.anyType, defaultValueForCall = defaultValueForCall)) return changeInfo } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt index 98f04131bd4..cc4a7156cb2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt @@ -30,7 +30,6 @@ import org.jetbrains.kotlin.asJava.getRepresentativeLightMethod import org.jetbrains.kotlin.asJava.namedUnwrappedElement import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.asJava.unwrapped -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.idea.JetLanguage import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet @@ -369,8 +368,8 @@ class KotlinPullUpHelper( // TODO: Drop after PsiTypes in light elements are properly generated if (member is JetCallableDeclaration && member.typeReference == null) { - val returnType = (data.memberDescriptors[member] as CallableDescriptor).returnType ?: KotlinBuiltIns.getInstance().anyType - returnType.anonymousObjectSuperTypeOrNull()?.let { member.setType(it, false) } + val returnType = (data.memberDescriptors[member] as CallableDescriptor).returnType + returnType?.anonymousObjectSuperTypeOrNull()?.let { member.setType(it, false) } } val project = member.project diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/pullUpUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/pullUpUtils.kt index 1dfb2157c2c..2ba98fa9e51 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/pullUpUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/pullUpUtils.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.TypeSubstitutor import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.typeUtil.isUnit @@ -108,14 +109,15 @@ fun makeAbstract(member: JetCallableDeclaration, member.addModifierWithSpace(JetTokens.ABSTRACT_KEYWORD) } + val builtIns = originalMemberDescriptor.builtIns if (member.typeReference == null) { var type = originalMemberDescriptor.returnType if (type == null || type.isError) { - type = KotlinBuiltIns.getInstance().nullableAnyType + type = builtIns.nullableAnyType } else { type = substitutor.substitute(type.anonymousObjectSuperTypeOrNull() ?: type, Variance.INVARIANT) - ?: KotlinBuiltIns.getInstance().nullableAnyType + ?: builtIns.nullableAnyType } if (member is JetProperty || !type.isUnit()) {