[AA] KtAnnotated: split hasAnnotation to two extensions
This commit is contained in:
committed by
Space Team
parent
2c305b46df
commit
5a74fec3ac
+15
-14
@@ -36,11 +36,11 @@ import java.lang.annotation.ElementType
|
||||
|
||||
internal fun KtAnnotatedSymbol.hasJvmSyntheticAnnotation(
|
||||
annotationUseSiteTarget: AnnotationUseSiteTarget? = null,
|
||||
strictUseSite: Boolean = true,
|
||||
): Boolean = hasAnnotation(JVM_SYNTHETIC_ANNOTATION_CLASS_ID, annotationUseSiteTarget, strictUseSite)
|
||||
acceptAnnotationsWithoutUseSite: Boolean = false,
|
||||
): Boolean = hasAnnotation(JVM_SYNTHETIC_ANNOTATION_CLASS_ID, annotationUseSiteTarget, acceptAnnotationsWithoutUseSite)
|
||||
|
||||
internal fun KtAnnotatedSymbol.getJvmNameFromAnnotation(annotationUseSiteTarget: AnnotationUseSiteTarget? = null): String? {
|
||||
val annotation = findAnnotation(StandardClassIds.Annotations.JvmName, annotationUseSiteTarget, strictUseSite = false)
|
||||
val annotation = findAnnotation(StandardClassIds.Annotations.JvmName, annotationUseSiteTarget, acceptAnnotationsWithoutUseSite = true)
|
||||
return annotation?.let {
|
||||
(it.arguments.firstOrNull()?.expression as? KtConstantAnnotationValue)?.constantValue?.value as? String
|
||||
}
|
||||
@@ -55,8 +55,9 @@ internal fun isHiddenByDeprecation(
|
||||
context(KtAnalysisSession)
|
||||
internal fun KtAnnotatedSymbol.isHiddenOrSynthetic(
|
||||
annotationUseSiteTarget: AnnotationUseSiteTarget? = null,
|
||||
strictUseSite: Boolean = true,
|
||||
) = isHiddenByDeprecation(this, annotationUseSiteTarget) || hasJvmSyntheticAnnotation(annotationUseSiteTarget, strictUseSite)
|
||||
acceptAnnotationsWithoutUseSite: Boolean = false,
|
||||
) = isHiddenByDeprecation(this, annotationUseSiteTarget) ||
|
||||
hasJvmSyntheticAnnotation(annotationUseSiteTarget, acceptAnnotationsWithoutUseSite)
|
||||
|
||||
internal fun KtAnnotatedSymbol.hasJvmFieldAnnotation(): Boolean = hasAnnotation(StandardClassIds.Annotations.JvmField)
|
||||
|
||||
@@ -65,28 +66,28 @@ internal fun KtAnnotatedSymbol.hasPublishedApiAnnotation(annotationUseSiteTarget
|
||||
|
||||
internal fun KtAnnotatedSymbol.hasDeprecatedAnnotation(
|
||||
annotationUseSiteTarget: AnnotationUseSiteTarget? = null,
|
||||
strictUseSite: Boolean = true,
|
||||
): Boolean = hasAnnotation(StandardClassIds.Annotations.Deprecated, annotationUseSiteTarget, strictUseSite)
|
||||
acceptAnnotationsWithoutUseSite: Boolean = false,
|
||||
): Boolean = hasAnnotation(StandardClassIds.Annotations.Deprecated, annotationUseSiteTarget, acceptAnnotationsWithoutUseSite)
|
||||
|
||||
internal fun KtAnnotatedSymbol.hasJvmOverloadsAnnotation(): Boolean = hasAnnotation(JVM_OVERLOADS_CLASS_ID)
|
||||
|
||||
internal fun KtAnnotatedSymbol.hasJvmStaticAnnotation(
|
||||
annotationUseSiteTarget: AnnotationUseSiteTarget? = null,
|
||||
strictUseSite: Boolean = true,
|
||||
): Boolean = hasAnnotation(StandardClassIds.Annotations.JvmStatic, annotationUseSiteTarget, strictUseSite)
|
||||
acceptAnnotationsWithoutUseSite: Boolean = false,
|
||||
): Boolean = hasAnnotation(StandardClassIds.Annotations.JvmStatic, annotationUseSiteTarget, acceptAnnotationsWithoutUseSite)
|
||||
|
||||
internal fun KtAnnotatedSymbol.hasInlineOnlyAnnotation(): Boolean = hasAnnotation(StandardClassIds.Annotations.InlineOnly)
|
||||
|
||||
internal fun KtAnnotatedSymbol.findAnnotation(
|
||||
classId: ClassId,
|
||||
annotationUseSiteTarget: AnnotationUseSiteTarget?,
|
||||
strictUseSite: Boolean = true,
|
||||
acceptAnnotationsWithoutUseSite: Boolean = false,
|
||||
): KtAnnotationApplication? {
|
||||
if (!hasAnnotation(classId, annotationUseSiteTarget, strictUseSite)) return null
|
||||
if (!hasAnnotation(classId, annotationUseSiteTarget, acceptAnnotationsWithoutUseSite)) return null
|
||||
|
||||
return annotations.find {
|
||||
val useSiteTarget = it.useSiteTarget
|
||||
(useSiteTarget == annotationUseSiteTarget || !strictUseSite && useSiteTarget == null) && it.classId == classId
|
||||
(useSiteTarget == annotationUseSiteTarget || acceptAnnotationsWithoutUseSite && useSiteTarget == null) && it.classId == classId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,14 +292,14 @@ internal fun KtAnnotatedSymbol.computeThrowsList(
|
||||
annotationUseSiteTarget: AnnotationUseSiteTarget?,
|
||||
useSitePosition: PsiElement,
|
||||
containingClass: SymbolLightClassBase,
|
||||
strictUseSite: Boolean = true,
|
||||
acceptAnnotationsWithoutUseSite: Boolean = false,
|
||||
) {
|
||||
if (containingClass.isEnum && this is KtFunctionSymbol && name == StandardNames.ENUM_VALUE_OF && isStatic) {
|
||||
builder.addReference(java.lang.IllegalArgumentException::class.qualifiedName)
|
||||
builder.addReference(java.lang.NullPointerException::class.qualifiedName)
|
||||
}
|
||||
|
||||
val annoApp = findAnnotation(StandardClassIds.Annotations.Throws, annotationUseSiteTarget, strictUseSite) ?: return
|
||||
val annoApp = findAnnotation(StandardClassIds.Annotations.Throws, annotationUseSiteTarget, acceptAnnotationsWithoutUseSite) ?: return
|
||||
|
||||
fun handleAnnotationValue(annotationValue: KtAnnotationValue) = when (annotationValue) {
|
||||
is KtArrayAnnotationValue -> {
|
||||
|
||||
+4
-4
@@ -292,14 +292,14 @@ internal fun SymbolLightClassBase.createPropertyAccessors(
|
||||
|
||||
fun KtPropertyAccessorSymbol.needToCreateAccessor(siteTarget: AnnotationUseSiteTarget): Boolean {
|
||||
if (onlyJvmStatic &&
|
||||
!hasJvmStaticAnnotation(siteTarget, strictUseSite = false) &&
|
||||
!declaration.hasJvmStaticAnnotation(siteTarget, strictUseSite = false)
|
||||
!hasJvmStaticAnnotation(siteTarget, acceptAnnotationsWithoutUseSite = true) &&
|
||||
!declaration.hasJvmStaticAnnotation(siteTarget, acceptAnnotationsWithoutUseSite = true)
|
||||
) return false
|
||||
|
||||
if (declaration.hasReifiedParameters) return false
|
||||
if (!hasBody && visibility.isPrivateOrPrivateToThis()) return false
|
||||
if (declaration.isHiddenOrSynthetic(siteTarget)) return false
|
||||
return !isHiddenOrSynthetic(siteTarget, strictUseSite = false)
|
||||
return !isHiddenOrSynthetic(siteTarget, acceptAnnotationsWithoutUseSite = true)
|
||||
}
|
||||
|
||||
val originalElement = declaration.sourcePsiSafe<KtDeclaration>()
|
||||
@@ -384,7 +384,7 @@ private fun hasBackingField(property: KtPropertySymbol): Boolean {
|
||||
}
|
||||
|
||||
if (property.modality == Modality.ABSTRACT ||
|
||||
property.isHiddenOrSynthetic(AnnotationUseSiteTarget.FIELD, strictUseSite = false)
|
||||
property.isHiddenOrSynthetic(AnnotationUseSiteTarget.FIELD, acceptAnnotationsWithoutUseSite = true)
|
||||
) return false
|
||||
|
||||
return hasBackingFieldByPsi ?: property.hasBackingField
|
||||
|
||||
+3
-3
@@ -83,7 +83,7 @@ internal class SymbolLightFieldForProperty private constructor(
|
||||
|
||||
private val _isDeprecated: Boolean by lazyPub {
|
||||
withPropertySymbol { propertySymbol ->
|
||||
propertySymbol.hasDeprecatedAnnotation(AnnotationUseSiteTarget.FIELD, strictUseSite = false)
|
||||
propertySymbol.hasDeprecatedAnnotation(AnnotationUseSiteTarget.FIELD, acceptAnnotationsWithoutUseSite = true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,12 +115,12 @@ internal class SymbolLightFieldForProperty private constructor(
|
||||
}
|
||||
|
||||
PsiModifier.VOLATILE -> withPropertySymbol { propertySymbol ->
|
||||
val hasAnnotation = propertySymbol.hasAnnotation(VOLATILE_ANNOTATION_CLASS_ID)
|
||||
val hasAnnotation = propertySymbol.hasAnnotation(VOLATILE_ANNOTATION_CLASS_ID, null)
|
||||
mapOf(modifier to hasAnnotation)
|
||||
}
|
||||
|
||||
PsiModifier.TRANSIENT -> withPropertySymbol { propertySymbol ->
|
||||
val hasAnnotation = propertySymbol.hasAnnotation(TRANSIENT_ANNOTATION_CLASS_ID)
|
||||
val hasAnnotation = propertySymbol.hasAnnotation(TRANSIENT_ANNOTATION_CLASS_ID, null)
|
||||
mapOf(modifier to hasAnnotation)
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -136,7 +136,7 @@ internal class SymbolLightAccessorMethod private constructor(
|
||||
accessorSite,
|
||||
this@SymbolLightAccessorMethod,
|
||||
containingClass,
|
||||
strictUseSite = false
|
||||
acceptAnnotationsWithoutUseSite = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -197,8 +197,8 @@ internal class SymbolLightAccessorMethod private constructor(
|
||||
private fun isStatic(): Boolean = analyzeForLightClasses(ktModule) {
|
||||
val propertySymbol = propertySymbol()
|
||||
propertySymbol.isStatic ||
|
||||
propertySymbol.hasJvmStaticAnnotation(accessorSite, strictUseSite = false) ||
|
||||
propertyAccessorSymbol().hasJvmStaticAnnotation(accessorSite, strictUseSite = false)
|
||||
propertySymbol.hasJvmStaticAnnotation(accessorSite, acceptAnnotationsWithoutUseSite = true) ||
|
||||
propertyAccessorSymbol().hasJvmStaticAnnotation(accessorSite, acceptAnnotationsWithoutUseSite = true)
|
||||
}
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
@@ -215,8 +215,8 @@ internal class SymbolLightAccessorMethod private constructor(
|
||||
|
||||
private val _isDeprecated: Boolean by lazyPub {
|
||||
analyzeForLightClasses(ktModule) {
|
||||
propertySymbol().hasDeprecatedAnnotation(accessorSite, strictUseSite = false) ||
|
||||
propertyAccessorSymbol().hasDeprecatedAnnotation(accessorSite, strictUseSite = false)
|
||||
propertySymbol().hasDeprecatedAnnotation(accessorSite, acceptAnnotationsWithoutUseSite = true) ||
|
||||
propertyAccessorSymbol().hasDeprecatedAnnotation(accessorSite, acceptAnnotationsWithoutUseSite = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user