SLC: honor wildcard suppression on declarations
^KT-61734 fixed
This commit is contained in:
+24
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.*
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtKClassAnnotationValue.KtNonLocalKClassAnnotationValue
|
||||
import org.jetbrains.kotlin.analysis.api.components.buildClassType
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtAnnotatedSymbol
|
||||
@@ -21,6 +22,7 @@ import org.jetbrains.kotlin.asJava.classes.annotateByTypeAnnotationProvider
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassBase
|
||||
import org.jetbrains.kotlin.light.classes.symbol.getContainingSymbolsWithSelf
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.JvmStandardClassIds
|
||||
import org.jetbrains.kotlin.name.JvmStandardClassIds.JVM_OVERLOADS_CLASS_ID
|
||||
@@ -91,6 +93,28 @@ internal fun KtAnnotatedSymbol.hasJvmStaticAnnotation(
|
||||
|
||||
internal fun KtAnnotatedSymbol.hasInlineOnlyAnnotation(): Boolean = hasAnnotation(StandardClassIds.Annotations.InlineOnly)
|
||||
|
||||
context(KtAnalysisSession)
|
||||
internal fun KtDeclarationSymbol.suppressWildcardMode(
|
||||
declarationFilter: (KtDeclarationSymbol) -> Boolean = { true },
|
||||
): Boolean? {
|
||||
return getContainingSymbolsWithSelf().firstNotNullOfOrNull { symbol ->
|
||||
symbol.takeIf(declarationFilter)?.suppressWildcard()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun KtAnnotatedSymbol.suppressWildcard(): Boolean? {
|
||||
if (hasJvmWildcardAnnotation()) return true
|
||||
return getJvmSuppressWildcardsFromAnnotation()
|
||||
}
|
||||
|
||||
internal fun KtAnnotatedSymbol.getJvmSuppressWildcardsFromAnnotation(): Boolean? {
|
||||
return annotationsByClassId(JvmStandardClassIds.Annotations.JvmSuppressWildcards).firstOrNull()?.let { annoApp ->
|
||||
(annoApp.arguments.firstOrNull()?.expression as? KtConstantAnnotationValue)?.constantValue?.value as? Boolean
|
||||
}
|
||||
}
|
||||
|
||||
internal fun KtAnnotatedSymbol.hasJvmWildcardAnnotation(): Boolean = hasAnnotation(JvmStandardClassIds.Annotations.JvmWildcard)
|
||||
|
||||
internal fun KtAnnotatedSymbol.findAnnotation(
|
||||
classId: ClassId,
|
||||
useSiteTargetFilter: AnnotationUseSiteTargetFilter = AnyAnnotationUseSiteTargetFilter,
|
||||
|
||||
+1
@@ -80,6 +80,7 @@ internal class SymbolLightFieldForProperty private constructor(
|
||||
this@SymbolLightFieldForProperty,
|
||||
allowErrorTypes = true,
|
||||
typeMappingMode,
|
||||
suppressWildcards = propertySymbol.suppressWildcardMode(),
|
||||
)
|
||||
} ?: nonExistentType()
|
||||
}
|
||||
|
||||
+8
@@ -269,12 +269,20 @@ internal class SymbolLightAccessorMethod private constructor(
|
||||
allowErrorTypes = true,
|
||||
typeMappingMode,
|
||||
containingClass.isAnnotationType,
|
||||
suppressWildcards(),
|
||||
)
|
||||
} ?: nonExistentType()
|
||||
}
|
||||
|
||||
override fun getReturnType(): PsiType = _returnedType
|
||||
|
||||
override fun suppressWildcards(): Boolean? =
|
||||
withAccessorSymbol { accessorSymbol ->
|
||||
accessorSymbol.suppressWildcardMode { parent ->
|
||||
parent !is KtPropertySymbol
|
||||
}
|
||||
}
|
||||
|
||||
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
||||
return super.isEquivalentTo(another) || basicIsEquivalentTo(this, another as? PsiField)
|
||||
}
|
||||
|
||||
+6
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.computeThrowsList
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.hasDeprecatedAnnotation
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.suppressWildcardMode
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassBase
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassForInterfaceDefaultImpls
|
||||
import org.jetbrains.kotlin.light.classes.symbol.compareSymbolPointers
|
||||
@@ -157,4 +158,9 @@ internal abstract class SymbolLightMethod<FType : KtFunctionLikeSymbol> private
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = kotlinOrigin.hashCode()
|
||||
|
||||
override fun suppressWildcards(): Boolean? =
|
||||
withFunctionSymbol { functionSymbol ->
|
||||
functionSymbol.suppressWildcardMode()
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -134,4 +134,6 @@ internal abstract class SymbolLightMethodBase(
|
||||
}
|
||||
|
||||
abstract fun isOverride(): Boolean
|
||||
|
||||
internal open fun suppressWildcards(): Boolean? = null
|
||||
}
|
||||
|
||||
+1
@@ -234,6 +234,7 @@ internal class SymbolLightSimpleMethod(
|
||||
allowErrorTypes = true,
|
||||
typeMappingMode,
|
||||
this@SymbolLightSimpleMethod.containingClass.isAnnotationType,
|
||||
suppressWildcards = suppressWildcards(),
|
||||
)?.let {
|
||||
annotateByKtType(it.type, ktType, it, modifierList)
|
||||
}
|
||||
|
||||
+3
-1
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.light.classes.symbol.*
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.annotateByKtType
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.suppressWildcardMode
|
||||
import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
|
||||
@@ -80,7 +81,8 @@ internal abstract class SymbolLightParameterCommon(
|
||||
ktType.asPsiTypeElement(
|
||||
this@SymbolLightParameterCommon,
|
||||
allowErrorTypes = true,
|
||||
ktType.typeMappingMode()
|
||||
ktType.typeMappingMode(),
|
||||
suppressWildcards = parameterSymbol.suppressWildcardMode(),
|
||||
)?.let {
|
||||
annotateByKtType(it.type, ktType, it, modifierList)
|
||||
}
|
||||
|
||||
+2
-1
@@ -90,7 +90,8 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
val psiType = ktType.asPsiTypeElement(
|
||||
this,
|
||||
allowErrorTypes = true,
|
||||
ktType.typeMappingMode()
|
||||
ktType.typeMappingMode(),
|
||||
suppressWildcards = receiver.suppressWildcard() ?: method.suppressWildcards(),
|
||||
)?.let {
|
||||
annotateByKtType(it.type, ktType, it, modifierList)
|
||||
}
|
||||
|
||||
+4
@@ -44,6 +44,10 @@ import java.util.*
|
||||
internal fun <L : Any> L.invalidAccess(): Nothing =
|
||||
error("Cls delegate shouldn't be accessed for symbol light classes! Qualified name: ${javaClass.name}")
|
||||
|
||||
context(KtAnalysisSession)
|
||||
internal fun KtDeclarationSymbol.getContainingSymbolsWithSelf(): Sequence<KtDeclarationSymbol> =
|
||||
generateSequence(this) { it.getContainingSymbol() }
|
||||
|
||||
internal fun KtAnalysisSession.mapType(
|
||||
type: KtType,
|
||||
psiContext: PsiElement,
|
||||
|
||||
Reference in New Issue
Block a user