diff --git a/src/PortToTripleSlash/src/libraries/AllTypesVisitor.cs b/src/PortToTripleSlash/src/libraries/AllTypesVisitor.cs index abe7421..9645eb3 100644 --- a/src/PortToTripleSlash/src/libraries/AllTypesVisitor.cs +++ b/src/PortToTripleSlash/src/libraries/AllTypesVisitor.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -25,7 +25,13 @@ public override void VisitNamedType(INamedTypeSymbol symbol) Visit(typeMember); } } - public override void VisitNamespace(INamespaceSymbol symbol) => Parallel.ForEach(symbol.GetMembers(), s => s.Accept(this)); + public override void VisitNamespace(INamespaceSymbol symbol) + { + foreach (INamespaceOrTypeSymbol s in symbol.GetMembers()) + { + s.Accept(this); + } + } public override void VisitDynamicType(IDynamicTypeSymbol symbol) => AllTypesSymbols.Add(symbol); public override void VisitFunctionPointerType(IFunctionPointerTypeSymbol symbol) => AllTypesSymbols.Add(symbol); public override void VisitAlias(IAliasSymbol symbol) => AllTypesSymbols.Add(symbol); diff --git a/src/PortToTripleSlash/src/libraries/ToTripleSlashPorter.cs b/src/PortToTripleSlash/src/libraries/ToTripleSlashPorter.cs index 1c1e26d..790654e 100644 --- a/src/PortToTripleSlash/src/libraries/ToTripleSlashPorter.cs +++ b/src/PortToTripleSlash/src/libraries/ToTripleSlashPorter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; @@ -91,7 +91,7 @@ public async Task StartAsync(CancellationToken cancellationToken) cancellationToken.ThrowIfCancellationRequested(); CollectFiles(); - if (!_docsComments.Types.Any()) + if (_docsComments.Types.Count == 0) { Log.Error("No docs files found."); return; @@ -105,7 +105,7 @@ public async Task StartAsync(CancellationToken cancellationToken) /// public async Task MatchSymbolsAsync(Compilation compilation, bool isMSBuildProject, CancellationToken cancellationToken) { - Debug.Assert(_docsComments.Types.Any()); + Debug.Assert(_docsComments.Types.Count != 0); cancellationToken.ThrowIfCancellationRequested(); Log.Info("Looking for symbol locations for all Docs types..."); @@ -127,13 +127,14 @@ public async Task MatchSymbolsAsync(Compilation compilation, bool isMSBuildProje /// public async Task PortAsync(bool isMSBuildProject, CancellationToken cancellationToken) { - Debug.Assert(_docsComments.Types.Any()); + Debug.Assert(_docsComments.Types.Count != 0); cancellationToken.ThrowIfCancellationRequested(); Log.Info($"Now attempting to port all found symbols..."); foreach (DocsType docsType in _docsComments.Types.Values) { - if (docsType.SymbolLocations == null || !docsType.SymbolLocations.Any()) + Debug.Assert(docsType.SymbolLocations != null); + if (docsType.SymbolLocations.Count == 0) { Log.Warning($"No symbols found for '{docsType.DocId}'. Skipping."); continue; @@ -164,7 +165,11 @@ private static void CollectSymbolLocations(Compilation compilation, DocsType doc { FindLocationsOfSymbolInResolvedProject(docsType, compilation); - if (docsType.SymbolLocations == null || !docsType.SymbolLocations.Any()) + if (docsType.SymbolLocations == null) + { + throw new NullReferenceException(); + } + if (docsType.SymbolLocations.Count == 0) { Log.Error($"No symbols found for docs type '{docsType.DocId}'."); } @@ -245,16 +250,15 @@ private static void FindLocationsOfSymbolInResolvedProject(DocsType docsType, Co // Next, filter types that match the current docsType IEnumerable currentTypeSymbols = visitor.AllTypesSymbols.Where(s => s != null && s.GetDocumentationCommentId() == docsType.DocId); + docsType.SymbolLocations ??= new(); foreach (ISymbol symbol in currentTypeSymbols) { - docsType.SymbolLocations = GetSymbolLocations(compilation, symbol); + GetSymbolLocations(docsType.SymbolLocations, compilation, symbol); } } - private static List GetSymbolLocations(Compilation compilation, ISymbol symbol) + private static void GetSymbolLocations(List resolvedLocations, Compilation compilation, ISymbol symbol) { - List resolvedLocations = new(); - int n = 0; string docId = symbol.GetDocumentationCommentId() ?? throw new NullReferenceException($"DocID was null for symbol '{symbol}'"); foreach (Location location in symbol.Locations) @@ -289,8 +293,6 @@ private static List GetSymbolLocations(Compilation compilation } n++; } - - return resolvedLocations; } [GeneratedRegex("src(?[\\\\\\/]{1})coreclr")]