@NotNull private static AnonymousFunctionDescriptor createFunctionDescriptor( @NotNull JetFunctionLiteralExpression expression, @NotNull ExpressionTypingContext context, boolean functionTypeExpected) { JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef(); AnonymousFunctionDescriptor functionDescriptor = new AnonymousFunctionDescriptor( context.scope.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), CallableMemberDescriptor.Kind.DECLARATION); List<ValueParameterDescriptor> valueParameterDescriptors = createValueParameterDescriptors( context, functionLiteral, functionDescriptor, functionTypeExpected); JetType effectiveReceiverType; if (receiverTypeRef == null) { if (functionTypeExpected) { effectiveReceiverType = KotlinBuiltIns.getInstance().getReceiverType(context.expectedType); } else { effectiveReceiverType = null; } } else { effectiveReceiverType = context .expressionTypingServices .getTypeResolver() .resolveType(context.scope, receiverTypeRef, context.trace, true); } functionDescriptor.initialize( effectiveReceiverType, ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER, Collections.<TypeParameterDescriptorImpl>emptyList(), valueParameterDescriptors, /*unsubstitutedReturnType = */ null, Modality.FINAL, Visibilities.LOCAL); BindingContextUtils.recordFunctionDeclarationToDescriptor( context.trace, functionLiteral, functionDescriptor); return functionDescriptor; }
@Override public void recordMethod( @NotNull JavaMethod method, @NotNull SimpleFunctionDescriptor descriptor) { BindingContextUtils.recordFunctionDeclarationToDescriptor( trace, ((JavaMethodImpl) method).getPsi(), descriptor); }