Exemplo n.º 1
0
  @Override
  protected void generateBody() {
    FunctionDescriptor erasedInterfaceFunction;
    if (samType == null) {
      erasedInterfaceFunction = getErasedInvokeFunction(funDescriptor);
    } else {
      erasedInterfaceFunction = samType.getAbstractMethod().getOriginal();
    }

    generateBridge(
        typeMapper.mapSignature(erasedInterfaceFunction).getAsmMethod(),
        typeMapper.mapSignature(funDescriptor).getAsmMethod());

    functionCodegen.generateMethod(OtherOrigin(element, funDescriptor), funDescriptor, strategy);

    // TODO: rewrite cause ugly hack
    if (samType != null) {
      SimpleFunctionDescriptorImpl descriptorForBridges =
          SimpleFunctionDescriptorImpl.create(
              funDescriptor.getContainingDeclaration(),
              funDescriptor.getAnnotations(),
              erasedInterfaceFunction.getName(),
              CallableMemberDescriptor.Kind.DECLARATION,
              funDescriptor.getSource());

      descriptorForBridges.initialize(
          null,
          erasedInterfaceFunction.getDispatchReceiverParameter(),
          erasedInterfaceFunction.getTypeParameters(),
          erasedInterfaceFunction.getValueParameters(),
          erasedInterfaceFunction.getReturnType(),
          Modality.OPEN,
          erasedInterfaceFunction.getVisibility());

      descriptorForBridges.addOverriddenDescriptor(erasedInterfaceFunction);
      functionCodegen.generateBridges(descriptorForBridges);
    }

    this.constructor = generateConstructor(superClassAsmType);

    if (isConst(closure)) {
      generateConstInstance();
    }

    genClosureFields(closure, v, typeMapper);

    functionCodegen.generateDefaultIfNeeded(
        context.intoFunction(funDescriptor),
        funDescriptor,
        context.getContextKind(),
        DefaultParameterValueLoader.DEFAULT,
        null);
  }