New J2K: correctly handle vararg annotation parameter of external Java class
#KT-31726 fixed
This commit is contained in:
Vendored
+4
@@ -123,4 +123,8 @@ public class JavaClass {
|
||||
public int get(int p) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public @interface SpecialExternal {
|
||||
String[] names(); //array is used
|
||||
}
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.nj2k.conversions
|
||||
|
||||
import com.intellij.psi.PsiArrayType
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiMethod
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaArrayType
|
||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||
import org.jetbrains.kotlin.nj2k.primaryConstructor
|
||||
import org.jetbrains.kotlin.nj2k.toExpression
|
||||
@@ -41,7 +41,6 @@ class AnnotationConversion(private val context: NewJ2kConverterContext) : Recurs
|
||||
.map { JKAnnotationParameterImpl(it) }
|
||||
annotationParameter is JKAnnotationNameParameter
|
||||
&& annotation.isVarargsArgument(annotationParameter.name.value)
|
||||
&& annotation.classSymbol.target is JKClass
|
||||
&& annotationParameter.value !is JKKtAnnotationArrayInitializerExpression -> {
|
||||
listOf(
|
||||
JKAnnotationNameParameterImpl(
|
||||
@@ -68,7 +67,7 @@ class AnnotationConversion(private val context: NewJ2kConverterContext) : Recurs
|
||||
}
|
||||
|
||||
private fun PsiMethod.isVarArgsAnnotationMethod(isNamedArgument: Boolean) =
|
||||
isVarArgs || returnType is JavaArrayType || name == "value" && !isNamedArgument
|
||||
isVarArgs || returnType is PsiArrayType || name == "value" && !isNamedArgument
|
||||
|
||||
private fun JKParameter.isVarArgsAnnotationParameter(isNamedArgument: Boolean) =
|
||||
isVarArgs || type.type.isArrayType() || name.value == "value" && !isNamedArgument
|
||||
|
||||
+6
-1
@@ -1,7 +1,12 @@
|
||||
import javaApi.SpecialExternal;
|
||||
|
||||
//Annotation class:
|
||||
public @interface Special {
|
||||
String[] names(); //array is used
|
||||
}
|
||||
//Class with annotation:
|
||||
@Special(names = "name1")
|
||||
public class JClass {}
|
||||
public class JClass {}
|
||||
|
||||
@SpecialExternal(names = "name1")
|
||||
public class JClass2 {}
|
||||
|
||||
+6
-1
@@ -1,6 +1,11 @@
|
||||
import javaApi.SpecialExternal
|
||||
|
||||
//Annotation class:
|
||||
annotation class Special(val names: Array<String> //array is used
|
||||
) //Class with annotation:
|
||||
|
||||
@Special(names = ["name1"])
|
||||
class JClass
|
||||
class JClass
|
||||
|
||||
@SpecialExternal(names = ["name1"])
|
||||
class JClass2
|
||||
Reference in New Issue
Block a user