Use AnnotationDescriptor.fqName instead of type

Also use the annotationClass extension property instead of
TypeUtils.getClassDescriptor(annotation.type)
This commit is contained in:
Alexander Udalov
2017-07-04 18:38:36 +03:00
parent 541b9dab52
commit def3f73fdd
16 changed files with 48 additions and 100 deletions
@@ -53,7 +53,7 @@ class KotlinSuppressIntentionAction private constructor(
val id = "\"$suppressKey\""
when (suppressAt) {
is KtModifierListOwner ->
suppressAt.addAnnotation(KotlinBuiltIns.FQ_NAMES.suppress.toSafe(),
suppressAt.addAnnotation(KotlinBuiltIns.FQ_NAMES.suppress,
id,
whiteSpaceText = if (kind.newLineNeeded) "\n" else " ",
addToExistingAnnotation = { entry ->
@@ -151,13 +151,9 @@ class KotlinSuppressIntentionAction private constructor(
}
private fun findSuppressAnnotation(context: BindingContext, annotationEntries: List<KtAnnotationEntry>): KtAnnotationEntry? {
for (entry in annotationEntries) {
val annotationDescriptor = context.get(BindingContext.ANNOTATION, entry)
if (annotationDescriptor != null && KotlinBuiltIns.isSuppressAnnotation(annotationDescriptor)) {
return entry
}
return annotationEntries.firstOrNull { entry ->
context.get(BindingContext.ANNOTATION, entry)?.fqName == KotlinBuiltIns.FQ_NAMES.suppress
}
return null
}
}
@@ -18,13 +18,11 @@ package org.jetbrains.kotlin.idea.util
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
fun KtModifierListOwner.addAnnotation(
annotationFqName: FqName,
annotationInnerText: String? = null,
@@ -75,16 +73,5 @@ fun KtAnnotated.findAnnotation(annotationFqName: FqName): KtAnnotationEntry? {
val context = analyze(bodyResolveMode = BodyResolveMode.PARTIAL)
for (entry in annotationEntries) {
val annotationDescriptor = context.get(BindingContext.ANNOTATION, entry)
if (annotationDescriptor != null) {
val fqName = annotationDescriptor.type.getJetTypeFqName(false)
if (fqName == annotationFqName.asString()) {
return entry
}
}
}
return null
return annotationEntries.firstOrNull { entry -> context.get(BindingContext.ANNOTATION, entry)?.fqName == annotationFqName }
}
@@ -118,10 +118,9 @@ class KtParameterPattern : PsiElementPattern<KtParameter, KtParameterPattern>(Kt
return withPatternCondition("KtParameterPattern-withAnnotation") { ktParameter, _ ->
if (ktParameter.annotationEntries.isEmpty()) return@withPatternCondition false
val parameterDescriptor = ktParameter.resolveToDescriptorIfAny() as? ValueParameterDescriptor ?: return@withPatternCondition false
parameterDescriptor.annotations.any { annotation ->
DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(annotation.type) == fqName
val parameterDescriptor = ktParameter.resolveToDescriptorIfAny()
parameterDescriptor is ValueParameterDescriptor && parameterDescriptor.annotations.any { annotation ->
annotation.fqName?.asString() == fqName
}
}
}
@@ -204,7 +204,7 @@ class MigrateExternalExtensionFix(declaration: KtNamedDeclaration)
}
if (declaration is KtFunction) {
declaration.addAnnotation(KotlinBuiltIns.FQ_NAMES.suppress.toSafe(), "\"NOTHING_TO_INLINE\"")
declaration.addAnnotation(KotlinBuiltIns.FQ_NAMES.suppress, "\"NOTHING_TO_INLINE\"")
}
convertNativeAnnotationToJsName(declaration, annotations)