Exemplo n.º 1
0
  public void gen(@NotNull KtNamedFunction function) {
    SimpleFunctionDescriptor functionDescriptor =
        bindingContext.get(BindingContext.FUNCTION, function);
    assert functionDescriptor != null
        : "No descriptor for function "
            + function.getText()
            + "\n"
            + "in "
            + function.getContainingFile().getVirtualFile();

    if (owner.getContextKind() != OwnerKind.DEFAULT_IMPLS || function.hasBody()) {
      generateMethod(
          JvmDeclarationOriginKt.OtherOrigin(function, functionDescriptor),
          functionDescriptor,
          new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function));
    }

    generateDefaultIfNeeded(
        owner.intoFunction(functionDescriptor),
        functionDescriptor,
        owner.getContextKind(),
        DefaultParameterValueLoader.DEFAULT,
        function);

    generateOverloadsWithDefaultValues(function, functionDescriptor, functionDescriptor);
  }
Exemplo n.º 2
0
 public void generateOverloadsWithDefaultValues(
     @Nullable KtNamedFunction function,
     @NotNull FunctionDescriptor functionDescriptor,
     @NotNull FunctionDescriptor delegateFunctionDescriptor) {
   new DefaultParameterValueSubstitutor(state)
       .generateOverloadsIfNeeded(
           function, functionDescriptor, delegateFunctionDescriptor, owner.getContextKind(), v);
 }
Exemplo n.º 3
0
  public void generateBridges(@NotNull FunctionDescriptor descriptor) {
    if (descriptor instanceof ConstructorDescriptor) return;
    if (owner.getContextKind() == OwnerKind.DEFAULT_IMPLS) return;
    if (isInterface(descriptor.getContainingDeclaration())) return;

    // equals(Any?), hashCode(), toString() never need bridges
    if (isMethodOfAny(descriptor)) return;

    // If the function doesn't have a physical declaration among super-functions, it's a SAM adapter
    // or alike and doesn't need bridges
    if (CallResolverUtilKt.isOrOverridesSynthesized(descriptor)) return;

    boolean isSpecial =
        SpecialBuiltinMembers.getOverriddenBuiltinReflectingJvmDescriptor(descriptor) != null;

    Set<Bridge<Method>> bridgesToGenerate;
    if (!isSpecial) {
      bridgesToGenerate =
          ImplKt.generateBridgesForFunctionDescriptor(descriptor, getSignatureMapper(typeMapper));
      if (!bridgesToGenerate.isEmpty()) {
        PsiElement origin =
            descriptor.getKind() == DECLARATION ? getSourceFromDescriptor(descriptor) : null;
        boolean isSpecialBridge =
            BuiltinMethodsWithSpecialGenericSignature
                    .getOverriddenBuiltinFunctionWithErasedValueParametersInJava(descriptor)
                != null;

        for (Bridge<Method> bridge : bridgesToGenerate) {
          generateBridge(
              origin, descriptor, bridge.getFrom(), bridge.getTo(), isSpecialBridge, false);
        }
      }
    } else {
      Set<BridgeForBuiltinSpecial<Method>> specials =
          BuiltinSpecialBridgesUtil.generateBridgesForBuiltinSpecial(
              descriptor, getSignatureMapper(typeMapper));

      if (!specials.isEmpty()) {
        PsiElement origin =
            descriptor.getKind() == DECLARATION ? getSourceFromDescriptor(descriptor) : null;
        for (BridgeForBuiltinSpecial<Method> bridge : specials) {
          generateBridge(
              origin,
              descriptor,
              bridge.getFrom(),
              bridge.getTo(),
              bridge.isSpecial(),
              bridge.isDelegateToSuper());
        }
      }

      if (!descriptor.getKind().isReal()
          && isAbstractMethod(descriptor, OwnerKind.IMPLEMENTATION)) {
        CallableDescriptor overridden =
            SpecialBuiltinMembers.getOverriddenBuiltinReflectingJvmDescriptor(descriptor);
        assert overridden != null;

        Method method = typeMapper.mapSignature(descriptor).getAsmMethod();
        int flags = ACC_ABSTRACT | getVisibilityAccessFlag(descriptor);
        v.newMethod(
            JvmDeclarationOriginKt.OtherOrigin(overridden),
            flags,
            method.getName(),
            method.getDescriptor(),
            null,
            null);
      }
    }
  }