KT-22167 "Add annotation target" quick fix does nothing and disappears from menu
This commit is contained in:
committed by
asedunov
parent
6fbf5a8904
commit
677b05cc8c
@@ -85,7 +85,9 @@ private fun KtAnnotationEntry.getRequiredAnnotationTargets(annotationClass: KtCl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun KtAnnotationEntry.getActualTargetList(): List<KotlinTarget> {
|
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())
|
return AnnotationChecker.getDeclarationSiteActualTargetList(annotatedElement, null, BindingTraceContext())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +103,7 @@ private fun KtClass.addAnnotationTargets(annotationTargets: List<KotlinTarget>,
|
|||||||
if (valueArgumentList == null) {
|
if (valueArgumentList == null) {
|
||||||
val text = annotationTargets.toArgumentListString()
|
val text = annotationTargets.toArgumentListString()
|
||||||
targetAnnotationEntry.add(psiFactory.createCallArguments(text))
|
targetAnnotationEntry.add(psiFactory.createCallArguments(text))
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
val arguments = targetAnnotationEntry.valueArguments.mapNotNull { it.getArgumentExpression()?.text }
|
val arguments = targetAnnotationEntry.valueArguments.mapNotNull { it.getArgumentExpression()?.text }
|
||||||
for (target in annotationTargets) {
|
for (target in annotationTargets) {
|
||||||
val text = target.asNameString()
|
val text = target.asNameString()
|
||||||
@@ -111,8 +112,6 @@ private fun KtClass.addAnnotationTargets(annotationTargets: List<KotlinTarget>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<KotlinTarget>.toArgumentListString() =
|
private fun List<KotlinTarget>.toArgumentListString() = joinToString(separator = ", ", prefix = "(", postfix = ")") { it.asNameString() }
|
||||||
joinToString(separator = ", ", prefix = "(", postfix = ")") { it.asNameString() }
|
|
||||||
|
|
||||||
private fun KotlinTarget.asNameString() =
|
private fun KotlinTarget.asNameString() = "${KotlinBuiltIns.FQ_NAMES.annotationTarget.shortName().asString()}.$name"
|
||||||
"${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);
|
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")
|
@TestMetadata("fromLib.kt")
|
||||||
public void testFromLib() throws Exception {
|
public void testFromLib() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addAnnotationTarget/fromLib.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addAnnotationTarget/fromLib.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user