Templates "ifn" and "inn" to use kotlinVariable() instead of suggestVariableName()
This commit is contained in:
@@ -51,6 +51,7 @@ fun KotlinType.immediateSupertypes(): Collection<KotlinType> = TypeUtils.getImme
|
|||||||
fun KotlinType.supertypes(): Collection<KotlinType> = TypeUtils.getAllSupertypes(this)
|
fun KotlinType.supertypes(): Collection<KotlinType> = TypeUtils.getAllSupertypes(this)
|
||||||
|
|
||||||
fun KotlinType.isNothing(): Boolean = KotlinBuiltIns.isNothing(this)
|
fun KotlinType.isNothing(): Boolean = KotlinBuiltIns.isNothing(this)
|
||||||
|
fun KotlinType.isNullableNothing(): Boolean = KotlinBuiltIns.isNullableNothing(this)
|
||||||
fun KotlinType.isUnit(): Boolean = KotlinBuiltIns.isUnit(this)
|
fun KotlinType.isUnit(): Boolean = KotlinBuiltIns.isUnit(this)
|
||||||
fun KotlinType.isAnyOrNullableAny(): Boolean = KotlinBuiltIns.isAnyOrNullableAny(this)
|
fun KotlinType.isAnyOrNullableAny(): Boolean = KotlinBuiltIns.isAnyOrNullableAny(this)
|
||||||
fun KotlinType.isBoolean(): Boolean = KotlinBuiltIns.isBoolean(this)
|
fun KotlinType.isBoolean(): Boolean = KotlinBuiltIns.isBoolean(this)
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.typeUtil.containsError
|
import org.jetbrains.kotlin.types.typeUtil.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -399,18 +397,29 @@ class ExpectedInfos(
|
|||||||
if (otherOperand != null) {
|
if (otherOperand != null) {
|
||||||
var expectedType = bindingContext.getType(otherOperand) ?: return null
|
var expectedType = bindingContext.getType(otherOperand) ?: return null
|
||||||
|
|
||||||
|
val expectedName = expectedNameFromExpression(otherOperand)
|
||||||
|
|
||||||
|
if (expectedType.isNullableNothing()) { // other operand is 'null'
|
||||||
|
return listOf(ExpectedInfo(NullableTypesFilter, expectedName, null))
|
||||||
|
}
|
||||||
|
|
||||||
// if we complete argument of == or !=, make types in expected info's nullable to allow nullable items too
|
// if we complete argument of == or !=, make types in expected info's nullable to allow nullable items too
|
||||||
if (operationToken in COMPARISON_TOKENS) {
|
if (operationToken in COMPARISON_TOKENS) {
|
||||||
expectedType = expectedType.makeNullable()
|
expectedType = expectedType.makeNullable()
|
||||||
}
|
}
|
||||||
|
|
||||||
return listOf(ExpectedInfo(expectedType, expectedNameFromExpression(otherOperand), null))
|
return listOf(ExpectedInfo(expectedType, expectedName, null))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private object NullableTypesFilter : ByTypeFilter {
|
||||||
|
override fun matchingSubstitutor(descriptorType: FuzzyType)
|
||||||
|
= if (descriptorType.type.nullability() != TypeNullability.NOT_NULL) TypeSubstitutor.EMPTY else null
|
||||||
|
}
|
||||||
|
|
||||||
private fun calculateForIf(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
private fun calculateForIf(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
|
||||||
val ifExpression = (expressionWithType.getParent() as? KtContainerNode)?.getParent() as? KtIfExpression ?: return null
|
val ifExpression = (expressionWithType.getParent() as? KtContainerNode)?.getParent() as? KtIfExpression ?: return null
|
||||||
return when (expressionWithType) {
|
return when (expressionWithType) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
<template resource-bundle="org.jetbrains.kotlin.idea.KotlinBundle" key="livetemplate.description.ifn"
|
<template resource-bundle="org.jetbrains.kotlin.idea.KotlinBundle" key="livetemplate.description.ifn"
|
||||||
name="ifn" toReformat="true" toShortenFQNames="true"
|
name="ifn" toReformat="true" toShortenFQNames="true"
|
||||||
value="if ($VAR$ == null) { $END$ }">
|
value="if ($VAR$ == null) { $END$ }">
|
||||||
<variable alwaysStopAt="true" defaultValue=""i"" expression="kotlinSuggestVariableName()" name="VAR" />
|
<variable alwaysStopAt="true" defaultValue=""i"" expression="kotlinVariable()" name="VAR" />
|
||||||
<context>
|
<context>
|
||||||
<option name="KOTLIN_EXPRESSION" value="true" />
|
<option name="KOTLIN_EXPRESSION" value="true" />
|
||||||
</context>
|
</context>
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<template resource-bundle="org.jetbrains.kotlin.idea.KotlinBundle" key="livetemplate.description.inn"
|
<template resource-bundle="org.jetbrains.kotlin.idea.KotlinBundle" key="livetemplate.description.inn"
|
||||||
name="inn" toReformat="true" toShortenFQNames="true"
|
name="inn" toReformat="true" toShortenFQNames="true"
|
||||||
value="if ($VAR$ != null) { $END$ }">
|
value="if ($VAR$ != null) { $END$ }">
|
||||||
<variable alwaysStopAt="true" defaultValue=""i"" expression="kotlinSuggestVariableName()" name="VAR" />
|
<variable alwaysStopAt="true" defaultValue=""i"" expression="kotlinVariable()" name="VAR" />
|
||||||
<context>
|
<context>
|
||||||
<option name="KOTLIN_EXPRESSION" value="true" />
|
<option name="KOTLIN_EXPRESSION" value="true" />
|
||||||
</context>
|
</context>
|
||||||
|
|||||||
Reference in New Issue
Block a user