Move property to constructor: minor refactoring

Related to KT-26015
This commit is contained in:
Mikhail Glukhikh
2018-09-06 16:32:16 +03:00
parent de6fdc5733
commit 8a5dbe1c6b
@@ -129,16 +129,19 @@ class MovePropertyToConstructorIntention :
private fun KtAnnotationEntry.getTextWithUseSite(context: BindingContext): String {
if (useSiteTarget != null) return text
val typeReference = this.typeReference?.text ?: return text
val valueArgumentList = valueArgumentList?.text.orEmpty()
fun AnnotationUseSiteTarget.textWithMe() = "@$renderName:$typeReference$valueArgumentList"
val descriptor = context[BindingContext.ANNOTATION, this] ?: return text
val applicableTargets = AnnotationChecker.applicableTargetSet(descriptor)
val valueArgumentList = valueArgumentList?.text.orEmpty()
return when {
KotlinTarget.VALUE_PARAMETER !in applicableTargets ->
text
KotlinTarget.PROPERTY in applicableTargets ->
"@${AnnotationUseSiteTarget.PROPERTY.renderName}:$typeReference$valueArgumentList"
AnnotationUseSiteTarget.PROPERTY.textWithMe()
KotlinTarget.FIELD in applicableTargets ->
"@${AnnotationUseSiteTarget.FIELD.renderName}:$typeReference$valueArgumentList"
AnnotationUseSiteTarget.FIELD.textWithMe()
else ->
text
}