Skip to content

chore: Add support for derivedClasses metadata when implements interfaces #10632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
46 changes: 33 additions & 13 deletions src/Docfx.Dotnet/ManagedReference/Resolvers/SetDerivedClass.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Runtime.InteropServices;
using Docfx.DataContracts.ManagedReference;

namespace Docfx.Dotnet;
Expand All @@ -22,6 +23,7 @@ private void UpdateDerivedClassMapping(List<MetadataItem> items, Dictionary<stri
{
foreach (var item in items ?? Enumerable.Empty<MetadataItem>())
{
// Handle class inheritance
var inheritance = item.Inheritance;
if (inheritance is { Count: > 0 })
{
Expand All @@ -35,15 +37,30 @@ private void UpdateDerivedClassMapping(List<MetadataItem> items, Dictionary<stri
// ignore System.Object's derived class
if (superClass != "System.Object")
{
if (_derivedClassMapping.TryGetValue(superClass, out List<string> derivedClasses))
{
ref var derivedClasses = ref CollectionsMarshal.GetValueRefOrAddDefault(_derivedClassMapping, superClass, out var exists);
if (exists)
derivedClasses.Add(item.Name);
}
else
{
_derivedClassMapping.Add(superClass, [item.Name]);
}
derivedClasses = [item.Name];
}
}

// Handle interface implementations
var implements = item.Implements;
if (implements is { Count: > 0 })
{
var superClass = implements[implements.Count - 1];

if (reference.TryGetValue(superClass, out var referenceItem))
{
superClass = referenceItem.Definition ?? superClass;
}

ref var derivedClasses = ref CollectionsMarshal.GetValueRefOrAddDefault(_derivedClassMapping, superClass, out var exists);
if (exists)
derivedClasses.Add(item.Name);
else
derivedClasses = [item.Name];
}
}
}
Expand All @@ -52,13 +69,16 @@ private void AppendDerivedClass(List<MetadataItem> items)
{
foreach (var item in items ?? Enumerable.Empty<MetadataItem>())
{
if (item.Type == MemberType.Class)
switch (item.Type)
{
if (_derivedClassMapping.TryGetValue(item.Name, out List<string> derivedClasses))
{
derivedClasses.Sort();
item.DerivedClasses = derivedClasses;
}
case MemberType.Class:
case MemberType.Interface:
if (_derivedClassMapping.TryGetValue(item.Name, out List<string> derivedClasses))
{
derivedClasses.Sort();
item.DerivedClasses = derivedClasses;
}
continue;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,24 @@
}
]
},
"derivedClasses": [
{
"isEii": false,
"isExtensionMethod": false,
"specName": [
{
"lang": "csharp",
"value": "<xref uid=\"CSharp11.StaticAbstractMembersInInterfaces.RepeatSequence\" displayProperty=\"name\"/>"
},
{
"lang": "vb",
"value": "<xref uid=\"CSharp11.StaticAbstractMembersInInterfaces.RepeatSequence\" displayProperty=\"name\"/>"
}
],
"level": 0,
"index": 1
}
],
"level": 0,
"_systemKeys": [
"uid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,24 @@
}
]
},
"derivedClasses": [
{
"isEii": false,
"isExtensionMethod": false,
"specName": [
{
"lang": "csharp",
"value": "<xref uid=\"BuildFromProject.Class1.Issue8948\" displayProperty=\"name\"/>"
},
{
"lang": "vb",
"value": "<xref uid=\"BuildFromProject.Class1.Issue8948\" displayProperty=\"name\"/>"
}
],
"level": 0,
"index": 1
}
],
"level": 0,
"_appName": "Seed",
"_appTitle": "docfx seed website",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,24 @@
}
]
},
"derivedClasses": [
{
"isEii": false,
"isExtensionMethod": false,
"specName": [
{
"lang": "csharp",
"value": "<xref uid=\"BuildFromProject.Inheritdoc.Issue9736.JsonApiOptions\" displayProperty=\"name\"/>"
},
{
"lang": "vb",
"value": "<xref uid=\"BuildFromProject.Inheritdoc.Issue9736.JsonApiOptions\" displayProperty=\"name\"/>"
}
],
"level": 0,
"index": 1
}
],
"level": 0,
"_appName": "Seed",
"_appTitle": "docfx seed website",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,24 @@
}
]
},
"derivedClasses": [
{
"isEii": false,
"isExtensionMethod": false,
"specName": [
{
"lang": "csharp",
"value": "<xref uid=\"CatLibrary.Cat`2\" displayProperty=\"name\"/>"
},
{
"lang": "vb",
"value": "<xref uid=\"CatLibrary.Cat`2\" displayProperty=\"name\"/>"
}
],
"level": 0,
"index": 1
}
],
"level": 0,
"conceptual": "<h3 id=\"welcome-to-the-animal-world\" sourcefile=\"specs/CatLibrary.IAnimal.md\" sourcestartlinenumber=\"6\">Welcome to the <strong sourcefile=\"specs/CatLibrary.IAnimal.md\" sourcestartlinenumber=\"6\">Animal</strong> world!</h3>\n",
"_appName": "Seed",
Expand Down