Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossanlop committed Jul 27, 2023
1 parent cccca92 commit 2ebdc98
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 1,001 deletions.
223 changes: 23 additions & 200 deletions src/PortToTripleSlash/src/libraries/Docs/DocsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ internal abstract class DocsAPI : IDocsAPI
Params.Any(p => p.Value.IsDocsEmpty()) ||
TypeParams.Any(tp => tp.Value.IsDocsEmpty());

public abstract bool Changed { get; set; }
public string FilePath { get; set; } = string.Empty;

public string DocId => _docId ??= GetApiSignatureDocId();
Expand All @@ -49,14 +48,7 @@ public List<DocsParameter> Parameters
if (_parameters == null)
{
XElement? xeParameters = XERoot.Element("Parameters");
if (xeParameters == null)
{
_parameters = new();
}
else
{
_parameters = xeParameters.Elements("Parameter").Select(x => new DocsParameter(x)).ToList();
}
_parameters = xeParameters == null ? (List<DocsParameter>)new() : xeParameters.Elements("Parameter").Select(x => new DocsParameter(x)).ToList();
}
return _parameters;
}
Expand All @@ -72,222 +64,59 @@ public List<DocsTypeParameter> TypeParameters
if (_typeParameters == null)
{
XElement? xeTypeParameters = XERoot.Element("TypeParameters");
if (xeTypeParameters == null)
{
_typeParameters = new();
}
else
{
_typeParameters = xeTypeParameters.Elements("TypeParameter").Select(x => new DocsTypeParameter(x)).ToList();
}
_typeParameters = xeTypeParameters == null ? (List<DocsTypeParameter>)new() : xeTypeParameters.Elements("TypeParameter").Select(x => new DocsTypeParameter(x)).ToList();
}
return _typeParameters;
}
}

public XElement Docs
{
get
{
return XERoot.Element("Docs") ?? throw new NullReferenceException($"Docs section was null in {FilePath}");
}
}
public XElement Docs => XERoot.Element("Docs") ?? throw new NullReferenceException($"Docs section was null in {FilePath}");

/// <summary>
/// The param elements found inside the Docs section.
/// </summary>
public List<DocsParam> Params
{
get
{
if (_params == null)
{
if (Docs != null)
{
_params = Docs.Elements("param").Select(x => new DocsParam(this, x)).ToList();
}
else
{
_params = new List<DocsParam>();
}
}
return _params;
}
}
public List<DocsParam> Params => _params ??= Docs != null ? Docs.Elements("param").Select(x => new DocsParam(this, x)).ToList() : new List<DocsParam>();

/// <summary>
/// The typeparam elements found inside the Docs section.
/// </summary>
public List<DocsTypeParam> TypeParams
{
get
{
if (_typeParams == null)
{
if (Docs != null)
{
_typeParams = Docs.Elements("typeparam").Select(x => new DocsTypeParam(this, x)).ToList();
}
else
{
_typeParams = new();
}
}
return _typeParams;
}
}
public List<DocsTypeParam> TypeParams => _typeParams ??= Docs != null ? Docs.Elements("typeparam").Select(x => new DocsTypeParam(this, x)).ToList() : (List<DocsTypeParam>)new();

public List<string> SeeAlsoCrefs
{
get
{
if (_seeAlsoCrefs == null)
{
if (Docs != null)
{
_seeAlsoCrefs = Docs.Elements("seealso").Select(x => XmlHelper.GetAttributeValue(x, "cref").DocIdEscaped()).ToList();
}
else
{
_seeAlsoCrefs = new();
}
}
return _seeAlsoCrefs;
}
}
public List<string> SeeAlsoCrefs => _seeAlsoCrefs ??= Docs != null ? Docs.Elements("seealso").Select(x => XmlHelper.GetAttributeValue(x, "cref").DocIdEscaped()).ToList() : (List<string>)new();

public List<string> AltMembers
{
get
{
if (_altMemberCrefs == null)
{
if (Docs != null)
{
_altMemberCrefs = Docs.Elements("altmember").Select(x => XmlHelper.GetAttributeValue(x, "cref").DocIdEscaped()).ToList();
}
else
{
_altMemberCrefs = new();
}
}
return _altMemberCrefs;
}
}
public List<string> AltMembers => _altMemberCrefs ??= Docs != null ? Docs.Elements("altmember").Select(x => XmlHelper.GetAttributeValue(x, "cref").DocIdEscaped()).ToList() : (List<string>)new();

public List<DocsRelated> Relateds
{
get
{
if (_relateds == null)
{
if (Docs != null)
{
_relateds = Docs.Elements("related").Select(x => new DocsRelated(this, x)).ToList();
}
else
{
_relateds = new();
}
}
return _relateds;
}
}
public List<DocsRelated> Relateds => _relateds ??= Docs != null ? Docs.Elements("related").Select(x => new DocsRelated(this, x)).ToList() : (List<DocsRelated>)new();

public abstract string Summary { get; }

public abstract string Value { get; }

public abstract string Summary { get; set; }
public abstract string Value { get; set; }
public abstract string ReturnType { get; }
public abstract string Returns { get; set; }
public abstract string Remarks { get; set; }

public abstract List<DocsException> Exceptions { get; }
public abstract string Returns { get; }

public List<DocsAssemblyInfo> AssemblyInfos
{
get
{
if (_assemblyInfos == null)
{
_assemblyInfos = new List<DocsAssemblyInfo>();
}
return _assemblyInfos;
}
}
public abstract string Remarks { get; }

public DocsParam SaveParam(XElement xeIntelliSenseXmlParam)
{
XElement xeDocsParam = new XElement(xeIntelliSenseXmlParam.Name);
xeDocsParam.ReplaceAttributes(xeIntelliSenseXmlParam.Attributes());
XmlHelper.SaveFormattedAsXml(xeDocsParam, xeIntelliSenseXmlParam.Value);
DocsParam docsParam = new DocsParam(this, xeDocsParam);
Changed = true;
return docsParam;
}
public abstract List<DocsException> Exceptions { get; }

public APIKind Kind
{
get
{
return this switch
{
DocsMember _ => APIKind.Member,
DocsType _ => APIKind.Type,
_ => throw new ArgumentException("Unrecognized IDocsAPI object")
};
}
}
public List<DocsAssemblyInfo> AssemblyInfos => _assemblyInfos ??= new List<DocsAssemblyInfo>();

public DocsTypeParam AddTypeParam(string name, string value)
public APIKind Kind => this switch
{
XElement typeParam = new XElement("typeparam");
typeParam.SetAttributeValue("name", name);
XmlHelper.AddChildFormattedAsXml(Docs, typeParam, value);
Changed = true;
return new DocsTypeParam(this, typeParam);
}
DocsMember _ => APIKind.Member,
DocsType _ => APIKind.Type,
_ => throw new ArgumentException("Unrecognized IDocsAPI object")
};

// For Types, these elements are called TypeSignature.
// For Members, these elements are called MemberSignature.
protected abstract string GetApiSignatureDocId();

protected string GetNodesInPlainText(string name)
{
if (TryGetElement(name, addIfMissing: false, out XElement? element))
{
if (name == "remarks")
{
XElement? formatElement = element.Element("format");
if (formatElement != null)
{
element = formatElement;
}
}

return XmlHelper.GetNodesInPlainText(element);
}
return string.Empty;
}

protected void SaveFormattedAsXml(string name, string value, bool addIfMissing)
{
if (TryGetElement(name, addIfMissing, out XElement? element))
{
XmlHelper.SaveFormattedAsXml(element, value);
Changed = true;
}
}

protected void SaveFormattedAsMarkdown(string name, string value, bool addIfMissing, bool isMember)
{
if (TryGetElement(name, addIfMissing, out XElement? element))
{
XmlHelper.SaveFormattedAsMarkdown(element, value, isMember);
Changed = true;
}
}
protected string GetNodesInPlainText(string name) => TryGetElement(name, out XElement? element) ? XmlHelper.GetNodesInPlainText(name, element) : string.Empty;

// Returns true if the element existed or had to be created with "To be added." as value. Returns false the element was not found and a new one was not created.
private bool TryGetElement(string name, bool addIfMissing, [NotNullWhen(returnValue: true)] out XElement? element)
private bool TryGetElement(string name, [NotNullWhen(returnValue: true)] out XElement? element)
{
element = null;

Expand All @@ -298,12 +127,6 @@ private bool TryGetElement(string name, bool addIfMissing, [NotNullWhen(returnVa

element = Docs.Element(name);

if (element == null && addIfMissing)
{
element = new XElement(name);
XmlHelper.AddChildFormattedAsXml(Docs, element, Configuration.ToBeAdded);
}

return element != null;
}
}
Expand Down
28 changes: 5 additions & 23 deletions src/PortToTripleSlash/src/libraries/Docs/DocsAssemblyInfo.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 @@ -10,31 +10,13 @@ namespace ApiDocsSync.PortToTripleSlash.Docs
internal class DocsAssemblyInfo
{
private readonly XElement XEAssemblyInfo;
public string AssemblyName
{
get
{
return XmlHelper.GetChildElementValue(XEAssemblyInfo, "AssemblyName");
}
}

public string AssemblyName => XmlHelper.GetChildElementValue(XEAssemblyInfo, "AssemblyName");

private List<string>? _assemblyVersions;
public List<string> AssemblyVersions
{
get
{
if (_assemblyVersions == null)
{
_assemblyVersions = XEAssemblyInfo.Elements("AssemblyVersion").Select(x => XmlHelper.GetNodesInPlainText(x)).ToList();
}
return _assemblyVersions;
}
}
public List<string> AssemblyVersions => _assemblyVersions ??= XEAssemblyInfo.Elements("AssemblyVersion").Select(x => XmlHelper.GetNodesInPlainText("AssemblyVersion", x)).ToList();

public DocsAssemblyInfo(XElement xeAssemblyInfo)
{
XEAssemblyInfo = xeAssemblyInfo;
}
public DocsAssemblyInfo(XElement xeAssemblyInfo) => XEAssemblyInfo = xeAssemblyInfo;

public override string ToString() => AssemblyName;
}
Expand Down
24 changes: 5 additions & 19 deletions src/PortToTripleSlash/src/libraries/Docs/DocsAttribute.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.Xml.Linq;
Expand All @@ -9,24 +9,10 @@ internal class DocsAttribute
{
private readonly XElement XEAttribute;

public string FrameworkAlternate
{
get
{
return XmlHelper.GetAttributeValue(XEAttribute, "FrameworkAlternate");
}
}
public string AttributeName
{
get
{
return XmlHelper.GetChildElementValue(XEAttribute, "AttributeName");
}
}
public string FrameworkAlternate => XmlHelper.GetAttributeValue(XEAttribute, "FrameworkAlternate");

public DocsAttribute(XElement xeAttribute)
{
XEAttribute = xeAttribute;
}
public string AttributeName => XmlHelper.GetChildElementValue(XEAttribute, "AttributeName");

public DocsAttribute(XElement xeAttribute) => XEAttribute = xeAttribute;
}
}
Loading

0 comments on commit 2ebdc98

Please sign in to comment.