diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java index 54a0d2735d8..d77fa2180d4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AnnotationCodegen.java @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen; import kotlin.collections.CollectionsKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; import org.jetbrains.kotlin.config.JvmTarget; import org.jetbrains.kotlin.descriptors.*; @@ -85,10 +86,12 @@ public abstract class AnnotationCodegen { private final InnerClassConsumer innerClassConsumer; private final KotlinTypeMapper typeMapper; + private final ModuleDescriptor module; - private AnnotationCodegen(@NotNull InnerClassConsumer innerClassConsumer, @NotNull KotlinTypeMapper typeMapper) { + private AnnotationCodegen(@NotNull InnerClassConsumer innerClassConsumer, @NotNull GenerationState state) { this.innerClassConsumer = innerClassConsumer; - this.typeMapper = typeMapper; + this.typeMapper = state.getTypeMapper(); + this.module = state.getModule(); } /** @@ -547,9 +550,9 @@ public abstract class AnnotationCodegen { public static AnnotationCodegen forClass( @NotNull ClassVisitor cv, @NotNull InnerClassConsumer innerClassConsumer, - @NotNull KotlinTypeMapper mapper + @NotNull GenerationState state ) { - return new AnnotationCodegen(innerClassConsumer, mapper) { + return new AnnotationCodegen(innerClassConsumer, state) { @NotNull @Override AnnotationVisitor visitAnnotation(String descr, boolean visible) { @@ -561,9 +564,9 @@ public abstract class AnnotationCodegen { public static AnnotationCodegen forMethod( @NotNull MethodVisitor mv, @NotNull InnerClassConsumer innerClassConsumer, - @NotNull KotlinTypeMapper mapper + @NotNull GenerationState state ) { - return new AnnotationCodegen(innerClassConsumer, mapper) { + return new AnnotationCodegen(innerClassConsumer, state) { @NotNull @Override AnnotationVisitor visitAnnotation(String descr, boolean visible) { @@ -575,9 +578,9 @@ public abstract class AnnotationCodegen { public static AnnotationCodegen forField( @NotNull FieldVisitor fv, @NotNull InnerClassConsumer innerClassConsumer, - @NotNull KotlinTypeMapper mapper + @NotNull GenerationState state ) { - return new AnnotationCodegen(innerClassConsumer, mapper) { + return new AnnotationCodegen(innerClassConsumer, state) { @NotNull @Override AnnotationVisitor visitAnnotation(String descr, boolean visible) { @@ -590,9 +593,9 @@ public abstract class AnnotationCodegen { int parameter, @NotNull MethodVisitor mv, @NotNull InnerClassConsumer innerClassConsumer, - @NotNull KotlinTypeMapper mapper + @NotNull GenerationState state ) { - return new AnnotationCodegen(innerClassConsumer, mapper) { + return new AnnotationCodegen(innerClassConsumer, state) { @NotNull @Override AnnotationVisitor visitAnnotation(String descr, boolean visible) { @@ -604,9 +607,9 @@ public abstract class AnnotationCodegen { public static AnnotationCodegen forAnnotationDefaultValue( @NotNull MethodVisitor mv, @NotNull InnerClassConsumer innerClassConsumer, - @NotNull KotlinTypeMapper mapper + @NotNull GenerationState state ) { - return new AnnotationCodegen(innerClassConsumer, mapper) { + return new AnnotationCodegen(innerClassConsumer, state) { @NotNull @Override AnnotationVisitor visitAnnotation(String descr, boolean visible) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt index f0bf9787d80..ca41298996c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt @@ -140,7 +140,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) { FunctionCodegen.getThrownExceptions(functionDescriptor, typeMapper) ) - AnnotationCodegen.forMethod(mv, memberCodegen, typeMapper).genAnnotations(functionDescriptor, signature.returnType) + AnnotationCodegen.forMethod(mv, memberCodegen, state).genAnnotations(functionDescriptor, signature.returnType) if (state.classBuilderMode == ClassBuilderMode.KAPT3) { mv.visitAnnotation(ANNOTATION_TYPE_DESCRIPTOR_FOR_JVM_OVERLOADS_GENERATED_METHODS, false) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 399f7f26c92..edf66c91138 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -307,7 +307,7 @@ public class FunctionCodegen { annotationsOwner = functionDescriptor; } - AnnotationCodegen.forMethod(mv, memberCodegen, typeMapper).genAnnotations(annotationsOwner, asmMethod.getReturnType()); + AnnotationCodegen.forMethod(mv, memberCodegen, state).genAnnotations(annotationsOwner, asmMethod.getReturnType()); generateParameterAnnotations(annotationsOwner, mv, jvmSignature, memberCodegen, state); } @@ -514,7 +514,7 @@ public class FunctionCodegen { @NotNull GenerationState state ) { if (isAccessor(functionDescriptor)) return; - KotlinTypeMapper typeMapper = state.getTypeMapper(); + Iterator iterator = valueParameters.iterator(); List kotlinParameterTypes = jvmSignature.getValueParameters(); @@ -526,7 +526,6 @@ public class FunctionCodegen { continue; } - AnnotationCodegen annotationCodegen = AnnotationCodegen.forParameter(i, mv, innerClassConsumer, typeMapper); Annotated annotated = kind == JvmMethodParameterKind.VALUE ? iterator.next() @@ -535,7 +534,7 @@ public class FunctionCodegen { : null; if (annotated != null) { - annotationCodegen.genAnnotations(annotated, parameterSignature.getAsmType()); + AnnotationCodegen.forParameter(i, mv, innerClassConsumer, state).genAnnotations(annotated, parameterSignature.getAsmType()); } } } @@ -1187,7 +1186,7 @@ public class FunctionCodegen { // Only method annotations are copied to the $default method. Parameter annotations are not copied until there are valid use cases; // enum constructors have two additional synthetic parameters which somewhat complicate this task - AnnotationCodegen.forMethod(mv, memberCodegen, typeMapper).genAnnotations(functionDescriptor, defaultMethod.getReturnType()); + AnnotationCodegen.forMethod(mv, memberCodegen, state).genAnnotations(functionDescriptor, defaultMethod.getReturnType()); if (!state.getClassBuilderMode().generateBodies) { if (this.owner instanceof MultifileClassFacadeContext) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 955949d4596..92539538919 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -228,7 +228,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { writeEnclosingMethod(); - AnnotationCodegen.forClass(v.getVisitor(), this, typeMapper).genAnnotations(descriptor, null); + AnnotationCodegen.forClass(v.getVisitor(), this, state).genAnnotations(descriptor, null); generateEnumEntries(); } @@ -817,7 +817,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { FieldVisitor fv = v.newField(JvmDeclarationOriginKt.OtherOrigin(companionObject == null ? myClass.getPsiOrParent() : companionObject), fieldAccessFlags, field.name, field.type.getDescriptor(), null, null); if (fieldShouldBeDeprecated) { - AnnotationCodegen.forField(fv, this, typeMapper).visitAnnotation("Ljava/lang/Deprecated;", true).visitEnd(); + AnnotationCodegen.forField(fv, this, state).visitAnnotation("Ljava/lang/Deprecated;", true).visitEnd(); } } @@ -902,7 +902,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { type.getDescriptor(), typeMapper.mapFieldSignature(property.getType(), property), info.defaultValue); - AnnotationCodegen.forField(fv, this, typeMapper).genAnnotations(property, type); + AnnotationCodegen.forField(fv, this, state).genAnnotations(property, type); //This field are always static and final so if it has constant initializer don't do anything in clinit, //field would be initialized via default value in v.newField(...) - see JVM SPEC Ch.4 @@ -1063,7 +1063,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { int isDeprecated = KotlinBuiltIns.isDeprecated(descriptor) ? ACC_DEPRECATED : 0; FieldVisitor fv = v.newField(JvmDeclarationOriginKt.OtherOrigin(enumEntry, descriptor), ACC_PUBLIC | ACC_ENUM | ACC_STATIC | ACC_FINAL | isDeprecated, descriptor.getName().asString(), classAsmType.getDescriptor(), null, null); - AnnotationCodegen.forField(fv, this, typeMapper).genAnnotations(descriptor, null); + AnnotationCodegen.forField(fv, this, state).genAnnotations(descriptor, null); } initializeEnumConstants(enumEntries); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index d1bf8a14231..6ac3c6d300b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -260,7 +260,7 @@ public abstract class MemberCodegen { } } Annotated annotatedFile = new AnnotatedImpl(Annotations.Companion.create(fileAnnotationDescriptors)); - AnnotationCodegen.forClass(v.getVisitor(), this, state.getTypeMapper()).genAnnotations(annotatedFile, null); + AnnotationCodegen.forClass(v.getVisitor(), this, state).genAnnotations(annotatedFile, null); } @Override diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index be2f35dfee0..d358409b3be 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -272,7 +272,7 @@ public class PropertyCodegen { PropertyGetterDescriptor getter = descriptor.getGetter(); assert getter != null : "Annotation property should have a getter: " + descriptor; v.getSerializationBindings().put(METHOD_FOR_FUNCTION, getter, asmMethod); - AnnotationCodegen.forMethod(mv, memberCodegen, typeMapper).genAnnotations(getter, asmMethod.getReturnType()); + AnnotationCodegen.forMethod(mv, memberCodegen, state).genAnnotations(getter, asmMethod.getReturnType()); KtExpression defaultValue = loadAnnotationArgumentDefaultValue(parameter, descriptor, expectedAnnotationConstructor); if (defaultValue != null) { @@ -281,7 +281,7 @@ public class PropertyCodegen { assert !state.getClassBuilderMode().generateBodies || constant != null : "Default value for annotation parameter should be compile time value: " + defaultValue.getText(); if (constant != null) { - AnnotationCodegen annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(mv, memberCodegen, typeMapper); + AnnotationCodegen annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(mv, memberCodegen, state); annotationCodegen.generateAnnotationDefaultValue(constant, descriptor.getType()); } } @@ -432,7 +432,7 @@ public class PropertyCodegen { ); if (annotatedField != null) { - AnnotationCodegen.forField(fv, memberCodegen, typeMapper).genAnnotations(annotatedField, type); + AnnotationCodegen.forField(fv, memberCodegen, state).genAnnotations(annotatedField, type); } } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt index 5e7d2a70615..bb17a2c6645 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt @@ -49,7 +49,7 @@ class ScriptCodegen private constructor( typeMapper.mapSupertype(scriptDescriptor.getSuperClassOrAny().defaultType, null).internalName, mapSupertypesNames(typeMapper, scriptDescriptor.getSuperInterfaces(), null) ) - AnnotationCodegen.forClass(v.visitor, this, typeMapper).genAnnotations(scriptDescriptor, null) + AnnotationCodegen.forClass(v.visitor, this, state).genAnnotations(scriptDescriptor, null) } override fun generateBody() { @@ -99,9 +99,7 @@ class ScriptCodegen private constructor( OtherOrigin(scriptDeclaration, scriptDescriptor.unsubstitutedPrimaryConstructor), ACC_PUBLIC, jvmSignature.asmMethod.name, jvmSignature.asmMethod.descriptor, null, null) - AnnotationCodegen.forMethod(mv, this, typeMapper).genAnnotations( - scriptDescriptor.unsubstitutedPrimaryConstructor, asmMethod.returnType - ) + AnnotationCodegen.forMethod(mv, this, state).genAnnotations(scriptDescriptor.unsubstitutedPrimaryConstructor, asmMethod.returnType) if (state.classBuilderMode.generateBodies) { mv.visitCode() diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt index 24963f461a0..4e0c9599e45 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt @@ -36,7 +36,6 @@ import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.org.objectweb.asm.Opcodes import org.jetbrains.org.objectweb.asm.Type -import java.lang.RuntimeException open class ClassCodegen protected constructor( internal val irClass: IrClass, @@ -84,7 +83,7 @@ open class ClassCodegen protected constructor( signature.superclassName, signature.interfaces.toTypedArray() ) - AnnotationCodegen.forClass(visitor.visitor, this, typeMapper).genAnnotations(descriptor, null) + AnnotationCodegen.forClass(visitor.visitor, this, state).genAnnotations(descriptor, null) visitor.visitSource(irClass.symbol.descriptor.source.containingFile.name!!, null) irClass.declarations.forEach { @@ -159,7 +158,7 @@ open class ClassCodegen protected constructor( ) if (field.origin == IrDeclarationOrigin.FIELD_FOR_ENUM_ENTRY) { - AnnotationCodegen.forField(fv, this, typeMapper).genAnnotations(field.descriptor, null) + AnnotationCodegen.forField(fv, this, state).genAnnotations(field.descriptor, null) } else { } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index ab658ecc3ed..e54df92e947 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -48,9 +48,7 @@ open class FunctionCodegen(private val irFunction: IrFunction, private val class val flags = calculateMethodFlags(irFunction.isStatic) val methodVisitor = createMethod(flags, signature) - AnnotationCodegen.forMethod(methodVisitor, classCodegen, state.typeMapper).genAnnotations( - descriptor, signature.asmMethod.returnType - ) + AnnotationCodegen.forMethod(methodVisitor, classCodegen, state).genAnnotations(descriptor, signature.asmMethod.returnType) FunctionCodegen.generateParameterAnnotations(descriptor, methodVisitor, signature, classCodegen, state) if (!state.classBuilderMode.generateBodies || flags.and(Opcodes.ACC_ABSTRACT) != 0 || irFunction.isExternal) { @@ -113,7 +111,7 @@ open class FunctionCodegen(private val irFunction: IrFunction, private val class ) assert(!state.classBuilderMode.generateBodies || constant != null) { "Default value for annotation parameter should be compile time value: " + defaultValue.text } if (constant != null) { - val annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(methodVisitor, classCodegen, state.typeMapper) + val annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(methodVisitor, classCodegen, state) annotationCodegen.generateAnnotationDefaultValue(constant, descriptor.returnType!!) } }