public async Task AnalyzerExceptionDiagnosticsWithDifferentContext() { var exceptionDiagnostics = new HashSet <Diagnostic>(); await VerifyCSharpAsync(@" public class C { } public class C1 { } public class C2 { } ", new[] { new ThrowExceptionForEachNamedTypeAnalyzer() }, onAnalyzerException : (ex, a, d) => exceptionDiagnostics.Add(d)); var diagnostic = Diagnostic("AD0001", null) .WithArguments( "Microsoft.CodeAnalysis.UnitTests.Diagnostics.SuppressMessageAttributeTests+ThrowExceptionForEachNamedTypeAnalyzer", "System.Exception", "ThrowExceptionAnalyzer exception") .WithLocation(1, 1); // expect 3 different diagnostics with 3 different contexts. exceptionDiagnostics.Verify(diagnostic, diagnostic, diagnostic); }
public async Task SuppressDuplicateAnalyzerExceptionDiagnostics() { var exceptionDiagnostics = new HashSet <Diagnostic>(); await VerifyCSharpAsync(@" public class C { } public class C1 { } public class C2 { } ", new[] { new ThrowExceptionForEachNamedTypeAnalyzer() }, onAnalyzerException : (ex, a, d) => exceptionDiagnostics.Add(d)); exceptionDiagnostics.Verify( Diagnostic("AD0001", null) .WithArguments( "Microsoft.CodeAnalysis.UnitTests.Diagnostics.SuppressMessageAttributeTests+ThrowExceptionForEachNamedTypeAnalyzer", "System.Exception", "ThrowExceptionAnalyzer exception") .WithLocation(1, 1)); }
/// <summary> /// Get all connected nodes for include set, excludeNodes will stop the edge tracing. /// </summary> /// <param name="includeNodeKeys">nodes to focus on</param> /// <param name="includeDependentNodes">true to trace dependencies</param> /// <param name="excludedNodeKeys">exclude nodes, will stop trace dependencies (edges) on these nodes</param> /// <param name="ownEdge">true to trace own edges</param> /// <param name="dependsOnEdge">true to trace depends on edges</param> /// <returns>List of linked nodes</returns> public IReadOnlyList <TNode> GetLinkedNodes(HashSet <TKey> includeNodeKeys, bool includeDependentNodes, HashSet <TKey> excludedNodeKeys, bool ownEdge, bool dependsOnEdge) { includeNodeKeys.Verify(nameof(includeNodeKeys)).IsNotNull(); var visitedKeys = excludedNodeKeys ?? new HashSet <TKey>(KeyCompare); var childrenKeys = new HashSet <TKey>(KeyCompare); var focusedKeys = new List <TKey>(includeNodeKeys); bool IsOwnEdge(IGraphEdge <TKey> edge) => ownEdge && typeof(GraphEdge <TKey>).IsAssignableFrom(edge.GetType()); bool IsDependsOnEdge(IGraphEdge <TKey> edge) => dependsOnEdge && typeof(GraphDependOnEdge <TKey>).IsAssignableFrom(edge.GetType()); var focusedEdges = includeDependentNodes ? Edges.Values.Where(x => IsOwnEdge(x) || IsDependsOnEdge(x)).ToList() : Enumerable.Empty <TEdge>().ToList(); while (true) { var children = focusedKeys .Where(x => !visitedKeys.Contains(x)) .Join(focusedEdges, x => x, x => !dependsOnEdge ? x.FromNodeKey : x.ToNodeKey, (o, i) => i, KeyCompare) .ToList(); if (children.Count == 0) { return(childrenKeys .Concat(focusedKeys.Where(x => !includeNodeKeys.Contains(x))) .Distinct(KeyCompare) .Join(Nodes.Values, x => x, x => x.Key, (o, i) => i, KeyCompare) .ToList()); } focusedKeys.Clear(); children .Select(x => !dependsOnEdge ? x.ToNodeKey : x.FromNodeKey) .Where(x => !visitedKeys.Contains(x)) .ForEach(x => focusedKeys.Add(x)); focusedKeys .ForEach(x => childrenKeys.Add(x)); children .ForEach(x => visitedKeys.Add(!dependsOnEdge ? x.FromNodeKey : x.ToNodeKey)); } }
public void SuppressDuplicateAnalyzerExceptionDiagnostics() { var exceptionDiagnostics = new HashSet<Diagnostic>(); VerifyCSharp(@" public class C { } public class C1 { } public class C2 { } ", new[] { new ThrowExceptionForEachNamedTypeAnalyzer() }, onAnalyzerException: (ex, a, d) => exceptionDiagnostics.Add(d)); exceptionDiagnostics.Verify( Diagnostic("AD0001", null) .WithArguments( "Microsoft.CodeAnalysis.UnitTests.Diagnostics.SuppressMessageAttributeTests+ThrowExceptionForEachNamedTypeAnalyzer", "System.Exception", "ThrowExceptionAnalyzer exception") .WithLocation(1, 1)); }
public async Task AnalyzerExceptionDiagnosticsWithDifferentContext() { var exceptionDiagnostics = new HashSet<Diagnostic>(); await VerifyCSharpAsync(@" public class C { } public class C1 { } public class C2 { } ", new[] { new ThrowExceptionForEachNamedTypeAnalyzer() }, onAnalyzerException: (ex, a, d) => exceptionDiagnostics.Add(d)); var diagnostic = Diagnostic("AD0001", null) .WithArguments( "Microsoft.CodeAnalysis.UnitTests.Diagnostics.SuppressMessageAttributeTests+ThrowExceptionForEachNamedTypeAnalyzer", "System.Exception", "ThrowExceptionAnalyzer exception") .WithLocation(1, 1); // expect 3 different diagnostics with 3 different contexts. exceptionDiagnostics.Verify(diagnostic, diagnostic, diagnostic); }