Correctly rearrange arguments for annotation constructors copied from another module
It won't fix KT-48181 completely, but it will allow to create such annotations if all value arguments are specified. For the full fix, we need to read default annotation values from classfiles in jar. #KT-48181 In progress
This commit is contained in:
+6
@@ -455,6 +455,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/annotations/instances/javaAnnotation.kt");
|
runTest("compiler/testData/codegen/box/annotations/instances/javaAnnotation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kotlinExistingAnnotation.kt")
|
||||||
|
public void testKotlinExistingAnnotation() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/instances/kotlinExistingAnnotation.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("multifileEqHc.kt")
|
@TestMetadata("multifileEqHc.kt")
|
||||||
public void testMultifileEqHc() throws Exception {
|
public void testMultifileEqHc() throws Exception {
|
||||||
|
|||||||
+18
-2
@@ -12,7 +12,8 @@ import org.jetbrains.kotlin.backend.common.ir.addFakeOverrides
|
|||||||
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
|
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
import org.jetbrains.kotlin.ir.builders.declarations.addConstructor
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildClass
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
@@ -56,13 +57,28 @@ abstract class AnnotationImplementationTransformer(val context: BackendContext,
|
|||||||
implClass.defaultType,
|
implClass.defaultType,
|
||||||
ctor.symbol,
|
ctor.symbol,
|
||||||
)
|
)
|
||||||
newCall.copyTypeAndValueArgumentsFrom(expression)
|
moveValueArgumentsUsingNames(expression, newCall)
|
||||||
newCall.transformChildrenVoid() // for annotations in annotations
|
newCall.transformChildrenVoid() // for annotations in annotations
|
||||||
return newCall
|
return newCall
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun IrClass.platformSetup() {}
|
open fun IrClass.platformSetup() {}
|
||||||
|
|
||||||
|
private fun moveValueArgumentsUsingNames(source: IrConstructorCall, destination: IrConstructorCall) {
|
||||||
|
val argumentsByName = source.getArgumentsWithIr().associateBy(
|
||||||
|
{ (param, _) -> param.name },
|
||||||
|
{ (_, value) -> value }
|
||||||
|
)
|
||||||
|
|
||||||
|
destination.symbol.owner.valueParameters.forEachIndexed { index, parameter ->
|
||||||
|
val valueArg = argumentsByName[parameter.name]
|
||||||
|
if (parameter.defaultValue == null && valueArg == null)
|
||||||
|
error("Usage of default value argument for this annotation is not yet possible.\n" +
|
||||||
|
"Please specify value for '${source.type.classOrNull?.owner?.name}.${parameter.name}' explicitly")
|
||||||
|
destination.putValueArgument(index, valueArg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createAnnotationImplementation(annotationClass: IrClass): IrClass {
|
private fun createAnnotationImplementation(annotationClass: IrClass): IrClass {
|
||||||
val localDeclarationParent = currentClass?.scope?.getLocalDeclarationParent() as? IrClass
|
val localDeclarationParent = currentClass?.scope?.getLocalDeclarationParent() as? IrClass
|
||||||
val parentFqName = annotationClass.fqNameWhenAvailable!!.asString().replace('.', '_')
|
val parentFqName = annotationClass.fqNameWhenAvailable!!.asString().replace('.', '_')
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
// TARGET_BACKEND: JVM_IR
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// !LANGUAGE: +InstantiationOfAnnotationClasses
|
||||||
|
|
||||||
|
fun f(): Metadata = Metadata(
|
||||||
|
kind = 0,
|
||||||
|
metadataVersion = intArrayOf(),
|
||||||
|
data1 = arrayOf(),
|
||||||
|
data2 = arrayOf(),
|
||||||
|
extraString = "",
|
||||||
|
packageName = "foo",
|
||||||
|
extraInt = 0,
|
||||||
|
bytecodeVersion = intArrayOf(1, 0, 3),
|
||||||
|
)
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val m = f()
|
||||||
|
if (m.toString() == """@kotlin.Metadata(bytecodeVersion=[1, 0, 3], data1=[], data2=[], extraInt=0, extraString=, kind=0, metadataVersion=[], packageName=foo)""")
|
||||||
|
return "OK"
|
||||||
|
return m.toString()
|
||||||
|
}
|
||||||
+6
@@ -455,6 +455,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/annotations/instances/javaAnnotation.kt");
|
runTest("compiler/testData/codegen/box/annotations/instances/javaAnnotation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kotlinExistingAnnotation.kt")
|
||||||
|
public void testKotlinExistingAnnotation() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/instances/kotlinExistingAnnotation.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("multifileEqHc.kt")
|
@TestMetadata("multifileEqHc.kt")
|
||||||
public void testMultifileEqHc() throws Exception {
|
public void testMultifileEqHc() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user