Drop some usages of KotlinBuiltIns.getInstance() in idea module

This commit is contained in:
Pavel V. Talanov
2015-09-21 20:31:25 +03:00
parent f1c76f0467
commit 51113c10b4
30 changed files with 99 additions and 64 deletions
@@ -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()) {
@@ -421,7 +421,7 @@ class ExpectedInfos(
private fun calculateForIf(expressionWithType: JetExpression): Collection<ExpectedInfo>? {
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<ExpectedInfo>? {
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<ExpectedInfo>? {
@@ -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<HeuristicSignatures>())
val detector = TypesWithContainsDetector(scope, leftOperandType, resolutionFacade)
val byTypeFilter = object : ByTypeFilter {
override fun matchingSubstitutor(descriptorType: FuzzyType): TypeSubstitutor? {
@@ -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<FuzzyType, Boolean>()
private val containsName = Name.identifier("contains")
private val booleanType = KotlinBuiltIns.getInstance().getBooleanType()
private val booleanType = resolutionFacade.moduleDescriptor.builtIns.booleanType
private val heuristicSignatures = resolutionFacade.ideService<HeuristicSignatures>()
private val typesWithExtensionContains: Collection<JetType> = scope.getFunctions(containsName, NoLookupLocation.FROM_IDE)
.filter { it.getExtensionReceiverParameter() != null && isGoodContainsFunction(it, listOf()) }