Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/PortToTripleSlash/src/libraries/AllTypesVisitor.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
26 changes: 14 additions & 12 deletions src/PortToTripleSlash/src/libraries/ToTripleSlashPorter.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
cancellationToken.ThrowIfCancellationRequested();

CollectFiles();
if (!_docsComments.Types.Any())
if (_docsComments.Types.Count == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to use !_docsComments.Types.HasItems() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CA1860 recommends using Count for perf and readability purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if !HasItems() is more performant than Count == 0. I applied the Roslyn suggestion.

{
Log.Error("No docs files found.");
return;
Expand All @@ -105,7 +105,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
/// </summary>
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...");
Expand All @@ -127,13 +127,14 @@ public async Task MatchSymbolsAsync(Compilation compilation, bool isMSBuildProje
/// </summary>
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;
Expand Down Expand Up @@ -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}'.");
}
Expand Down Expand Up @@ -245,16 +250,15 @@ private static void FindLocationsOfSymbolInResolvedProject(DocsType docsType, Co
// Next, filter types that match the current docsType
IEnumerable<ISymbol> 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<ResolvedLocation> GetSymbolLocations(Compilation compilation, ISymbol symbol)
private static void GetSymbolLocations(List<ResolvedLocation> resolvedLocations, Compilation compilation, ISymbol symbol)
{
List<ResolvedLocation> resolvedLocations = new();

int n = 0;
string docId = symbol.GetDocumentationCommentId() ?? throw new NullReferenceException($"DocID was null for symbol '{symbol}'");
foreach (Location location in symbol.Locations)
Expand Down Expand Up @@ -289,8 +293,6 @@ private static List<ResolvedLocation> GetSymbolLocations(Compilation compilation
}
n++;
}

return resolvedLocations;
}

[GeneratedRegex("src(?<separator>[\\\\\\/]{1})coreclr")]
Expand Down