Skip to content

Commit

Permalink
Suppressing 'unknown type' warning if a type is used as a base class,…
Browse files Browse the repository at this point in the history
… but never mentioned in the documentation.
  • Loading branch information
DanielSWolf committed Jan 5, 2014
1 parent 84ed8e4 commit 6aed696
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions MoaiUtils/CreateApiDescription/CodeGraph/MoaiType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class MoaiType : INamedEntity, IDocumentedEntity {
public MoaiType() {
Members = new List<MoaiTypeMember>();
BaseTypes = new List<MoaiType>();
ReferencingFilePositions = new SortedSet<FilePosition>();
DocumentationReferences = new SortedSet<FilePosition>();
}

public TypePosition TypePosition { get; set; }
Expand All @@ -16,7 +16,7 @@ public MoaiType() {
public string Description { get; set; }
public List<MoaiTypeMember> Members { get; private set; }
public List<MoaiType> BaseTypes { get; private set; }
public SortedSet<FilePosition> ReferencingFilePositions { get; private set; }
public SortedSet<FilePosition> DocumentationReferences { get; private set; }

public string Signature {
get {
Expand Down
16 changes: 9 additions & 7 deletions MoaiUtils/CreateApiDescription/MoaiCodeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MoaiType> typesReferencedInDocumentation = typesByName.Values
.Where(type => type.DocumentationReferences.Any());
foreach (MoaiType type in typesReferencedInDocumentation.ToArray()) {
WarnIfSpeculative(type);
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -173,12 +175,12 @@ private void ParseMoaiCodeFiles(DirectoryInfo moaiSourceDirectory, PathFormat me
int\s+(?<className>[A-Za-z0-9_]+)\s*::\s*(?<methodName>[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;
}
Expand Down Expand Up @@ -224,7 +226,7 @@ private void ParseMoaiFile(string code, FilePosition filePosition) {
MoaiType[] baseTypes = match.Groups["baseClassName"].Captures
.Cast<Capture>()
.Where(capture => !capture.Value.Contains("<"))
.Select(capture => GetOrCreateType(capture.Value, documentationPosition))
.Select(capture => GetOrCreateType(capture.Value, null))
.ToArray();

var typePosition = (TypePosition) documentationPosition;
Expand Down

0 comments on commit 6aed696

Please sign in to comment.