public static Endpoint ToEndpoint(this SymbolCallerInfo symbolCallerInfo) { var action = symbolCallerInfo.CallingSymbol; var attribute = action .GetAttributes() .FirstOrDefault(a => a.AttributeClass.Name == "Usage"); string url = string.Empty, method = string.Empty; var isLabeledWithAttribute = attribute != null; if (isLabeledWithAttribute) { var parameters = attribute.ApplicationSyntaxReference.GetSyntax() .DescendantNodes() .Where(n => n is AttributeArgumentSyntax) .ToArray(); url = parameters[0].ToString().Replace("\"", ""); method = parameters[1].ToString().Replace("\"", ""); } return(new Endpoint() { Url = url, HttpMethod = method, Controller = action.ContainingType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), Method = action.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), Namespace = action.ContainingSymbol.ContainingNamespace.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), IsLabelled = isLabeledWithAttribute }); }
private void Warning(SymbolCallerInfo callerInfo, string message) { foreach (var location in callerInfo.Locations.Reverse()) { Warning(location.GetLineSpan(), message); } }
void FindCallers(MenuItem menuItem, ISymbol source) { var docs = System.Collections.Immutable.ImmutableHashSet.CreateRange(_Document.Project.GetRelatedDocuments()); SymbolCallerInfo[] callers; switch (source.Kind) { case SymbolKind.Method: case SymbolKind.Property: case SymbolKind.Event: callers = SymbolFinder.FindCallersAsync(source, _Document.Project.Solution, docs).Result.ToArray(); break; case SymbolKind.NamedType: var tempResults = new HashSet <SymbolCallerInfo>(SymbolCallerInfoComparer.Instance); foreach (var item in (source as INamedTypeSymbol).InstanceConstructors) { foreach (var c in SymbolFinder.FindCallersAsync(item, _Document.Project.Solution, docs).Result) { tempResults.Add(c); } } tempResults.CopyTo(callers = new SymbolCallerInfo[tempResults.Count]); break; default: return; } Array.Sort(callers, (a, b) => { var s = a.CallingSymbol.ContainingType.Name.CompareTo(b.CallingSymbol.ContainingType.Name); return(s != 0 ? s : a.CallingSymbol.Name.CompareTo(b.CallingSymbol.Name)); }); if (callers.Length < 10) { foreach (var caller in callers) { var s = caller.CallingSymbol; menuItem.Items.Add(new SymbolMenuItem(this, s, caller.Locations) { Header = new TextBlock().Append(s.ContainingType.Name + ".", System.Windows.Media.Brushes.Gray).Append(s.Name) }); } } else { SymbolMenuItem subMenu = null; INamedTypeSymbol typeSymbol = null; foreach (var caller in callers) { var s = caller.CallingSymbol; if (typeSymbol == null || typeSymbol != s.ContainingType) { typeSymbol = s.ContainingType; subMenu = new SymbolMenuItem(this, typeSymbol, null); menuItem.Items.Add(subMenu); } subMenu.Items.Add(new SymbolMenuItem(this, s, caller.Locations)); } } }
void FindCallers(CommandContext context, MenuItem menuItem, ISymbol source) { var doc = _Context.Document; var docs = System.Collections.Immutable.ImmutableHashSet.CreateRange(doc.Project.GetRelatedProjectDocuments()); SymbolCallerInfo[] callers; switch (source.Kind) { case SymbolKind.Method: case SymbolKind.Property: case SymbolKind.Event: callers = ThreadHelper.JoinableTaskFactory.Run(() => SymbolFinder.FindCallersAsync(source, doc.Project.Solution, docs, context.CancellationToken)).ToArray(); break; case SymbolKind.NamedType: var tempResults = new HashSet <SymbolCallerInfo>(SymbolCallerInfoComparer.Instance); ThreadHelper.JoinableTaskFactory.Run(async() => { foreach (var item in (source as INamedTypeSymbol).InstanceConstructors) { foreach (var c in await SymbolFinder.FindCallersAsync(item, doc.Project.Solution, docs, context.CancellationToken)) { tempResults.Add(c); } } }); tempResults.CopyTo(callers = new SymbolCallerInfo[tempResults.Count]); break; default: return; } Array.Sort(callers, (a, b) => { return(CompareSymbol(a.CallingSymbol, b.CallingSymbol)); }); if (callers.Length < 10) { foreach (var caller in callers) { var s = caller.CallingSymbol; menuItem.Items.Add(new SymbolMenuItem(this, s, caller.Locations) { Header = new TextBlock().Append(s.ContainingType.Name + ".", WpfBrushes.Gray).Append(s.Name) }); } } else { SymbolMenuItem subMenu = null; INamedTypeSymbol typeSymbol = null; foreach (var caller in callers) { var s = caller.CallingSymbol; if (typeSymbol == null || typeSymbol != s.ContainingType) { typeSymbol = s.ContainingType; subMenu = new SymbolMenuItem(this, typeSymbol, null); menuItem.Items.Add(subMenu); } subMenu.Items.Add(new SymbolMenuItem(this, s, caller.Locations)); } } }