Introduce Type Alias: Don't change non-nullable type to nullable alias
#KT-15840 Fixed
This commit is contained in:
+4
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import java.util.*
|
||||
|
||||
sealed class IntroduceTypeAliasAnalysisResult {
|
||||
@@ -214,6 +215,9 @@ fun findDuplicates(typeAlias: KtTypeAlias): Map<KotlinPsiRange, () -> Unit> {
|
||||
else continue
|
||||
}
|
||||
if (arguments.size != typeAliasDescriptor.declaredTypeParameters.size) continue
|
||||
if (TypeUtils.isNullableType(typeAliasDescriptor.underlyingType)
|
||||
&& occurrence is KtUserType
|
||||
&& occurrence.parent !is KtNullableType) continue
|
||||
rangesWithReplacers += occurrence.toRange() to { replaceOccurrence(occurrence, arguments) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// NAME: NullableA
|
||||
|
||||
class A
|
||||
|
||||
fun f(p: A): <selection>A?</selection> = null
|
||||
@@ -0,0 +1,7 @@
|
||||
// NAME: NullableA
|
||||
|
||||
class A
|
||||
|
||||
typealias NullableA = A?
|
||||
|
||||
fun f(p: A): NullableA = null
|
||||
+6
@@ -4268,6 +4268,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
||||
doIntroduceTypeAliasTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unmatchedNullability.kt")
|
||||
public void testUnmatchedNullability() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceTypeAlias/unmatchedNullability.kt");
|
||||
doIntroduceTypeAliasTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("userTypeDuplicatesNoTypeParameters.kt")
|
||||
public void testUserTypeDuplicatesNoTypeParameters() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceTypeAlias/userTypeDuplicatesNoTypeParameters.kt");
|
||||
|
||||
Reference in New Issue
Block a user