[FIR] Remove annotations.any from FirParcelizeAnnotationChecker
This commit is contained in:
committed by
Space Team
parent
4cddbb5fc0
commit
23301e3369
+13
-2
@@ -23,9 +23,12 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
|
||||
private fun FirAnnotation.toAnnotationLookupTag(session: FirSession): ConeClassLikeLookupTag? =
|
||||
fun FirAnnotation.toAnnotationClassLikeType(session: FirSession): ConeClassLikeType? =
|
||||
// this cast fails when we have generic-typed annotations @T
|
||||
(annotationTypeRef.coneType as? ConeClassLikeType)?.fullyExpandedType(session)?.lookupTag
|
||||
(annotationTypeRef.coneType as? ConeClassLikeType)?.fullyExpandedType(session)
|
||||
|
||||
private fun FirAnnotation.toAnnotationLookupTag(session: FirSession): ConeClassLikeLookupTag? =
|
||||
toAnnotationClassLikeType(session)?.lookupTag
|
||||
|
||||
private fun FirAnnotation.toAnnotationLookupTagSafe(session: FirSession): ConeClassLikeLookupTag? =
|
||||
annotationTypeRef.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session)?.lookupTag
|
||||
@@ -105,6 +108,10 @@ private val USE_SITE_TARGET_NAME_MAP = mapOf(
|
||||
private val DEFAULT_USE_SITE_TARGETS: Set<AnnotationUseSiteTarget> =
|
||||
USE_SITE_TARGET_NAME_MAP.values.fold(setOf<AnnotationUseSiteTarget>()) { a, b -> a + b } - setOf(AnnotationUseSiteTarget.FILE)
|
||||
|
||||
fun FirDeclaration.hasAnnotation(type: ConeClassLikeType, session: FirSession): Boolean {
|
||||
return annotations.hasAnnotation(type, session)
|
||||
}
|
||||
|
||||
fun FirDeclaration.hasAnnotation(classId: ClassId, session: FirSession): Boolean {
|
||||
return annotations.hasAnnotation(classId, session)
|
||||
}
|
||||
@@ -121,6 +128,10 @@ fun FirAnnotationContainer.hasAnnotation(classId: ClassId, session: FirSession):
|
||||
return annotations.hasAnnotation(classId, session)
|
||||
}
|
||||
|
||||
fun List<FirAnnotation>.hasAnnotation(type: ConeClassLikeType, session: FirSession): Boolean {
|
||||
return this.any { it.toAnnotationClassLikeType(session) == type }
|
||||
}
|
||||
|
||||
fun List<FirAnnotation>.hasAnnotation(classId: ClassId, session: FirSession): Boolean {
|
||||
return this.any { it.toAnnotationClassId(session) == classId }
|
||||
}
|
||||
|
||||
+4
-2
@@ -13,7 +13,9 @@ import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirAnnotationCallCh
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.findClosestClassOrObject
|
||||
import org.jetbrains.kotlin.fir.correspondingProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
|
||||
import org.jetbrains.kotlin.fir.declarations.toAnnotationClassId
|
||||
import org.jetbrains.kotlin.fir.declarations.toAnnotationClassLikeType
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.fromPrimaryConstructor
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
@@ -93,8 +95,8 @@ object FirParcelizeAnnotationChecker : FirAnnotationCallChecker() {
|
||||
if (annotationContainer is FirValueParameter && annotationContainer.correspondingProperty?.fromPrimaryConstructor == true) {
|
||||
val enclosingClass = context.findClosestClassOrObject() ?: return
|
||||
|
||||
val annotationType = annotationCall.typeRef.coneType
|
||||
if (enclosingClass.annotations.any { it.typeRef.coneType == annotationType }) {
|
||||
val annotationType = annotationCall.toAnnotationClassLikeType(context.session) ?: return
|
||||
if (enclosingClass.hasAnnotation(annotationType, context.session)) {
|
||||
val reportElement = annotationCall.calleeReference.source ?: annotationCall.source
|
||||
reporter.reportOn(reportElement, KtErrorsParcelize.REDUNDANT_TYPE_PARCELER, enclosingClass.symbol, context)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user