Example #1
0
  public static SimpleFunctionDescriptor createInvoke(FunctionDescriptor fd) {
    int arity = fd.getValueParameters().size();
    SimpleFunctionDescriptorImpl invokeDescriptor =
        new SimpleFunctionDescriptorImpl(
            fd.getExpectedThisObject().exists()
                ? JetStandardClasses.getReceiverFunction(arity)
                : JetStandardClasses.getFunction(arity),
            Collections.<AnnotationDescriptor>emptyList(),
            Name.identifier("invoke"),
            CallableMemberDescriptor.Kind.DECLARATION);

    invokeDescriptor.initialize(
        fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null,
        fd.getExpectedThisObject(),
        Collections.<TypeParameterDescriptorImpl>emptyList(),
        fd.getValueParameters(),
        fd.getReturnType(),
        Modality.FINAL,
        Visibilities.PUBLIC,
        /*isInline = */ false);
    return invokeDescriptor;
  }
Example #2
0
  @NotNull
  public Collection<JetType> getSupertypesForCallableReference(
      @NotNull FunctionDescriptor descriptor) {
    ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
    ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject();

    List<TypeProjection> typeArguments = new ArrayList<TypeProjection>(2);

    ClassDescriptor classDescriptor;
    JetType receiverType;
    if (receiverParameter != null) {
      classDescriptor = kExtensionFunctionImpl;
      receiverType = receiverParameter.getType();
      typeArguments.add(new TypeProjectionImpl(receiverType));
    } else if (expectedThisObject != null) {
      classDescriptor = kMemberFunctionImpl;
      receiverType = expectedThisObject.getType();
      typeArguments.add(new TypeProjectionImpl(receiverType));
    } else {
      classDescriptor = kFunctionImpl;
      receiverType = null;
    }

    //noinspection ConstantConditions
    typeArguments.add(new TypeProjectionImpl(descriptor.getReturnType()));

    JetType kFunctionImplType =
        new JetTypeImpl(
            classDescriptor.getDefaultType().getAnnotations(),
            classDescriptor.getTypeConstructor(),
            false,
            typeArguments,
            classDescriptor.getMemberScope(typeArguments));

    JetType kFunctionType =
        reflectionTypes.getKFunctionType(
            Annotations.EMPTY,
            receiverType,
            DescriptorUtils.getValueParametersTypes(descriptor.getValueParameters()),
            descriptor.getReturnType(),
            receiverParameter != null);

    return Arrays.asList(kFunctionImplType, kFunctionType);
  }
  public AccessorForFunctionDescriptor(
      @NotNull FunctionDescriptor descriptor,
      @NotNull DeclarationDescriptor containingDeclaration,
      int index) {
    super(
        containingDeclaration,
        Annotations.EMPTY,
        Name.identifier(
            (descriptor instanceof ConstructorDescriptor ? "$init" : descriptor.getName())
                + "$b$"
                + index),
        Kind.DECLARATION);

    initialize(
        DescriptorUtils.getReceiverParameterType(descriptor.getReceiverParameter()),
        descriptor instanceof ConstructorDescriptor
            ? NO_RECEIVER_PARAMETER
            : descriptor.getExpectedThisObject(),
        Collections.<TypeParameterDescriptor>emptyList(),
        copyValueParameters(descriptor),
        descriptor.getReturnType(),
        Modality.FINAL,
        Visibilities.INTERNAL);
  }