@NotNull public Collection<JetType> getSupertypesForClosure(@NotNull FunctionDescriptor descriptor) { ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter(); List<TypeProjection> typeArguments = new ArrayList<TypeProjection>(2); ClassDescriptor classDescriptor; if (receiverParameter != null) { classDescriptor = extensionFunctionImpl; typeArguments.add(new TypeProjectionImpl(receiverParameter.getType())); } else { classDescriptor = functionImpl; } //noinspection ConstantConditions typeArguments.add(new TypeProjectionImpl(descriptor.getReturnType())); JetType functionImplType = new JetTypeImpl( classDescriptor.getDefaultType().getAnnotations(), classDescriptor.getTypeConstructor(), false, typeArguments, classDescriptor.getMemberScope(typeArguments)); JetType functionType = KotlinBuiltIns.getInstance() .getFunctionType( Annotations.EMPTY, receiverParameter == null ? null : receiverParameter.getType(), DescriptorUtils.getValueParametersTypes(descriptor.getValueParameters()), descriptor.getReturnType()); return Arrays.asList(functionImplType, functionType); }
/* FUNCTIONS */ private void renderFunction( @NotNull FunctionDescriptor function, @NotNull StringBuilder builder) { if (!startFromName) { renderAnnotations(function, builder); renderVisibility(function.getVisibility(), builder); renderModalityForCallable(function, builder); renderOverride(function, builder); renderMemberKind(function, builder); builder.append(renderKeyword("fun")).append(" "); renderTypeParameters(function.getTypeParameters(), builder, true); ReceiverParameterDescriptor receiver = function.getReceiverParameter(); if (receiver != null) { builder.append(escape(renderType(receiver.getType()))).append("."); } } renderName(function, builder); renderValueParameters(function, builder); JetType returnType = function.getReturnType(); if (unitReturnType || !KotlinBuiltIns.getInstance().isUnit(returnType)) { builder.append(": ").append(returnType == null ? "[NULL]" : escape(renderType(returnType))); } renderWhereSuffix(function.getTypeParameters(), builder); }
static List<KotlinType> compiledValueParameters(CallableDescriptor callableDescriptor) { ReceiverParameterDescriptor receiverParameter = callableDescriptor.getExtensionReceiverParameter(); List<KotlinType> parameters = new ArrayList<KotlinType>(); if (receiverParameter != null) { parameters.add(receiverParameter.getType()); } for (ValueParameterDescriptor valueParameterDescriptor : callableDescriptor.getValueParameters()) { parameters.add(valueParameterDescriptor.getType()); } return parameters; }
@NotNull public Collection<KotlinType> getSupertypesForClosure(@NotNull FunctionDescriptor descriptor) { ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter(); //noinspection ConstantConditions KotlinType functionType = DescriptorUtilsKt.getBuiltIns(descriptor) .getFunctionType( Annotations.Companion.getEMPTY(), receiverParameter == null ? null : receiverParameter.getType(), ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()), descriptor.getReturnType()); return Arrays.asList(lambda.getDefaultType(), functionType); }
@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); }
@NotNull public Collection<KotlinType> getSupertypesForFunctionReference( @NotNull FunctionDescriptor descriptor) { ReceiverParameterDescriptor extensionReceiver = descriptor.getExtensionReceiverParameter(); ReceiverParameterDescriptor dispatchReceiver = descriptor.getDispatchReceiverParameter(); KotlinType receiverType = extensionReceiver != null ? extensionReceiver.getType() : dispatchReceiver != null ? dispatchReceiver.getType() : null; //noinspection ConstantConditions KotlinType functionType = DescriptorUtilsKt.getBuiltIns(descriptor) .getFunctionType( Annotations.Companion.getEMPTY(), receiverType, ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()), descriptor.getReturnType()); return Arrays.asList(functionReference.getDefaultType(), functionType); }
private void renderProperty( @NotNull PropertyDescriptor property, @NotNull StringBuilder builder) { if (!startFromName) { renderAnnotations(property, builder); renderVisibility(property.getVisibility(), builder); renderModalityForCallable(property, builder); renderOverride(property, builder); renderMemberKind(property, builder); renderValVarPrefix(property, builder); } renderTypeParameters(property.getTypeParameters(), builder, true); ReceiverParameterDescriptor receiver = property.getReceiverParameter(); if (receiver != null) { builder.append(escape(renderType(receiver.getType()))).append("."); } renderName(property, builder); builder.append(": ").append(escape(renderType(property.getType()))); renderWhereSuffix(property.getTypeParameters(), builder); }
@Nullable public static KotlinType getReceiverParameterType( @Nullable ReceiverParameterDescriptor receiverParameterDescriptor) { return receiverParameterDescriptor == null ? null : receiverParameterDescriptor.getType(); }