You've already forked linux-packaging-mono
Imported Upstream version 5.2.0.179
Former-commit-id: a536d4f20e27294d8bbc2184d75f3a22364f7ba1
This commit is contained in:
parent
966bba02bb
commit
fad71374d0
85
external/api-doc-tools/mdoc/Mono.Documentation/Frameworks/AssemblySet.cs
vendored
Normal file
85
external/api-doc-tools/mdoc/Mono.Documentation/Frameworks/AssemblySet.cs
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Mono.Cecil;
|
||||
|
||||
namespace Mono.Documentation
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a set of assemblies that we want to document
|
||||
/// </summary>
|
||||
class AssemblySet : IDisposable
|
||||
{
|
||||
readonly DefaultAssemblyResolver resolver = new DefaultAssemblyResolver ();
|
||||
HashSet<string> assemblyPaths = new HashSet<string> ();
|
||||
HashSet<string> assemblySearchPaths = new HashSet<string> ();
|
||||
HashSet<string> forwardedTypes = new HashSet<string> ();
|
||||
|
||||
public AssemblySet (string path) : this (new string[] { path }) { }
|
||||
|
||||
public AssemblySet (IEnumerable<string> paths) : this ("Default", paths, new string[0]) { }
|
||||
|
||||
public AssemblySet (string name, IEnumerable<string> paths, IEnumerable<string> resolverSearchPaths)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
foreach (var path in paths)
|
||||
assemblyPaths.Add (path);
|
||||
|
||||
// add default search paths
|
||||
var assemblyDirectories = paths
|
||||
.Where (p => p.Contains (Path.DirectorySeparatorChar))
|
||||
.Select (p => Path.GetDirectoryName (p));
|
||||
|
||||
foreach (var searchPath in resolverSearchPaths.Union(assemblyDirectories))
|
||||
assemblySearchPaths.Add (searchPath);
|
||||
|
||||
char oppositeSeparator = Path.DirectorySeparatorChar == '/' ? '\\' : '/';
|
||||
Func<string, string> sanitize = p =>
|
||||
p.Replace (oppositeSeparator, Path.DirectorySeparatorChar);
|
||||
|
||||
foreach (var searchPath in assemblySearchPaths.Select(sanitize))
|
||||
resolver.AddSearchDirectory (searchPath);
|
||||
}
|
||||
|
||||
public string Name { get; private set; }
|
||||
|
||||
public IEnumerable<AssemblyDefinition> Assemblies { get { return this.LoadAllAssemblies ().Where(a => a != null); } }
|
||||
public IEnumerable<string> AssemblyPaths { get { return this.assemblyPaths; } }
|
||||
|
||||
/// <returns><c>true</c>, if in set was contained in the set of assemblies, <c>false</c> otherwise.</returns>
|
||||
/// <param name="name">An assembly file name</param>
|
||||
public bool Contains (string name)
|
||||
{
|
||||
return assemblyPaths.Any (p => Path.GetFileName (p) == name);
|
||||
}
|
||||
|
||||
/// <summary>Tells whether an already enumerated AssemblyDefinition, contains the type.</summary>
|
||||
/// <param name="name">Type name</param>
|
||||
public bool ContainsForwardedType (string name)
|
||||
{
|
||||
return forwardedTypes.Contains (name);
|
||||
}
|
||||
|
||||
public void Dispose () => resolver.Dispose ();
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return string.Format ("[AssemblySet: Name={0}, Assemblies={1}]", Name, assemblyPaths.Count);
|
||||
}
|
||||
|
||||
IEnumerable<AssemblyDefinition> LoadAllAssemblies ()
|
||||
{
|
||||
foreach (var path in this.assemblyPaths) {
|
||||
var assembly = MDocUpdater.Instance.LoadAssembly (path, this.resolver);
|
||||
if (assembly != null) {
|
||||
foreach (var type in assembly.MainModule.ExportedTypes.Where (t => t.IsForwarder).Select (t => t.FullName))
|
||||
forwardedTypes.Add (type);
|
||||
}
|
||||
yield return assembly;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
external/api-doc-tools/mdoc/Mono.Documentation/Frameworks/FrameworkEntry.cs
vendored
Normal file
50
external/api-doc-tools/mdoc/Mono.Documentation/Frameworks/FrameworkEntry.cs
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Rocks;
|
||||
|
||||
namespace Mono.Documentation
|
||||
{
|
||||
class FrameworkEntry
|
||||
{
|
||||
SortedSet<FrameworkTypeEntry> types = new SortedSet<FrameworkTypeEntry> ();
|
||||
|
||||
List<FrameworkEntry> allframeworks;
|
||||
|
||||
public FrameworkEntry (List<FrameworkEntry> frameworks)
|
||||
{
|
||||
allframeworks = frameworks;
|
||||
if (allframeworks == null)
|
||||
allframeworks = new List<FrameworkEntry> (0);
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public ISet<FrameworkTypeEntry> Types { get { return this.types; } }
|
||||
|
||||
public IEnumerable<FrameworkEntry> Frameworks { get { return this.allframeworks; } }
|
||||
|
||||
public static readonly FrameworkEntry Empty = new EmptyFrameworkEntry () { Name = "Empty" };
|
||||
|
||||
public virtual FrameworkTypeEntry ProcessType (TypeDefinition type)
|
||||
{
|
||||
|
||||
var entry = types.FirstOrDefault (t => t.Name.Equals (type.FullName));
|
||||
if (entry == null) {
|
||||
var docid = DocCommentId.GetDocCommentId (type);
|
||||
entry = new FrameworkTypeEntry (this) { Id = docid, Name = type.FullName, Namespace = type.Namespace };
|
||||
types.Add (entry);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
public override string ToString () => this.Name;
|
||||
|
||||
class EmptyFrameworkEntry : FrameworkEntry
|
||||
{
|
||||
public EmptyFrameworkEntry () : base (null) { }
|
||||
public override FrameworkTypeEntry ProcessType (TypeDefinition type) { return FrameworkTypeEntry.Empty; }
|
||||
}
|
||||
}
|
||||
}
|
89
external/api-doc-tools/mdoc/Mono.Documentation/Frameworks/FrameworkIndex.cs
vendored
Normal file
89
external/api-doc-tools/mdoc/Mono.Documentation/Frameworks/FrameworkIndex.cs
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
using Mono.Cecil;
|
||||
|
||||
namespace Mono.Documentation
|
||||
{
|
||||
|
||||
class FrameworkIndex
|
||||
{
|
||||
List<FrameworkEntry> frameworks = new List<FrameworkEntry> ();
|
||||
string path;
|
||||
|
||||
public FrameworkIndex (string pathToFrameworks)
|
||||
{
|
||||
path = pathToFrameworks;
|
||||
}
|
||||
|
||||
public IList<FrameworkEntry> Frameworks {
|
||||
get {
|
||||
return this.frameworks;
|
||||
}
|
||||
}
|
||||
|
||||
public FrameworkEntry StartProcessingAssembly (AssemblyDefinition assembly)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace (this.path))
|
||||
return FrameworkEntry.Empty;
|
||||
|
||||
string assemblyPath = assembly.MainModule.FileName;
|
||||
string relativePath = assemblyPath.Replace (this.path, string.Empty);
|
||||
string shortPath = Path.GetDirectoryName (relativePath);
|
||||
if (shortPath.StartsWith (Path.DirectorySeparatorChar.ToString (), StringComparison.InvariantCultureIgnoreCase))
|
||||
shortPath = shortPath.Substring (1, shortPath.Length - 1);
|
||||
|
||||
|
||||
var entry = frameworks.FirstOrDefault (f => f.Name.Equals (shortPath));
|
||||
if (entry == null) {
|
||||
entry = new FrameworkEntry (frameworks) { Name = shortPath };
|
||||
frameworks.Add (entry);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
/// <summary>Writes the framework indices to disk.</summary>
|
||||
/// <param name="path">The folder where one file for every FrameworkEntry will be written.</param>
|
||||
public void WriteToDisk (string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace (this.path))
|
||||
return;
|
||||
|
||||
string outputPath = Path.Combine (path, "FrameworksIndex");
|
||||
if (!Directory.Exists (outputPath))
|
||||
Directory.CreateDirectory (outputPath);
|
||||
|
||||
foreach (var fx in this.frameworks) {
|
||||
|
||||
XDocument doc = new XDocument (
|
||||
new XElement("Framework",
|
||||
new XAttribute ("Name", fx.Name),
|
||||
fx.Types
|
||||
.GroupBy(t => t.Namespace)
|
||||
.Select(g => new XElement("Namespace",
|
||||
new XAttribute("Name", g.Key),
|
||||
g.Select (t => new XElement ("Type",
|
||||
new XAttribute ("Name", t.Name),
|
||||
new XAttribute("Id", t.Id),
|
||||
t.Members.Select (m =>
|
||||
new XElement ("Member",
|
||||
new XAttribute ("Id", m)))))))));
|
||||
|
||||
// now save the document
|
||||
string filePath = Path.Combine (outputPath, fx.Name + ".xml");
|
||||
|
||||
if (File.Exists (filePath))
|
||||
File.Delete (filePath);
|
||||
|
||||
var settings = new XmlWriterSettings { Indent = true };
|
||||
using (var writer = XmlWriter.Create (filePath, settings)) {
|
||||
doc.WriteTo (writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
80
external/api-doc-tools/mdoc/Mono.Documentation/Frameworks/FrameworkTypeEntry.cs
vendored
Normal file
80
external/api-doc-tools/mdoc/Mono.Documentation/Frameworks/FrameworkTypeEntry.cs
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Rocks;
|
||||
|
||||
namespace Mono.Documentation
|
||||
{
|
||||
class FrameworkTypeEntry : IComparable<FrameworkTypeEntry>
|
||||
{
|
||||
SortedSet<string> members = new SortedSet<string> ();
|
||||
SortedSet<string> memberscsharpsig = new SortedSet<string> ();
|
||||
|
||||
ILFullMemberFormatter formatter = new ILFullMemberFormatter ();
|
||||
|
||||
FrameworkEntry fx;
|
||||
|
||||
public static FrameworkTypeEntry Empty = new EmptyTypeEntry (FrameworkEntry.Empty) { Name = "Empty" };
|
||||
|
||||
public FrameworkTypeEntry (FrameworkEntry fx)
|
||||
{
|
||||
this.fx = fx;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Namespace { get; set; }
|
||||
public FrameworkEntry Framework { get { return fx; } }
|
||||
|
||||
public ISet<string> Members {
|
||||
get {
|
||||
return this.members;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessMember (MemberReference member)
|
||||
{
|
||||
var resolvedMember = member.Resolve ();
|
||||
if (resolvedMember != null) {
|
||||
var docid = DocCommentId.GetDocCommentId (resolvedMember);
|
||||
members.Add (docid);
|
||||
}
|
||||
else
|
||||
members.Add (member.FullName);
|
||||
|
||||
// this is for lookup purposes
|
||||
try {
|
||||
memberscsharpsig.Add(formatter.GetDeclaration(member));
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
|
||||
public bool ContainsCSharpSig (string sig)
|
||||
{
|
||||
return memberscsharpsig.Contains (sig);
|
||||
}
|
||||
|
||||
public override string ToString () => $"{this.Name} in {this.fx.Name}";
|
||||
|
||||
public int CompareTo (FrameworkTypeEntry other)
|
||||
{
|
||||
if (other == null) return -1;
|
||||
if (this.Name == null) return 1;
|
||||
|
||||
return string.Compare (this.Name, other.Name, StringComparison.CurrentCulture);
|
||||
}
|
||||
|
||||
public override bool Equals (object obj)
|
||||
{
|
||||
FrameworkTypeEntry other = obj as FrameworkTypeEntry;
|
||||
if (other == null) return false;
|
||||
return this.Name.Equals (other.Name);
|
||||
}
|
||||
|
||||
class EmptyTypeEntry : FrameworkTypeEntry
|
||||
{
|
||||
public EmptyTypeEntry (FrameworkEntry fx) : base (fx) { }
|
||||
public override void ProcessMember (MemberReference member) { }
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user