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;
}
Aggregations