Search in sources :

Example 1 with ClassDescriptorImpl

use of org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl in project kotlin by JetBrains.

the class SamWrapperCodegen method genWrapper.

@NotNull
public Type genWrapper(@NotNull KtFile file) {
    // Name for generated class, in form of whatever$1
    FqName fqName = getWrapperName(file);
    Type asmType = asmTypeByFqNameWithoutInnerClasses(fqName);
    // e.g. (T, T) -> Int
    KotlinType functionType = samType.getKotlinFunctionType();
    ClassDescriptor classDescriptor = new ClassDescriptorImpl(samType.getJavaClassDescriptor().getContainingDeclaration(), fqName.shortName(), Modality.FINAL, ClassKind.CLASS, Collections.singleton(samType.getType()), SourceElement.NO_SOURCE, /* isExternal = */
    false);
    // e.g. compare(T, T)
    SimpleFunctionDescriptor erasedInterfaceFunction = samType.getAbstractMethod().getOriginal().copy(classDescriptor, Modality.FINAL, Visibilities.PUBLIC, CallableMemberDescriptor.Kind.SYNTHESIZED, /*copyOverrides=*/
    false);
    ClassBuilder cv = state.getFactory().newVisitor(JvmDeclarationOriginKt.OtherOrigin(erasedInterfaceFunction), asmType, file);
    cv.defineClass(file, state.getClassFileVersion(), ACC_FINAL | ACC_SUPER | visibility, asmType.getInternalName(), null, OBJECT_TYPE.getInternalName(), new String[] { typeMapper.mapType(samType.getType()).getInternalName() });
    cv.visitSource(file.getName(), null);
    WriteAnnotationUtilKt.writeSyntheticClassMetadata(cv, state);
    // e.g. ASM type for Function2
    Type functionAsmType = typeMapper.mapType(functionType);
    cv.newField(JvmDeclarationOriginKt.OtherOrigin(erasedInterfaceFunction), ACC_SYNTHETIC | ACC_PRIVATE | ACC_FINAL, FUNCTION_FIELD_NAME, functionAsmType.getDescriptor(), null, null);
    generateConstructor(asmType, functionAsmType, cv);
    generateMethod(asmType, functionAsmType, cv, erasedInterfaceFunction, functionType);
    cv.done();
    return asmType;
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) Type(org.jetbrains.org.objectweb.asm.Type) JavaClassDescriptor(org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor) FqName(org.jetbrains.kotlin.name.FqName) KotlinType(org.jetbrains.kotlin.types.KotlinType) ClassDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 ClassDescriptorImpl (org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl)1 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)1 FqName (org.jetbrains.kotlin.name.FqName)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 Type (org.jetbrains.org.objectweb.asm.Type)1