Example #1
0
            public async Task <OperationStatus <SemanticDocument> > ApplyAsync(GeneratedCode generatedCode, CancellationToken cancellationToken)
            {
                var document = generatedCode.SemanticDocument;
                var root     = document.Root;

                var callsiteAnnotation         = generatedCode.CallSiteAnnotation;
                var methodDefinitionAnnotation = generatedCode.MethodDefinitionAnnotation;

                var callsite = root.GetAnnotatedNodesAndTokens(callsiteAnnotation).SingleOrDefault().AsNode();
                var method   = root.GetAnnotatedNodesAndTokens(methodDefinitionAnnotation).SingleOrDefault().AsNode();

                var annotationResolver = GetAnnotationResolver(callsite, method);
                var triviaResolver     = GetTriviaResolver(method);

                if (annotationResolver == null || triviaResolver == null)
                {
                    // bug # 6644
                    // this could happen in malformed code. return as it was.
                    var status = new OperationStatus(OperationStatusFlag.None, "FeaturesResources.CantNotConstructFinalTree");
                    return(status.With(document));
                }

                return(OperationStatus.Succeeded.With(
                           await document.WithSyntaxRootAsync(_result.RestoreTrivia(root, annotationResolver, triviaResolver), cancellationToken).ConfigureAwait(false)));
            }
        private async Task <Tuple <bool, OperationStatus> > TryCheckVariableTypeAsync(
            SemanticDocument document, SyntaxNode contextNode, IEnumerable <VariableInfo> variables,
            OperationStatus status, CancellationToken cancellationToken)
        {
            if (status.FailedWithNoBestEffortSuggestion())
            {
                return(Tuple.Create(false, status));
            }

            var location = contextNode.GetLocation();

            foreach (var variable in variables)
            {
                var originalType = variable.GetVariableType(document);
                var result       = await CheckTypeAsync(document.Document, contextNode, location, originalType, cancellationToken).ConfigureAwait(false);

                if (result.FailedWithNoBestEffortSuggestion())
                {
                    status = status.With(result);
                    return(Tuple.Create(false, status));
                }
            }

            return(Tuple.Create(true, status));
        }