KT-22167 "Add annotation target" quick fix does nothing and disappears from menu

This commit is contained in:
Toshiaki Kameyama
2018-01-29 15:35:50 +09:00
committed by asedunov
parent 6fbf5a8904
commit 677b05cc8c
4 changed files with 27 additions and 7 deletions
@@ -85,7 +85,9 @@ private fun KtAnnotationEntry.getRequiredAnnotationTargets(annotationClass: KtCl
}
private fun KtAnnotationEntry.getActualTargetList(): List<KotlinTarget> {
val annotatedElement = getStrictParentOfType<KtModifierList>()?.owner as? KtElement ?: return emptyList()
val annotatedElement = getStrictParentOfType<KtModifierList>()?.owner as? KtElement
?: getStrictParentOfType<KtAnnotatedExpression>()?.baseExpression
?: return emptyList()
return AnnotationChecker.getDeclarationSiteActualTargetList(annotatedElement, null, BindingTraceContext())
}
@@ -101,8 +103,7 @@ private fun KtClass.addAnnotationTargets(annotationTargets: List<KotlinTarget>,
if (valueArgumentList == null) {
val text = annotationTargets.toArgumentListString()
targetAnnotationEntry.add(psiFactory.createCallArguments(text))
}
else {
} else {
val arguments = targetAnnotationEntry.valueArguments.mapNotNull { it.getArgumentExpression()?.text }
for (target in annotationTargets) {
val text = target.asNameString()
@@ -111,8 +112,6 @@ private fun KtClass.addAnnotationTargets(annotationTargets: List<KotlinTarget>,
}
}
private fun List<KotlinTarget>.toArgumentListString() =
joinToString(separator = ", ", prefix = "(", postfix = ")") { it.asNameString() }
private fun List<KotlinTarget>.toArgumentListString() = joinToString(separator = ", ", prefix = "(", postfix = ")") { it.asNameString() }
private fun KotlinTarget.asNameString() =
"${KotlinBuiltIns.FQ_NAMES.annotationTarget.shortName().asString()}.$name"
private fun KotlinTarget.asNameString() = "${KotlinBuiltIns.FQ_NAMES.annotationTarget.shortName().asString()}.$name"
@@ -0,0 +1,7 @@
// "Add annotation target" "true"
annotation class Foo
fun test() {
var v = 0
<caret>@Foo v++
}
@@ -0,0 +1,8 @@
// "Add annotation target" "true"
@Target(AnnotationTarget.EXPRESSION)
annotation class Foo
fun test() {
var v = 0
@Foo v++
}
@@ -258,6 +258,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("expression.kt")
public void testExpression() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addAnnotationTarget/expression.kt");
doTest(fileName);
}
@TestMetadata("fromLib.kt")
public void testFromLib() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addAnnotationTarget/fromLib.kt");