[JEDI.NET-commits] tools/JediDoc/source JediDoc.System.Xml.Reflection.pas,1.4,1.5
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2005-06-25 13:16:12
|
Update of /cvsroot/jedidotnet/tools/JediDoc/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6039/tools/JediDoc/source Modified Files: JediDoc.System.Xml.Reflection.pas Log Message: New: <case>, <option> and <condition> tags to handle "<para>option 1</para><para>-or-</para><para>option 2</para>" New: <eventref>, <fieldref>, <methodref>, <propertyref>, <typeref> tags to create <see> references to members. <ref> tag has been altered so it will now accept references to local members and you can specify whether the type should get its own <see> reference. Fix: <true-if> tag now accepts XML markup in its contents Index: JediDoc.System.Xml.Reflection.pas =================================================================== RCS file: /cvsroot/jedidotnet/tools/JediDoc/source/JediDoc.System.Xml.Reflection.pas,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JediDoc.System.Xml.Reflection.pas 23 Jun 2005 17:27:11 -0000 1.4 --- JediDoc.System.Xml.Reflection.pas 25 Jun 2005 13:15:54 -0000 1.5 *************** *** 58,65 **** --- 58,68 ---- strict private class function GetIncludedNodes(filename, xpath: string; fileList: HashTable): XmlNodeList; static; + class procedure GetMemberInfo(currentNode: XmlNode; out &type, member: string); static; + class function GetMemberNode(currentNode: XmlNode): XmlNode; static; class procedure ProcessIncludeReplacements(importedNode, includeNode: XmlNode); static; {$ENDREGION} {$REGION 'Custom tag processing methods'} strict private + class procedure ProcessCase(doc: XmlDocument); static; class procedure ProcessCtor(doc: XmlDocument); static; class procedure ProcessRef(doc: XmlDocument); static; *************** *** 140,143 **** --- 143,147 ---- class procedure XmlUtils.CustomTagProcessing(doc: XmlDocument); begin + ProcessCase(doc); ProcessCtor(doc); ProcessRef(doc); *************** *** 211,214 **** --- 215,268 ---- end; + class procedure XmlUtils.GetMemberInfo(currentNode: XmlNode; out &type, member: string); + var + attr: XmlAttribute; + begin + currentNode := GetMemberNode(currentNode); + attr := currentNode.Attributes['name']; + if attr = nil then + begin + &type := ''; + member := ''; + end + else + begin + member := StringUtils.BeforeLast(attr.Value, '('); + &type := StringUtils.BeforeLast(member, '.').Substring(2); + member := StringUtils.AfterLast(member, '.'); + end; + end; + + class function XmlUtils.GetMemberNode(currentNode: XmlNode): XmlNode; + begin + while (currentNode <> nil) and ((currentNode.NodeType <> XmlNodeType.Element) or (currentNode.Name <> 'member')) do + currentNode := currentNode.ParentNode; + Result := currentNode; + end; + + class procedure XmlUtils.ProcessCase(doc: XmlDocument); + var + replaceList: Hashtable; + caseNode: XmlNode; + frag: XmlDocumentFragment; + prevSibling: XmlElement; + entry: DictionaryEntry; + begin + replaceList := HashTable.Create; + for caseNode in doc.SelectNodes('//*[self::case or self::option or self::condition]') do + begin + frag := doc.CreateDocumentFragment; + prevSibling := XmlElement(caseNode.PreviousSibling); + if (prevSibling <> nil) and ( + (prevSibling.Name = 'case') or (prevSibling.Name = 'option') or (prevSibling.Name = 'condition')) then + frag.InnerXml := System.String.Format('<para>-or-</para><para>{0}</para>', caseNode.InnerXml.Trim) + else + frag.InnerXml := System.String.Format('<para>{0}</para>', caseNode.InnerXml.Trim); + replaceList.Add(caseNode, frag); + end; + for entry in replaceList do + XmlNode(entry.Key).ParentNode.ReplaceChild(XmlNode(entry.Value), XmlNode(entry.Key)); + end; + class procedure XmlUtils.ProcessCtor(doc: XmlDocument); var *************** *** 265,304 **** class procedure XmlUtils.ProcessRef(doc: XmlDocument); var ! removeList: ArrayList; refNode: XmlNode; ! attr: XmlAttribute; typeName: string; memberName: string; ! memberType: string; ! frag: XmlDocumentFragment; ! obj: &Object; begin ! removeList := ArrayList.Create; ! for refNode in doc.GetElementsByTagName('ref') do begin attr := refNode.Attributes['type']; ! if attr = nil then ! raise Exception.Create('Missing ''type'' attribute in ''ref'' tag'); ! typeName := attr.Value; attr := refNode.Attributes['member']; ! if attr = nil then ! raise Exception.Create('Missing ''member'' attribute in ''ref'' tag'); ! memberName := attr.Value; ! attr := refNode.Attributes['memberType']; ! if attr = nil then ! memberType := 'M' else ! memberType := attr.Value.Chars[0]; ! frag := doc.CreateDocumentFragment; ! frag.InnerXml := System.String.Format('<see cref="T:{0}" />.<see cref="{2}:{0}.{1}" />', ! typeName, memberName, memberType.ToUpper); ! refNode.ParentNode.InsertBefore(frag, refNode); ! removeList.Add(refNode); end; ! for obj in removeList do ! XmlNode(obj).ParentNode.RemoveChild(XmlNode(obj)); end; --- 319,401 ---- class procedure XmlUtils.ProcessRef(doc: XmlDocument); var ! replaceList: Hashtable; refNode: XmlNode; ! frag: XmlDocumentFragment; ! thisType: string; ! thisMember: string; ! canonType: string; typeName: string; memberName: string; ! refToType: Boolean; ! attr: XmlAttribute; ! entry: DictionaryEntry; begin ! replaceList := HashTable.Create; ! for refNode in doc.SelectNodes( ! '//*[self::eventref or self::fieldref or self::methodref or self::propertyref or self::ref or self::typeref]') do begin + frag := doc.CreateDocumentFragment; + GetMemberInfo(refNode, thisType, thisMember); + + if refNode.Name = 'ref' then + begin + attr := refNode.Attributes['memberType']; + if attr = nil then + canonType := 'M' + else + canonType := attr.Value.Substring(0, 1).ToUpper; + end + else + canonType := refNode.Name.SubString(0, 1).ToUpper; + attr := refNode.Attributes['type']; ! if attr <> nil then ! typeName := attr.Value ! else ! typeName := thisType; attr := refNode.Attributes['member']; ! if attr <> nil then ! memberName := attr.Value ! else ! begin ! attr := refNode.Attributes['name']; ! if (attr = nil) and (refNode.Name <> 'typeref') then ! raise Exception.Create('''{0}'' tag requires either the ''name'' or ''member'' attribute'); ! if attr <> nil then ! memberName := attr.Value ! else ! memberName := ''; ! end; ! if (refNode.Name = 'typeref') and (memberName <> '') then ! begin ! typeName := typeName + '.' + memberName; ! memberName := ''; ! end; ! ! attr := refNode.Attributes['reftype']; ! if attr <> nil then ! refToType := (attr.Value = '1') or (attr.Value.ToLower = 'yes') or (attr.Value.ToLower = 'true') else ! refToType := refNode.Name = 'ref'; ! refToType := refToType and (thisType <> typeName) and (memberName <> ''); ! ! if refToType then ! frag.InnerXml := System.String.Format( ! '<see cref="T:{0}" />.<see cref="{2}:{0}.{1}" />', typeName, memberName, canonType) ! else ! if memberName <> '' then ! frag.InnerXml := System.String.Format( ! '<see cref="{2}:{0}.{1}">{3}</see>', [typeName, memberName, canonType, refNode.InnerXml.Trim]) ! else ! frag.InnerXml := System.String.Format( ! '<see cref="{1}:{0}">{2}</see>', typeName, canonType, refNode.InnerXml.Trim); ! ! replaceList.Add(refNode, frag); end; ! for entry in replaceList do ! XmlNode(entry.Key).ParentNode.ReplaceChild(XmlNode(entry.Value), XmlNode(entry.Key)); end; *************** *** 315,319 **** frag := doc.CreateDocumentFragment; frag.InnerXml := System.String.Format('<see langword="true" /> if {0}; <see langword="false" /> otherwise.', ! trueIfNode.InnerText); trueIfNode.ParentNode.InsertBefore(frag, trueIfNode); removeList.Add(trueIfNode); --- 412,416 ---- frag := doc.CreateDocumentFragment; frag.InnerXml := System.String.Format('<see langword="true" /> if {0}; <see langword="false" /> otherwise.', ! trueIfNode.InnerXml); trueIfNode.ParentNode.InsertBefore(frag, trueIfNode); removeList.Add(trueIfNode); |