From 6aed696e96b59066f1554bb089d5ed9a84cef032 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Sun, 5 Jan 2014 23:11:29 +0100 Subject: [PATCH] Suppressing 'unknown type' warning if a type is used as a base class, but never mentioned in the documentation. --- .../CreateApiDescription/CodeGraph/MoaiType.cs | 4 ++-- MoaiUtils/CreateApiDescription/MoaiCodeParser.cs | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/MoaiUtils/CreateApiDescription/CodeGraph/MoaiType.cs b/MoaiUtils/CreateApiDescription/CodeGraph/MoaiType.cs index a62cd59..636dc11 100644 --- a/MoaiUtils/CreateApiDescription/CodeGraph/MoaiType.cs +++ b/MoaiUtils/CreateApiDescription/CodeGraph/MoaiType.cs @@ -7,7 +7,7 @@ public class MoaiType : INamedEntity, IDocumentedEntity { public MoaiType() { Members = new List(); BaseTypes = new List(); - ReferencingFilePositions = new SortedSet(); + DocumentationReferences = new SortedSet(); } public TypePosition TypePosition { get; set; } @@ -16,7 +16,7 @@ public MoaiType() { public string Description { get; set; } public List Members { get; private set; } public List BaseTypes { get; private set; } - public SortedSet ReferencingFilePositions { get; private set; } + public SortedSet DocumentationReferences { get; private set; } public string Signature { get { diff --git a/MoaiUtils/CreateApiDescription/MoaiCodeParser.cs b/MoaiUtils/CreateApiDescription/MoaiCodeParser.cs index 75f2581..a7ca95e 100644 --- a/MoaiUtils/CreateApiDescription/MoaiCodeParser.cs +++ b/MoaiUtils/CreateApiDescription/MoaiCodeParser.cs @@ -47,7 +47,9 @@ public void Parse(DirectoryInfo moaiSourceDirectory, PathFormat messagePathForma } // Check if we have information on all referenced classes - foreach (MoaiType type in typesByName.Values.ToArray()) { + IEnumerable typesReferencedInDocumentation = typesByName.Values + .Where(type => type.DocumentationReferences.Any()); + foreach (MoaiType type in typesReferencedInDocumentation.ToArray()) { WarnIfSpeculative(type); } @@ -100,12 +102,12 @@ private void WarnIfSpeculative(MoaiType type) { } StringBuilder message = new StringBuilder(); - message.AppendFormat("Found references to missing or undocumented type '{0}'.", type.Name); + message.AppendFormat("Documentation mentions missing or undocumented type '{0}'.", type.Name); if (nameProposal != null) { message.AppendFormat(" Should this be '{0}'?", nameProposal); } message.AppendLine(); - foreach (FilePosition referencingFilePosition in type.ReferencingFilePositions) { + foreach (FilePosition referencingFilePosition in type.DocumentationReferences) { message.AppendFormat("> {0}", referencingFilePosition); message.AppendLine(); } @@ -173,12 +175,12 @@ private void ParseMoaiCodeFiles(DirectoryInfo moaiSourceDirectory, PathFormat me int\s+(?[A-Za-z0-9_]+)\s*::\s*(?[A-Za-z0-9_]+) )", RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptions.Compiled); - private MoaiType GetOrCreateType(string typeName, FilePosition filePosition) { + private MoaiType GetOrCreateType(string typeName, FilePosition documentationPosition) { MoaiType result = typesByName.ContainsKey(typeName) ? typesByName[typeName] : typesByName[typeName] = new MoaiType { Name = typeName }; - if (filePosition != null) { - result.ReferencingFilePositions.Add(filePosition); + if (documentationPosition != null) { + result.DocumentationReferences.Add(documentationPosition); } return result; } @@ -224,7 +226,7 @@ private void ParseMoaiFile(string code, FilePosition filePosition) { MoaiType[] baseTypes = match.Groups["baseClassName"].Captures .Cast() .Where(capture => !capture.Value.Contains("<")) - .Select(capture => GetOrCreateType(capture.Value, documentationPosition)) + .Select(capture => GetOrCreateType(capture.Value, null)) .ToArray(); var typePosition = (TypePosition) documentationPosition;