Added utility extension methods to not use TypeUtils
This commit is contained in:
@@ -27,6 +27,7 @@ import com.intellij.codeInsight.completion.*
|
||||
import java.util.*
|
||||
import org.jetbrains.jet.plugin.completion.*
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||
|
||||
class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
val resolveSession: ResolveSessionForBodies,
|
||||
@@ -87,7 +88,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
if (itemsToSkip.contains(descriptor)) continue
|
||||
|
||||
val types = typesWithAutoCasts(descriptor)
|
||||
val nonNullTypes = types.map { TypeUtils.makeNotNullable(it) }
|
||||
val nonNullTypes = types.map { it.makeNotNullable() }
|
||||
val classifier = { (expectedInfo: ExpectedInfo) ->
|
||||
when {
|
||||
types.any { it.isSubtypeOf(expectedInfo.`type`) } -> ExpectedInfoClassification.MATCHES
|
||||
|
||||
@@ -26,9 +26,7 @@ import org.jetbrains.jet.lang.descriptors.Visibilities
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor
|
||||
import org.jetbrains.jet.plugin.completion.DescriptorLookupConverter
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||
import org.jetbrains.jet.plugin.completion.handlers.CaretPosition
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
import com.intellij.codeInsight.lookup.LookupElementDecorator
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
@@ -38,7 +36,7 @@ import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import org.jetbrains.jet.plugin.completion.ExpectedInfo
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||
|
||||
// adds java static members, enum members and members from class object
|
||||
class StaticMembers(val bindingContext: BindingContext, val resolveSession: ResolveSessionForBodies) {
|
||||
@@ -71,7 +69,7 @@ class StaticMembers(val bindingContext: BindingContext, val resolveSession: Reso
|
||||
expectedInfo ->
|
||||
when {
|
||||
returnType.isSubtypeOf(expectedInfo.`type`) -> ExpectedInfoClassification.MATCHES
|
||||
returnType.isNullable() && TypeUtils.makeNotNullable(returnType).isSubtypeOf(expectedInfo.`type`) -> ExpectedInfoClassification.MAKE_NOT_NULLABLE
|
||||
returnType.isNullable() && returnType.makeNotNullable().isSubtypeOf(expectedInfo.`type`) -> ExpectedInfoClassification.MAKE_NOT_NULLABLE
|
||||
else -> ExpectedInfoClassification.NOT_MATCHES
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ import org.jetbrains.jet.lang.psi.JetValueArgumentList
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.plugin.completion.ExpectedInfo
|
||||
import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||
|
||||
class ThisItems(val bindingContext: BindingContext) {
|
||||
public fun addToCollection(collection: MutableCollection<LookupElement>, context: JetExpression, expectedInfos: Collection<ExpectedInfo>) {
|
||||
@@ -48,7 +48,7 @@ class ThisItems(val bindingContext: BindingContext) {
|
||||
val classifier = { (expectedInfo: ExpectedInfo) ->
|
||||
when {
|
||||
thisType.isSubtypeOf(expectedInfo.`type`) -> ExpectedInfoClassification.MATCHES
|
||||
thisType.isNullable() && TypeUtils.makeNotNullable(thisType).isSubtypeOf(expectedInfo.`type`) -> ExpectedInfoClassification.MAKE_NOT_NULLABLE
|
||||
thisType.isNullable() && thisType.makeNotNullable().isSubtypeOf(expectedInfo.`type`) -> ExpectedInfoClassification.MAKE_NOT_NULLABLE
|
||||
else -> ExpectedInfoClassification.NOT_MATCHES
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.plugin.completion.smart
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer
|
||||
@@ -37,12 +36,13 @@ import org.jetbrains.jet.plugin.completion.*
|
||||
import org.jetbrains.jet.plugin.completion.handlers.CaretPosition
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities
|
||||
import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||
|
||||
class TypeInstantiationItems(val bindingContext: BindingContext,
|
||||
val resolveSession: ResolveSessionForBodies,
|
||||
val visibilityFilter: (DeclarationDescriptor) -> Boolean) {
|
||||
public fun addToCollection(collection: MutableCollection<LookupElement>, expectedInfos: Collection<ExpectedInfo>) {
|
||||
val expectedInfosGrouped: Map<JetType, List<ExpectedInfo>> = expectedInfos.groupBy { TypeUtils.makeNotNullable(it.`type`) }
|
||||
val expectedInfosGrouped: Map<JetType, List<ExpectedInfo>> = expectedInfos.groupBy { it.`type`.makeNotNullable() }
|
||||
for ((jetType, types) in expectedInfosGrouped) {
|
||||
val tail = mergeTails(types.map { it.tail })
|
||||
addToCollection(collection, jetType, tail)
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind
|
||||
import java.util.Collections
|
||||
@@ -35,6 +34,7 @@ import org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability
|
||||
import java.util.HashSet
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||
|
||||
class TypesWithAutoCasts(val bindingContext: BindingContext) {
|
||||
public fun calculate(expression: JetExpression, receiver: JetExpression?): (DeclarationDescriptor) -> Iterable<JetType> {
|
||||
@@ -50,8 +50,8 @@ class TypesWithAutoCasts(val bindingContext: BindingContext) {
|
||||
return listOf()
|
||||
}
|
||||
if (descriptor is VariableDescriptor) {
|
||||
if (notNullVariables.contains(descriptor) && returnType != null) {
|
||||
returnType = TypeUtils.makeNotNullable(returnType!!)
|
||||
if (notNullVariables.contains(descriptor)) {
|
||||
returnType = returnType?.makeNotNullable()
|
||||
}
|
||||
|
||||
val autoCastTypes = variableToTypes[descriptor]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.jetbrains.jet.plugin.util
|
||||
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
|
||||
fun JetType.makeNullable() = TypeUtils.makeNullable(this)
|
||||
fun JetType.makeNotNullable() = TypeUtils.makeNotNullable(this)
|
||||
Reference in New Issue
Block a user