Skip to content

Commit

Permalink
Cosmetics: generators
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrnet committed Apr 27, 2013
1 parent 31a0287 commit 3995d63
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 114 deletions.
88 changes: 25 additions & 63 deletions src/Docu.Console/Documentation/Generators/BaseGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,116 +9,78 @@ namespace Docu.Documentation.Generators
{
internal abstract class BaseGenerator
{
readonly ICommentParser commentParser;
readonly ICommentParser _commentParser;

protected BaseGenerator(ICommentParser commentParser)
{
this.commentParser = commentParser;
_commentParser = commentParser;
}

protected Namespace FindNamespace(IDocumentationMember association, List<Namespace> namespaces)
protected static Namespace FindNamespace(IDocumentationMember association, List<Namespace> namespaces)
{
NamespaceIdentifier identifier = Identifier.FromNamespace(association.TargetType.Namespace);
return namespaces.Find(x => x.IsIdentifiedBy(identifier));
}

protected DeclaredType FindType(Namespace ns, IDocumentationMember association)
protected static DeclaredType FindType(IDocumentationMember association, List<Namespace> namespaces)
{
TypeIdentifier typeName = Identifier.FromType(association.TargetType);
return ns.Types.FirstOrDefault(x => x.IsIdentifiedBy(typeName));
var typeName = Identifier.FromType(association.TargetType);
var identifier = Identifier.FromNamespace(association.TargetType.Namespace);
return namespaces.Find(x => x.IsIdentifiedBy(identifier)).Types.FirstOrDefault(x => x.IsIdentifiedBy(typeName));
}

protected void ParseExample(IDocumentationMember member, IDocumentationElement doc)
{
if (member.Xml == null)
{
return;
}

if (member.Xml == null) return;
XmlNode node = member.Xml.SelectSingleNode("example");
if (node == null) return;

if (node != null)
{
doc.Example = new MultilineCode(
commentParser.ParseNode(node, new ParseOptions {PreserveWhitespace = true}));
}
doc.Example = new MultilineCode(_commentParser.ParseNode(node, new ParseOptions {PreserveWhitespace = true}));
}

protected void ParseParamSummary(IDocumentationMember member, IDocumentationElement doc)
{
if (member.Xml == null)
{
return;
}

if (member.Xml == null) return;
XmlNode node = member.Xml.SelectSingleNode("param[@name='" + doc.Name + "']");
if (node == null) return;

ParseSummary(node, doc);
doc.Summary = new Summary(_commentParser.ParseNode(node));
}

protected void ParseRemarks(IDocumentationMember member, IDocumentationElement doc)
{
if (member.Xml == null)
{
return;
}

if (member.Xml == null) return;
XmlNode node = member.Xml.SelectSingleNode("remarks");
if (node == null) return;

if (node != null)
{
doc.Remarks = new Remarks(commentParser.ParseNode(node));
}
doc.Remarks = new Remarks(_commentParser.ParseNode(node));
}

protected void ParseReturns(IDocumentationMember member, Method doc)
{
if (member.Xml == null)
{
return;
}

if (member.Xml == null) return;
XmlNode node = member.Xml.SelectSingleNode("returns");
if (node == null) return;

if (node != null)
{
doc.Returns = new Summary(commentParser.ParseNode(node));
}
doc.Returns = new Summary(_commentParser.ParseNode(node));
}

protected void ParseSummary(IDocumentationMember member, IDocumentationElement doc)
{
if (member.Xml == null)
{
return;
}

if (member.Xml == null) return;
XmlNode node = member.Xml.SelectSingleNode("summary");
if (node == null) return;

ParseSummary(node, doc);
doc.Summary = new Summary(_commentParser.ParseNode(node));
}

protected void ParseValue(IDocumentationMember member, IDocumentationElement doc)
{
if (member.Xml == null)
{
return;
}

if (member.Xml == null) return;
XmlNode node = member.Xml.SelectSingleNode("value");
if (node == null) return;

if (node != null)
{
doc.Value = new Value(commentParser.ParseNode(node));
}
}

void ParseSummary(XmlNode node, IDocumentationElement doc)
{
if (node != null)
{
doc.Summary = new Summary(commentParser.ParseNode(node));
}
doc.Value = new Value(_commentParser.ParseNode(node));
}
}
}
9 changes: 4 additions & 5 deletions src/Docu.Console/Documentation/Generators/EventGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace Docu.Documentation.Generators
{
internal class EventGenerator : BaseGenerator, IGenerator<DocumentedEvent>
{
readonly IDictionary<Identifier, IReferencable> matchedAssociations;
readonly IDictionary<Identifier, IReferencable> _matchedAssociations;

public EventGenerator(IDictionary<Identifier, IReferencable> matchedAssociations, ICommentParser commentParser)
: base(commentParser)
{
this.matchedAssociations = matchedAssociations;
_matchedAssociations = matchedAssociations;
}

public void Add(List<Namespace> namespaces, DocumentedEvent association)
Expand All @@ -21,16 +21,15 @@ public void Add(List<Namespace> namespaces, DocumentedEvent association)
return;
}

Namespace ns = FindNamespace(association, namespaces);
DeclaredType type = FindType(ns, association);
DeclaredType type = FindType(association, namespaces);

Event doc = Event.Unresolved(Identifier.FromEvent(association.Event, association.TargetType), type);

ParseSummary(association, doc);
ParseRemarks(association, doc);
ParseExample(association, doc);

matchedAssociations.Add(association.Name, doc);
_matchedAssociations.Add(association.Name, doc);
type.AddEvent(doc);
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/Docu.Console/Documentation/Generators/FieldGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace Docu.Documentation.Generators
{
internal class FieldGenerator : BaseGenerator, IGenerator<DocumentedField>
{
readonly IDictionary<Identifier, IReferencable> matchedAssociations;
readonly IDictionary<Identifier, IReferencable> _matchedAssociations;

public FieldGenerator(IDictionary<Identifier, IReferencable> matchedAssociations, ICommentParser commentParser)
: base(commentParser)
{
this.matchedAssociations = matchedAssociations;
_matchedAssociations = matchedAssociations;
}

public void Add(List<Namespace> namespaces, DocumentedField association)
Expand All @@ -21,8 +21,7 @@ public void Add(List<Namespace> namespaces, DocumentedField association)
return;
}

Namespace ns = FindNamespace(association, namespaces);
DeclaredType type = FindType(ns, association);
DeclaredType type = FindType(association, namespaces);

DeclaredType returnType = DeclaredType.Unresolved(
Identifier.FromType(association.Field.FieldType),
Expand All @@ -35,7 +34,7 @@ public void Add(List<Namespace> namespaces, DocumentedField association)
ParseRemarks(association, doc);
ParseExample(association, doc);

matchedAssociations.Add(association.Name, doc);
_matchedAssociations.Add(association.Name, doc);
type.AddField(doc);
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/Docu.Console/Documentation/Generators/MethodGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Docu.Documentation.Generators
{
internal class MethodGenerator : BaseGenerator, IGenerator<DocumentedMethod>
{
readonly IDictionary<Identifier, IReferencable> matchedAssociations;
readonly IDictionary<Identifier, IReferencable> _matchedAssociations;

public MethodGenerator(IDictionary<Identifier, IReferencable> matchedAssociations, ICommentParser commentParser)
: base(commentParser)
{
this.matchedAssociations = matchedAssociations;
_matchedAssociations = matchedAssociations;
}

public void Add(List<Namespace> namespaces, DocumentedMethod association)
Expand All @@ -22,8 +22,7 @@ public void Add(List<Namespace> namespaces, DocumentedMethod association)
return;
}

Namespace ns = FindNamespace(association, namespaces);
DeclaredType type = FindType(ns, association);
DeclaredType type = FindType(association, namespaces);

DeclaredType methodReturnType = null;
if (association.Method.MemberType == MemberTypes.Method)
Expand Down Expand Up @@ -59,12 +58,12 @@ public void Add(List<Namespace> namespaces, DocumentedMethod association)
doc.AddParameter(docParam);
}

if (matchedAssociations.ContainsKey(association.Name))
if (_matchedAssociations.ContainsKey(association.Name))
{
return; // weird case when a type has the same method declared twice
}

matchedAssociations.Add(association.Name, doc);
_matchedAssociations.Add(association.Name, doc);

if (type == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace Docu.Documentation.Generators
{
internal class NamespaceGenerator : IGenerator<IDocumentationMember>
{
readonly IDictionary<Identifier, IReferencable> matchedAssociations;
readonly IDictionary<Identifier, IReferencable> _matchedAssociations;

public NamespaceGenerator(IDictionary<Identifier, IReferencable> matchedAssociations)
{
this.matchedAssociations = matchedAssociations;
_matchedAssociations = matchedAssociations;
}

public void Add(List<Namespace> namespaces, IDocumentationMember association)
Expand All @@ -26,7 +26,7 @@ public void Add(List<Namespace> namespaces, IDocumentationMember association)
if (!namespaces.Exists(x => x.IsIdentifiedBy(ns)))
{
Namespace doc = Namespace.Unresolved(ns);
matchedAssociations.Add(association.Name.CloneAsNamespace(), doc);
_matchedAssociations.Add(association.Name.CloneAsNamespace(), doc);
namespaces.Add(doc);
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/Docu.Console/Documentation/Generators/PropertyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace Docu.Documentation.Generators
{
internal class PropertyGenerator : BaseGenerator, IGenerator<DocumentedProperty>
{
readonly IDictionary<Identifier, IReferencable> matchedAssociations;
readonly IDictionary<Identifier, IReferencable> _matchedAssociations;

public PropertyGenerator(
IDictionary<Identifier, IReferencable> matchedAssociations, ICommentParser commentParser)
: base(commentParser)
{
this.matchedAssociations = matchedAssociations;
_matchedAssociations = matchedAssociations;
}

public void Add(List<Namespace> namespaces, DocumentedProperty association)
Expand All @@ -22,8 +22,7 @@ public void Add(List<Namespace> namespaces, DocumentedProperty association)
return;
}

Namespace ns = FindNamespace(association, namespaces);
DeclaredType type = FindType(ns, association);
DeclaredType type = FindType(association, namespaces);

DeclaredType propertyReturnType =
DeclaredType.Unresolved(
Expand All @@ -38,12 +37,12 @@ public void Add(List<Namespace> namespaces, DocumentedProperty association)
ParseRemarks(association, doc);
ParseExample(association, doc);

if (matchedAssociations.ContainsKey(association.Name))
if (_matchedAssociations.ContainsKey(association.Name))
{
return;
}

matchedAssociations.Add(association.Name, doc);
_matchedAssociations.Add(association.Name, doc);
if (type == null)
{
return;
Expand Down
9 changes: 4 additions & 5 deletions src/Docu.Console/Parsing/Model/DocumentedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ public DocumentedEvent(Identifier name, XmlNode xml, EventInfo ev, Type targetTy
TargetType = targetType;
}

public Type TargetType { get; set; }
public EventInfo Event { get; set; }

public XmlNode Xml { get; set; }
public Identifier Name { get; set; }
public Identifier Name { get; private set; }
public Type TargetType { get; private set; }
public XmlNode Xml { get; private set; }
public EventInfo Event { get; private set; }

public bool Match(Identifier name)
{
Expand Down
9 changes: 4 additions & 5 deletions src/Docu.Console/Parsing/Model/DocumentedField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ public DocumentedField(Identifier name, XmlNode xml, FieldInfo field, Type targe
TargetType = targetType;
}

public Type TargetType { get; set; }
public FieldInfo Field { get; set; }

public XmlNode Xml { get; set; }
public Identifier Name { get; set; }
public Identifier Name { get; private set; }
public Type TargetType { get; private set; }
public XmlNode Xml { get; private set; }
public FieldInfo Field { get; private set; }

public bool Match(Identifier name)
{
Expand Down
9 changes: 4 additions & 5 deletions src/Docu.Console/Parsing/Model/DocumentedMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ public DocumentedMethod(Identifier name, XmlNode xml, MethodBase method, Type ta
Name = name;
}

public Type TargetType { get; set; }
public MethodBase Method { get; set; }

public XmlNode Xml { get; set; }
public Identifier Name { get; set; }
public Identifier Name { get; private set; }
public Type TargetType { get; private set; }
public XmlNode Xml { get; private set; }
public MethodBase Method { get; private set; }

public bool Match(Identifier name)
{
Expand Down
9 changes: 4 additions & 5 deletions src/Docu.Console/Parsing/Model/DocumentedProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ public DocumentedProperty(Identifier name, XmlNode xml, PropertyInfo property, T
TargetType = targetType;
}

public Type TargetType { get; set; }
public PropertyInfo Property { get; set; }

public XmlNode Xml { get; set; }
public Identifier Name { get; set; }
public Identifier Name { get; private set; }
public Type TargetType { get; private set; }
public XmlNode Xml { get; private set; }
public PropertyInfo Property { get; private set; }

public bool Match(Identifier name)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Docu.Console/Parsing/Model/DocumentedType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public DocumentedType(Identifier name, XmlNode xml, Type type)
Name = name;
}

public XmlNode Xml { get; set; }
public Identifier Name { get; set; }
public Type TargetType { get; set; }
public Identifier Name { get; private set; }
public Type TargetType { get; private set; }
public XmlNode Xml { get; private set; }

public bool Match(Identifier name)
{
Expand Down
Loading

0 comments on commit 3995d63

Please sign in to comment.