/// <summary>
        /// Returns all cached method summaries for the specified call.
        /// </summary>
        /// <param name="call">ExpressionSyntax</param>
        /// <param name="node">IDataFlowNode</param>
        /// <returns>MethodSummarys</returns>
        private static ISet <MethodSummary> ResolveMethodSummaries(ExpressionSyntax call, IDataFlowNode node)
        {
            var summaries = new HashSet <MethodSummary>();

            var invocation  = call as InvocationExpressionSyntax;
            var objCreation = call as ObjectCreationExpressionSyntax;
            var callSymbol  = node.Summary.SemanticModel.GetSymbolInfo(call).Symbol;

            if (callSymbol == null ||
                (invocation == null && objCreation == null))
            {
                return(summaries);
            }

            if (node.MethodSummaryCache.ContainsKey(callSymbol))
            {
                summaries.UnionWith(node.MethodSummaryCache[callSymbol]);
            }
            else if (invocation != null)
            {
                var parameterTypes = MethodSummaryResolver.GetCandidateParameterTypes(
                    invocation.ArgumentList, node);
                var candidateCalleeDeclarations = MethodSummaryResolver.
                                                  ResolveCandidateMethodsAtCallSite(invocation, node);
                foreach (var candidateCalleeDeclaration in candidateCalleeDeclarations)
                {
                    var calleeSummary = MethodSummary.Create(node.Summary.AnalysisContext,
                                                             candidateCalleeDeclaration, parameterTypes);
                    if (calleeSummary != null)
                    {
                        summaries.Add(calleeSummary);
                    }
                }
            }
            else
            {
                var parameterTypes = MethodSummaryResolver.GetCandidateParameterTypes(
                    objCreation.ArgumentList, node);
                var constructor = MethodSummaryResolver.ResolveMethodDeclaration(
                    objCreation, node) as ConstructorDeclarationSyntax;
                if (constructor != null)
                {
                    var calleeSummary = MethodSummary.Create(node.Summary.AnalysisContext,
                                                             constructor, parameterTypes);
                    if (calleeSummary != null)
                    {
                        summaries.Add(calleeSummary);
                    }
                }
            }

            return(summaries);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates the summary of the specified method.
 /// </summary>
 /// <param name="context">AnalysisContext</param>
 /// <param name="method">BaseMethodDeclarationSyntax</param>
 /// <returns>MethodSummary</returns>
 public static MethodSummary Create(AnalysisContext context, BaseMethodDeclarationSyntax method)
 {
     return(MethodSummary.Create(context, method, new Dictionary <int, ISet <ITypeSymbol> >()));
 }