Skip to content

Commit

Permalink
v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
saucecontrol committed Dec 19, 2023
1 parent 6e5438b commit e8ce562
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
.vs
bin
obj
out
TestResults
BenchmarkDotNet.Artifacts
8 changes: 4 additions & 4 deletions build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Owners>SauceControl</Owners>
<Authors>Clinton Ingram</Authors>
<RepositoryUrl>https://github.com/saucecontrol/InheritDoc</RepositoryUrl>
<Copyright>Copyright © 2019-$([System.DateTime]::Today.Year) $(Authors)</Copyright>
<Copyright>Copyright © 2019-$([System.DateTime]::Today.Year) $(Authors) and Contributors</Copyright>
<Title>Automatic Documentation Inheritance Processing</Title>
<Description>Automatically replace &lt;inheritdoc /&gt; tags with inherited documentation at build time. Integrates with MSBuild, so no command line tool or VS add-on is required.</Description>

Expand All @@ -13,7 +13,7 @@
<AssemblyTitle>$(MSBuildProjectName)</AssemblyTitle>
<Product>$(MSBuildProjectName)</Product>

<PackageIcon>$(Owners).png</PackageIcon>
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
Expand Down Expand Up @@ -57,8 +57,8 @@
</PropertyGroup>

<ItemGroup Condition="'$(Configuration)'=='Dist' Or '$(Configuration)'=='Coverage'">
<None Include="$(MSBuildThisFileDirectory)$(Owners).png" Pack="true" PackagePath="/" />
<None Include="$(ProjectRoot)readme.md" Pack="true" PackagePath="/" />
<None Include="$(MSBuildThisFileDirectory)$(PackageIcon)" Pack="true" PackagePath="/" />
<None Include="$(ProjectRoot)$(PackageReadmeFile)" Pack="true" PackagePath="/" />
<None Include="$(RepositoryRoot)license" Pack="true" PackagePath="/" />
<None Include="$(RepositoryRoot)third-party-notices" Pack="true" PackagePath="/" />
<SourceRoot Include="$(RepositoryRoot)" />
Expand Down
Binary file removed build/SauceControl.png
Binary file not shown.
Binary file added build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 35 additions & 31 deletions src/InheritDoc/InheritDocProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,34 +226,30 @@ static XDocument loadDoc(string path)
md.SetAttributeValue(DocAttributeNames._gencode, true);
}

if (methDocs.Descendants(DocElementNames.InheritDoc).Any())
if (methDocs.Any() && (m.IsConstructor || methDocs.Descendants(DocElementNames.InheritDoc).Any()))
{
logger.Write(ILogger.Severity.Diag, "Processing DocID: " + memID);

var crefs = methDocs.Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(c => !string.IsNullOrWhiteSpace(c)).ToHashSet();
var bases = (om is not null ? (new[] { om }) : [ ]).Concat(m.GetBaseCandidates()).ToList();

// Fix up docs for C# primary constructors, which do not have docs of their own and therefore should not get warnings for missing base.
if (m.IsConstructor && bases.Count == 0 && crefs.Count == 0 && memDocs.Any())
// Fix up docs for C# primary constructors, which result in type and constructor sharing docs.
if (m.IsConstructor && memDocs.Any())
{
var typeDoc = memDocs.First();
var ctorDoc = methDocs.First();
ctorDoc.SetAttributeValue(DocAttributeNames.Name, typeID);

// Type and constructor having identical docs is the surest sign of a primary constructor.
// We'll find a suitable base for the ctor and inject a cref pointing to it.
if (nodeComparer.Equals(typeDoc, ctorDoc))
{
string cref = typeID;
if (m.GetBaseConstructor() is MethodDefinition bc && bc.GetDocID().SelectMany(d => findDocsByID(docMembers, d)).FirstOrDefault() is XElement bcd)
cref = (string)bcd.Attribute(DocAttributeNames.Name);
// Find a suitable base for the ctor and inject a cref in order to avoid warning for missing base.
if (ctorDoc.Elements(DocElementNames.InheritDoc).Any())
{
string cref = typeID;
if (m.GetBaseConstructor() is MethodDefinition bc && bc.GetDocID().SelectMany(d => findDocsByID(docMembers, d)).FirstOrDefault() is XElement bcd)
cref = (string)bcd.Attribute(DocAttributeNames.Name);

crefs.Add(cref);
foreach (var d in methDocs.Descendants(DocElementNames.InheritDoc))
d.SetElementValue(DocAttributeNames.Cref, cref);
foreach (var d in ctorDoc.Elements(DocElementNames.InheritDoc).Where(i => !i.HasAttribute(DocAttributeNames.Cref)))
d.SetAttributeValue(DocAttributeNames.Cref, cref);
}

// `param` elements meant for the constructor will also appear in the type's docs.
foreach (var param in typeDoc.Descendants(DocElementNames.Param).ToList())
// Remove `param` elements meant for the constructor, which also appear in the type's docs.
foreach (var param in typeDoc.Elements(DocElementNames.Param).ToList())
{
if ((param.PreviousNode?.IsWhiteSpace()).GetValueOrDefault())
param.PreviousNode!.Remove();
Expand All @@ -265,23 +261,31 @@ static XDocument loadDoc(string path)
ctorDoc.SetAttributeValue(DocAttributeNames.Name, memID);
}

var dml = new List<DocMatch>();
foreach (var (bm, cref) in bases.SelectMany(bm => bm.GetDocID().Select(d => (bm, d))))
if (methDocs.Descendants(DocElementNames.InheritDoc).Any())
{
if (dml.Count == 0 || crefs.Contains(cref))
dml.Add(new DocMatch(cref, m, bm));
logger.Write(ILogger.Severity.Diag, "Processing DocID: " + memID);

if (crefs.Count == 0)
break;
}
var bases = (om is not null ? (new[] { om }) : []).Concat(m.GetBaseCandidates()).ToList();
var crefs = methDocs.Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(c => !string.IsNullOrWhiteSpace(c)).ToHashSet();
var dml = new List<DocMatch>();

foreach (var cref in crefs.Where(c => !dml.Any(dm => dm.Cref == c)))
dml.Add(new DocMatch(cref, m));
foreach (var (bm, cref) in bases.SelectMany(bm => bm.GetDocID().Select(d => (bm, d))))
{
if (dml.Count == 0 || crefs.Contains(cref))
dml.Add(new DocMatch(cref, m, bm));

if (dml.Count > 0)
docMap.Add(memID, dml);
else
logger.Write(ILogger.Severity.Info, "No inherit candidate for: " + memID);
if (crefs.Count == 0)
break;
}

foreach (var cref in crefs.Where(c => !dml.Any(dm => dm.Cref == c)))
dml.Add(new DocMatch(cref, m));

if (dml.Count > 0)
docMap.Add(memID, dml);
else
logger.Write(ILogger.Severity.Info, "No inherit candidate for: " + memID);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/InheritDoc.Test/InheritDoc.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>
Expand Down

0 comments on commit e8ce562

Please sign in to comment.