Skip to content

Commit

Permalink
remove documentation object abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed May 6, 2024
1 parent 576f5e9 commit a365f76
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 44 deletions.
5 changes: 5 additions & 0 deletions src/Doki.Abstractions/AssemblyDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ public NamespaceDocumentation[] Namespaces
get => InternalNamespaces;
init => InternalNamespaces = value;
}

public AssemblyDocumentation()
{
Content = DocumentationContentType.Assembly;
}
}
5 changes: 5 additions & 0 deletions src/Doki.Abstractions/CodeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public sealed record CodeBlock : DocumentationObject
/// Gets the code of the block.
/// </summary>
public string Code { get; internal init; } = null!;

public CodeBlock()
{
Content = DocumentationContentType.CodeBlock;
}
}
20 changes: 18 additions & 2 deletions src/Doki.Abstractions/DocumentationContentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,82 @@ public enum DocumentationContentType
/// The root of the documentation, containing all assemblies/packages.
/// </summary>
Root,

/// <summary>
/// An assembly in the documentation.
/// </summary>
Assembly,

/// <summary>
/// A namespace in the documentation.
/// </summary>
Namespace,

/// <summary>
/// A type reference in the documentation.
/// </summary>
TypeReference,

/// <summary>
/// A class in the documentation.
/// </summary>
Class,

/// <summary>
/// An enum in the documentation.
/// </summary>
Enum,

/// <summary>
/// A struct in the documentation.
/// </summary>
Struct,

/// <summary>
/// An interface in the documentation.
/// </summary>
Interface,

/// <summary>
/// A type.
/// </summary>
Type,

/// <summary>
/// A generic type argument.
/// </summary>
GenericTypeArgument,

/// <summary>
/// A xml documentation object.
/// A xml content.
/// </summary>
XmlDocumentation,
Xml,

/// <summary>
/// A text content.
/// </summary>
Text,

/// <summary>
/// A code block.
/// </summary>
CodeBlock,

/// <summary>
/// A link.
/// </summary>
Link,

/// <summary>
/// A constructor in the documentation.
/// </summary>
Constructor,

/// <summary>
/// A field in the documentation.
/// </summary>
Field,

/// <summary>
/// A property in the documentation.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Doki.Abstractions/DocumentationObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract record DocumentationObject
/// <summary>
/// Gets the content type of the documentation object.
/// </summary>
public DocumentationContentType Content { get; internal init; }
public DocumentationContentType Content { get; protected set; }

protected DocumentationObject()
{
Expand Down
5 changes: 5 additions & 0 deletions src/Doki.Abstractions/GenericTypeArgumentDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public sealed record GenericTypeArgumentDocumentation : TypeDocumentationReferen
/// Gets a value indicating whether the generic type argument is a generic parameter.
/// </summary>
public bool IsGenericParameter { get; internal init; }

public GenericTypeArgumentDocumentation()
{
Content = DocumentationContentType.GenericTypeArgument;
}
}
5 changes: 5 additions & 0 deletions src/Doki.Abstractions/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public sealed record Link : DocumentationObject
/// Gets the text of the link.
/// </summary>
public string Text { get; init; } = null!;

public Link()
{
Content = DocumentationContentType.Link;
}
}
22 changes: 1 addition & 21 deletions src/Doki.Abstractions/MemberDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,5 @@ public record MemberDocumentation : DocumentationObject
/// </summary>
public DocumentationObject? Summary { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="MemberDocumentation"/> class.
/// </summary>
public MemberDocumentation()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MemberDocumentation"/> class.
/// </summary>
/// <param name="obj">The object to copy.</param>
/// <exception cref="ArgumentException"></exception>
public MemberDocumentation(MemberDocumentation obj) : base(obj)
{
ArgumentNullException.ThrowIfNull(obj);

Name = obj.Name ?? throw new ArgumentException("MemberDocumentation.Name cannot be null.", nameof(obj));
Namespace = obj.Namespace;
Assembly = obj.Assembly;
Summary = obj.Summary;
}
public new DocumentationContentType Content { get; internal init; }
}
5 changes: 5 additions & 0 deletions src/Doki.Abstractions/NamespaceDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public TypeDocumentation[] Types
get => InternalTypes;
init => InternalTypes = value;
}

public NamespaceDocumentation()
{
Content = DocumentationContentType.Namespace;
}
}
5 changes: 5 additions & 0 deletions src/Doki.Abstractions/TextContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ public sealed record TextContent : DocumentationObject
/// Gets the text content.
/// </summary>
public string Text { get; internal init; } = null!;

public TextContent()
{
Content = DocumentationContentType.Text;
}
}
2 changes: 2 additions & 0 deletions src/Doki.Abstractions/TypeDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public sealed record TypeDocumentation : TypeDocumentationReference
/// Gets the methods of the type.
/// </summary>
public MemberDocumentation[] Methods { get; internal set; } = [];

public new DocumentationContentType Content { get; internal init; }
}
21 changes: 21 additions & 0 deletions src/Doki.Abstractions/XmlDocumentation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Doki;

public sealed record XmlDocumentation : DocumentationObject
{
public string Name { get; init; } = null!;

public string? Description { get; init; }

internal DocumentationObject[] InternalContents = [];

public DocumentationObject[] Contents
{
get => InternalContents;
init => InternalContents = value;
}

public XmlDocumentation()
{
Content = DocumentationContentType.Xml;
}
}
26 changes: 10 additions & 16 deletions src/Doki/DocumentationGenerator.Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ private IEnumerable<GenericTypeArgumentDocumentation> BuildGenericTypeArgumentDo
Id = genericArgumentId,
Name = genericArgument.GetSanitizedName(),
FullName = genericArgument.GetSanitizedName(true),
Content = DocumentationContentType.GenericTypeArgument,
Namespace = genericArgument.Namespace,
Assembly = genericArgumentAssembly.Name,
IsGeneric = genericArgument.IsGenericType,
Expand Down Expand Up @@ -263,17 +262,16 @@ private IEnumerable<MemberDocumentation> BuildMethodDocumentation(Type type, Doc
}
}

private DocumentationObject BuildXmlDocumentation(XPathNavigator navigator, DocumentationObject parent)
private XmlDocumentation BuildXmlDocumentation(XPathNavigator navigator, DocumentationObject parent)
{
var content = new ContentList
var content = new XmlDocumentation
{
Id = navigator.BaseURI,
Content = DocumentationContentType.XmlDocumentation,
Parent = parent,
Name = navigator.Name
};

var items = new List<DocumentationObject>();
var contents = new List<DocumentationObject>();
var nodes = navigator.SelectChildren(XPathNodeType.All);
while (nodes.MoveNext())
{
Expand All @@ -289,12 +287,11 @@ private DocumentationObject BuildXmlDocumentation(XPathNavigator navigator, Docu
case "see":
var cref = node.GetAttribute("cref", string.Empty);
var href = node.GetAttribute("href", string.Empty);
if (cref != string.Empty) items.Add(BuildCRefDocumentation(cref, content));
if (cref != string.Empty) contents.Add(BuildCRefDocumentation(cref, content));
else if (href != string.Empty)
items.Add(new Link
contents.Add(new Link
{
Id = node.BaseURI,
Content = DocumentationContentType.Link,
Parent = content,
Url = href,
Text = node.Value.TrimIndentation()
Expand All @@ -303,26 +300,24 @@ private DocumentationObject BuildXmlDocumentation(XPathNavigator navigator, Docu
case "code":
var language = node.GetAttribute("lang", string.Empty);
if (language == string.Empty) language = null;
items.Add(new CodeBlock
contents.Add(new CodeBlock
{
Id = node.BaseURI,
Content = DocumentationContentType.CodeBlock,
Parent = content,
Language = language,
Code = node.Value.TrimIndentation().TrimEnd()
});
break;
default:
items.Add(BuildXmlDocumentation(node, content));
contents.Add(BuildXmlDocumentation(node, content));
break;
}

break;
case XPathNodeType.Text:
items.Add(new TextContent
contents.Add(new TextContent
{
Id = node.BaseURI,
Content = DocumentationContentType.Text,
Parent = content,
Text = node.Value.TrimIndentation()
});
Expand All @@ -332,7 +327,7 @@ private DocumentationObject BuildXmlDocumentation(XPathNavigator navigator, Docu
}
}

content.Items = items.ToArray();
content.InternalContents = contents.ToArray();
return content;
}

Expand All @@ -343,7 +338,7 @@ private DocumentationObject BuildCRefDocumentation(string cref, DocumentationObj
var typeName = cref[2..];
if (!typeName.Contains('.'))
{
var @namespace = parent.TryGetParent<ContentList>(DocumentationContentType.Namespace);
var @namespace = parent.TryGetParent<NamespaceDocumentation>(DocumentationContentType.Namespace);
if (@namespace != null) typeName = $"{@namespace.Id}.{typeName}";
}

Expand All @@ -352,7 +347,6 @@ private DocumentationObject BuildCRefDocumentation(string cref, DocumentationObj
return new TextContent
{
Id = typeName,
Content = DocumentationContentType.Text,
Parent = parent,
Text = typeName
};
Expand Down
5 changes: 1 addition & 4 deletions src/Doki/DocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ await GenerateAssemblyDocumentationAsync(new GeneratorContext<Assembly>
Id = assemblyId,
Name = assemblyId,
Parent = context.Parent,
Content = DocumentationContentType.Assembly,
Description = description,
FileName = context.Current.Location.Split(Path.DirectorySeparatorChar).Last(),
Version = assemblyName.Version?.ToString(),
Expand All @@ -245,8 +244,7 @@ await GenerateAssemblyDocumentationAsync(new GeneratorContext<Assembly>
{
Id = @namespace,
Name = @namespace,
Parent = assemblyDocumentation,
Content = DocumentationContentType.Namespace
Parent = assemblyDocumentation
};

var typeItems = new List<TypeDocumentation>();
Expand Down Expand Up @@ -356,7 +354,6 @@ private async Task<TypeDocumentation> GenerateTypeDocumentationAsync(GeneratorCo
var typeReference = new TypeDocumentationReference
{
Id = baseType.GetXmlDocumentationId(),
Content = DocumentationContentType.TypeReference,
Parent = baseParent,
Name = baseType.GetSanitizedName(),
FullName = baseType.GetSanitizedName(true),
Expand Down

0 comments on commit a365f76

Please sign in to comment.