Allow KtEnumEntry...RefExpression.referencedElement be nullable

This commit fixes KNPE provoked by RemoveExplicitTypeArgumentsIntention
#KT-29735 Fixed
This commit is contained in:
Mikhail Glukhikh
2020-12-17 13:04:12 +03:00
parent 4f96f9d6a1
commit d907c48d9c
5 changed files with 30 additions and 5 deletions
@@ -36,8 +36,8 @@ class KtEnumEntrySuperclassReferenceExpression :
super(stub, KtStubElementTypes.ENUM_ENTRY_SUPERCLASS_REFERENCE_EXPRESSION)
// It is the owner enum class (not an enum entry but the whole enum)
private val referencedElement: KtClass
get() = calcReferencedElement()!!
private val referencedElement: KtClass?
get() = calcReferencedElement()
private fun calcReferencedElement(): KtClass? {
val owner = this.getStrictParentOfType<KtEnumEntry>()
@@ -54,15 +54,15 @@ class KtEnumEntrySuperclassReferenceExpression :
}
override fun getReferencedNameAsName(): Name {
return referencedElement.name?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED
return referencedElement?.name?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED
}
override fun getReferencedNameElement(): PsiElement {
return referencedElement
return referencedElement!!
}
override fun getIdentifier(): PsiElement? {
return referencedElement.nameIdentifier
return referencedElement?.nameIdentifier
}
override fun getReferencedNameElementType(): IElementType {
@@ -223,4 +223,14 @@
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unnecessary type argument</problem_class>
<description>Remove explicit type arguments</description>
</problem>
<problem>
<file>kt29735.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<package>kt29735</package>
<entry_point TYPE="file" FQNAME="kt29735.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unnecessary type argument</problem_class>
<description>Remove explicit type arguments</description>
</problem>
</problems>
@@ -0,0 +1,5 @@
// WITH_RUNTIME
enum class A(val strings: List<String>) {
B(listOf<Str<caret>ing>(""))
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
enum class A(val strings: List<String>) {
B(listOf(""))
}
@@ -14492,6 +14492,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/removeExplicitTypeArguments/insideOtherCall.kt");
}
@TestMetadata("kt29735.kt")
public void testKt29735() throws Exception {
runTest("idea/testData/intentions/removeExplicitTypeArguments/kt29735.kt");
}
@TestMetadata("kt31441.kt")
public void testKt31441() throws Exception {
runTest("idea/testData/intentions/removeExplicitTypeArguments/kt31441.kt");