private async Task ProcessMethod( MethodDeclarationSyntax method , Compilation compilation , SyntaxTree syntaxTree) { var model = compilation.GetSemanticModel(syntaxTree); var methodSymbol = model.GetDeclaredSymbol(method); var callingMethods = await GetCallingMethodsAsync(methodSymbol, method); Parallel.ForEach(callingMethods, callingMethod => { ClassDeclarationSyntax callingClass = null; if (SyntaxNodeHelper.TryGetParentSyntax(method, out callingClass)) { List <MethodDeclarationSyntax> value; if (!_methodDeclarationSyntaxes.TryGetValue(callingMethod, out value)) { if (!_methodDeclarationSyntaxes.TryAdd(callingMethod, new List <MethodDeclarationSyntax>() { method })) { throw new Exception("Could not add item to _methodDeclarationSyntaxes!"); } } else { value.Add(method); } } }); }
private IEnumerable <string> PrintMethodInfo(MethodDeclarationSyntax callingMethod) { if (!_methodDeclarationSyntaxes.ContainsKey(callingMethod)) { return(new string[0]); } List <string> result = new List <string>(); Dictionary <int, MethodDeclarationSyntax> calledMethods = _methodOrder[callingMethod]; IOrderedEnumerable <KeyValuePair <int, MethodDeclarationSyntax> > orderedCalledMethods = calledMethods.OrderBy(kvp => kvp.Key); foreach (MethodDeclarationSyntax calledMethod in orderedCalledMethods.Select(kvp => kvp.Value)) { if (SyntaxNodeHelper.TryGetParentSyntax(callingMethod, out ClassDeclarationSyntax callingClass) && SyntaxNodeHelper.TryGetParentSyntax(calledMethod, out ClassDeclarationSyntax calledClass)) { string resultLine = PrintOutgoingCallInfo(calledClass, callingClass, callingMethod, calledMethod); if (callingMethod != calledMethod) { resultLine += PrintMethodInfo(calledMethod); } resultLine += PrintReturnCallInfo(calledClass, callingClass, callingMethod, calledMethod); result.Add(resultLine); } } return(result); }
public void PrintMethodInfo(MethodDeclarationSyntax callingMethod) { if (!_methodDeclarationSyntaxes.ContainsKey(callingMethod)) { return; } var calledMethods = _methodOrder[callingMethod]; var orderedCalledMethods = calledMethods.OrderBy(kvp => kvp.Key); foreach (var kvp in orderedCalledMethods) { var calledMethod = kvp.Value; ClassDeclarationSyntax callingClass = null; ClassDeclarationSyntax calledClass = null; if (!SyntaxNodeHelper.TryGetParentSyntax(callingMethod, out callingClass) || !SyntaxNodeHelper.TryGetParentSyntax(calledMethod, out calledClass)) { continue; } PrintOutgoingCallInfo( calledClass , callingClass , callingMethod , calledMethod ); if (callingMethod != calledMethod) { PrintMethodInfo(calledMethod); } PrintReturnCallInfo( calledClass , callingClass , callingMethod , calledMethod ); } }
private async Task ProcessMethod(MethodDeclarationSyntax method, Compilation compilation, SyntaxTree syntaxTree) { SemanticModel model = compilation.GetSemanticModel(syntaxTree); IMethodSymbol methodSymbol = model.GetDeclaredSymbol(method); List <MethodDeclarationSyntax> callingMethods = await GetCallingMethodsAsync(methodSymbol, method); Parallel.ForEach(callingMethods , callingMethod => { if (SyntaxNodeHelper.TryGetParentSyntax(method, out ClassDeclarationSyntax _)) { if (!_methodDeclarationSyntaxes.ContainsKey(callingMethod)) { _methodDeclarationSyntaxes[callingMethod] = new List <MethodDeclarationSyntax>(); } _methodDeclarationSyntaxes[callingMethod].Add(method); } }); }