Add ModuleDescriptor to AnnotationCodegen
This commit is contained in:
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
@@ -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<ValueParameterDescriptor> iterator = valueParameters.iterator();
|
||||
List<JvmMethodParameterSignature> 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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -260,7 +260,7 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
int flags = ACC_DEPRECATED | ACC_STATIC | ACC_SYNTHETIC | AsmUtil.getVisibilityAccessFlag(descriptor);
|
||||
MethodVisitor mv = v.newMethod(JvmDeclarationOriginKt.OtherOrigin(descriptor), flags, syntheticMethod.getName(),
|
||||
syntheticMethod.getDescriptor(), null, null);
|
||||
AnnotationCodegen.forMethod(mv, this, typeMapper).genAnnotations(new AnnotatedImpl(annotations), Type.VOID_TYPE);
|
||||
AnnotationCodegen.forMethod(mv, this, state).genAnnotations(new AnnotatedImpl(annotations), Type.VOID_TYPE);
|
||||
mv.visitCode();
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
mv.visitEnd();
|
||||
|
||||
@@ -85,7 +85,7 @@ public class PackagePartCodegen extends MemberCodegen<KtFile> {
|
||||
}
|
||||
}
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
+2
-3
@@ -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 {
|
||||
|
||||
}
|
||||
|
||||
+2
-4
@@ -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!!)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user