FIR IDE: null out for erroneous PsiType conversion

This commit is contained in:
Jinseong Jeon
2021-08-27 16:53:27 -07:00
committed by Ilya Kirillov
parent 8e242655f9
commit 5446a8ad10
10 changed files with 44 additions and 22 deletions
@@ -67,6 +67,7 @@ internal class FirLightFieldForEnumEntry(
private val _type: PsiType by lazyPub {
analyzeWithSymbolAsContext(enumEntrySymbol) {
enumEntrySymbol.annotatedType.type.asPsiType(this@FirLightFieldForEnumEntry)
?: this@FirLightFieldForEnumEntry.nonExistentType()
}
}
@@ -87,4 +88,4 @@ internal class FirLightFieldForEnumEntry(
override fun equals(other: Any?): Boolean =
other is FirLightFieldForEnumEntry &&
enumEntrySymbol == other.enumEntrySymbol
}
}
@@ -41,6 +41,7 @@ internal class FirLightFieldForObjectSymbol(
private val _type: PsiType by lazyPub {
analyzeWithSymbolAsContext(objectSymbol) {
objectSymbol.buildSelfClassType().asPsiType(this@FirLightFieldForObjectSymbol)
?: this@FirLightFieldForObjectSymbol.nonExistentType()
}
}
@@ -64,4 +65,4 @@ internal class FirLightFieldForObjectSymbol(
override fun hashCode(): Int = kotlinOrigin.hashCode()
override fun isValid(): Boolean = super.isValid() && objectSymbol.isValid()
}
}
@@ -30,6 +30,7 @@ internal class FirLightFieldForPropertySymbol(
private val _returnedType: PsiType by lazyPub {
analyzeWithSymbolAsContext(propertySymbol) {
propertySymbol.annotatedType.type.asPsiType(this@FirLightFieldForPropertySymbol)
?: this@FirLightFieldForPropertySymbol.nonExistentType()
}
}
@@ -114,4 +115,4 @@ internal class FirLightFieldForPropertySymbol(
override fun hashCode(): Int = kotlinOrigin.hashCode()
override fun isValid(): Boolean = super.isValid() && propertySymbol.isValid()
}
}
@@ -6,7 +6,9 @@
package org.jetbrains.kotlin.light.classes.symbol
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiType
import org.jetbrains.kotlin.idea.frontend.api.InvalidWayOfUsingAnalysisSession
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSessionProvider
@@ -31,4 +33,7 @@ internal inline fun <R> Project.analyzeWithSymbolAsContext(
action: KtAnalysisSession.() -> R
): R {
return KtAnalysisSessionProvider.getInstance(this).analyzeWithSymbolAsContext(contextSymbol, action)
}
}
internal fun PsiElement.nonExistentType(): PsiType =
JavaPsiFacade.getElementFactory(project).createTypeFromText("error.NonExistentClass", this)
@@ -149,14 +149,15 @@ internal class FirLightAccessorMethodForSymbol(
override fun getNameIdentifier(): PsiIdentifier = _identifier
private val _returnedType: PsiType? by lazyPub {
private val _returnedType: PsiType by lazyPub {
if (!isGetter) return@lazyPub PsiType.VOID
analyzeWithSymbolAsContext(containingPropertySymbol) {
containingPropertySymbol.annotatedType.type.asPsiType(this@FirLightAccessorMethodForSymbol)
?: this@FirLightAccessorMethodForSymbol.nonExistentType()
}
}
override fun getReturnType(): PsiType? = _returnedType
override fun getReturnType(): PsiType = _returnedType
override fun equals(other: Any?): Boolean =
this === other ||
@@ -131,6 +131,7 @@ internal class FirLightSimpleMethodForSymbol(
if (isVoidReturnType) return@lazyPub PsiType.VOID
analyzeWithSymbolAsContext(functionSymbol) {
functionSymbol.annotatedType.type.asPsiType(this@FirLightSimpleMethodForSymbol)
?: this@FirLightSimpleMethodForSymbol.nonExistentType()
}
}
@@ -142,4 +143,4 @@ internal class FirLightSimpleMethodForSymbol(
override fun hashCode(): Int = functionSymbol.hashCode()
override fun isValid(): Boolean = super.isValid() && functionSymbol.isValid()
}
}
@@ -48,6 +48,7 @@ internal abstract class FirLightParameterBaseForSymbol(
private val _type by lazyPub {
val convertedType = analyzeWithSymbolAsContext(parameterSymbol) {
parameterSymbol.annotatedType.type.asPsiType(this@FirLightParameterBaseForSymbol)
?: this@FirLightParameterBaseForSymbol.nonExistentType()
}
if (convertedType is PsiArrayType && parameterSymbol.isVararg) {
PsiEllipsisType(convertedType.componentType, convertedType.annotationProvider)
@@ -59,4 +60,4 @@ internal abstract class FirLightParameterBaseForSymbol(
abstract override fun equals(other: Any?): Boolean
abstract override fun hashCode(): Int
}
}
@@ -72,6 +72,7 @@ internal class FirLightParameterForReceiver private constructor(
private val _type: PsiType by lazyPub {
analyzeWithSymbolAsContext(context) {
receiverTypeAndAnnotations.type.asPsiType(this@FirLightParameterForReceiver)
?: this@FirLightParameterForReceiver.nonExistentType()
}
}