private void AddToCallerCalleeMap(OperationAnalysisContext context, Dictionary <IMethodSymbol, List <CallInfo> > callerToCalleeMap) { if (CSharpUtils.IsWithinNameOf(context.Operation.Syntax)) { return; } IMethodSymbol?GetPropertyAccessor(IPropertySymbol?propertySymbol) { if (propertySymbol is object) { return(CSharpUtils.IsOnLeftHandOfAssignment(context.Operation.Syntax) ? propertySymbol.SetMethod : propertySymbol.GetMethod); } return(null); } ISymbol? targetMethod = null; SyntaxNode locationToBlame = context.Operation.Syntax; switch (context.Operation) { case IInvocationOperation invocationOperation: targetMethod = invocationOperation.TargetMethod; locationToBlame = this.languageUtils.IsolateMethodName(invocationOperation); break; case IPropertyReferenceOperation propertyReference: targetMethod = GetPropertyAccessor(propertyReference.Property); break; case IEventAssignmentOperation eventAssignmentOperation: IOperation eventReferenceOp = eventAssignmentOperation.EventReference; if (eventReferenceOp is IEventReferenceOperation eventReference) { targetMethod = eventAssignmentOperation.Adds ? eventReference.Event.AddMethod : eventReference.Event.RemoveMethod; locationToBlame = eventReference.Syntax; } break; } if (context.ContainingSymbol is IMethodSymbol caller && targetMethod is IMethodSymbol callee) { lock (callerToCalleeMap) { if (!callerToCalleeMap.TryGetValue(caller, out List <CallInfo> callees)) { callerToCalleeMap[caller] = callees = new List <CallInfo>(); } callees.Add(new CallInfo(methodSymbol: callee, invocationSyntax: locationToBlame)); } } }
private static void AddToCallerCalleeMap(SyntaxNodeAnalysisContext context, Dictionary <IMethodSymbol, List <CallInfo> > callerToCalleeMap) { if (CSharpUtils.IsWithinNameOf(context.Node)) { return; } IMethodSymbol?GetPropertyAccessor(IPropertySymbol?propertySymbol) { if (propertySymbol is object) { return(CSharpUtils.IsOnLeftHandOfAssignment(context.Node) ? propertySymbol.SetMethod : propertySymbol.GetMethod); } return(null); } ISymbol? targetMethod = null; SyntaxNode locationToBlame = context.Node; switch (context.Node) { case InvocationExpressionSyntax invocationExpressionSyntax: targetMethod = context.SemanticModel.GetSymbolInfo(invocationExpressionSyntax.Expression, context.CancellationToken).Symbol; locationToBlame = invocationExpressionSyntax.Expression; break; case MemberAccessExpressionSyntax memberAccessExpressionSyntax: targetMethod = GetPropertyAccessor(context.SemanticModel.GetSymbolInfo(memberAccessExpressionSyntax.Name, context.CancellationToken).Symbol as IPropertySymbol); break; case IdentifierNameSyntax identifierNameSyntax: targetMethod = GetPropertyAccessor(context.SemanticModel.GetSymbolInfo(identifierNameSyntax, context.CancellationToken).Symbol as IPropertySymbol); break; } if (context.ContainingSymbol is IMethodSymbol caller && targetMethod is IMethodSymbol callee) { lock (callerToCalleeMap) { if (!callerToCalleeMap.TryGetValue(caller, out List <CallInfo> callees)) { callerToCalleeMap[caller] = callees = new List <CallInfo>(); } callees.Add(new CallInfo(methodSymbol: callee, invocationSyntax: locationToBlame)); } } }