182: KotlinElementActionsFactory: "value"-parameters in generated java-annotations is putted without explicit parameter name #KT-23644
This commit is contained in:
+10
-3
@@ -436,13 +436,20 @@ class KotlinElementActionsFactory : JvmElementActionsFactory() {
|
|||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
|
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
|
||||||
val target = pointer.element ?: return
|
val target = pointer.element ?: return
|
||||||
|
val kotlinAnnotation = JavaPsiFacade.getInstance(project).findClass(
|
||||||
|
request.qualifiedName,
|
||||||
|
target.resolveScope
|
||||||
|
)?.language == KotlinLanguage.INSTANCE
|
||||||
val entry = target.addAnnotationEntry(
|
val entry = target.addAnnotationEntry(
|
||||||
KtPsiFactory(target)
|
KtPsiFactory(target)
|
||||||
.createAnnotationEntry(
|
.createAnnotationEntry(
|
||||||
"@${request.qualifiedName}${
|
"@${request.qualifiedName}${
|
||||||
request.attributes.joinToString(", ", "(", ")") { p ->
|
request.attributes.mapIndexed { i, p ->
|
||||||
"${p.name} = ${renderAttributeValue(p.value)}"
|
if (!kotlinAnnotation && i == 0 && p.name == "value")
|
||||||
}
|
renderAttributeValue(p.value).toString()
|
||||||
|
else
|
||||||
|
"${p.name} = ${renderAttributeValue(p.value)}"
|
||||||
|
}.joinToString(", ", "(", ")")
|
||||||
}"
|
}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -204,6 +204,50 @@ class CommonIntentionActionsTest : LightPlatformCodeInsightFixtureTestCase() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testAddJavaAnnotationValue() {
|
||||||
|
|
||||||
|
myFixture.addFileToProject(
|
||||||
|
"pkg/myannotation/JavaAnnotation.java", """
|
||||||
|
package pkg.myannotation
|
||||||
|
|
||||||
|
public @interface JavaAnnotation {
|
||||||
|
String value();
|
||||||
|
int param() default 0;
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
myFixture.configureByText(
|
||||||
|
"foo.kt", """class Foo {
|
||||||
|
| fun bar(){}
|
||||||
|
| fun baz(){}
|
||||||
|
|}""".trim().trimMargin()
|
||||||
|
)
|
||||||
|
|
||||||
|
myFixture.launchAction(
|
||||||
|
createAddAnnotationActions(
|
||||||
|
myFixture.findElementByText("bar", KtModifierListOwner::class.java).toLightElements().single() as PsiMethod,
|
||||||
|
annotationRequest("pkg.myannotation.JavaAnnotation", stringAttribute("value", "foo"), intAttribute("param", 2))
|
||||||
|
).single()
|
||||||
|
)
|
||||||
|
myFixture.launchAction(
|
||||||
|
createAddAnnotationActions(
|
||||||
|
myFixture.findElementByText("baz", KtModifierListOwner::class.java).toLightElements().single() as PsiMethod,
|
||||||
|
annotationRequest("pkg.myannotation.JavaAnnotation", intAttribute("param", 2), stringAttribute("value", "foo"))
|
||||||
|
).single()
|
||||||
|
)
|
||||||
|
myFixture.checkResult(
|
||||||
|
"""import pkg.myannotation.JavaAnnotation
|
||||||
|
|
|
||||||
|
|class Foo {
|
||||||
|
| @JavaAnnotation("foo", param = 2)
|
||||||
|
| fun bar(){}
|
||||||
|
| @JavaAnnotation(param = 2, value = "foo")
|
||||||
|
| fun baz(){}
|
||||||
|
|}""".trim().trimMargin(), true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun testDontMakePublicPublic() {
|
fun testDontMakePublicPublic() {
|
||||||
myFixture.configureByText(
|
myFixture.configureByText(
|
||||||
"foo.kt", """class Foo {
|
"foo.kt", """class Foo {
|
||||||
|
|||||||
Reference in New Issue
Block a user