/// <summary> /// Returns the candidate callees after resolving the specified invocation. /// </summary> /// <param name="invocation">InvocationExpressionSyntax</param> /// <param name="node">IDataFlowNode</param> /// <returns>Set of candidate callees</returns> private static HashSet <MethodDeclarationSyntax> ResolveCandidateMethodsAtCallSite( InvocationExpressionSyntax invocation, IDataFlowNode node) { var candidateCallees = new HashSet <MethodDeclarationSyntax>(); var candidateMethodDeclaration = MethodSummaryResolver.ResolveMethodDeclaration( invocation, node) as MethodDeclarationSyntax; if (candidateMethodDeclaration == null) { return(candidateCallees); } if (candidateMethodDeclaration.Modifiers.Any(SyntaxKind.AbstractKeyword) || candidateMethodDeclaration.Modifiers.Any(SyntaxKind.VirtualKeyword) || candidateMethodDeclaration.Modifiers.Any(SyntaxKind.OverrideKeyword)) { HashSet <MethodDeclarationSyntax> overriders = null; if (!MethodSummaryResolver.TryGetCandidateMethodOverriders(out overriders, invocation, node)) { return(candidateCallees); } candidateCallees.UnionWith(overriders); } if (candidateCallees.Count == 0) { candidateCallees.Add(candidateMethodDeclaration); } return(candidateCallees); }
/// <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); }