[JEDI.NET-commits] tools/JediDoc/source JediDoc.System.Xml.Reflection.pas,1.3,1.4
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2005-06-23 17:27:20
|
Update of /cvsroot/jedidotnet/tools/JediDoc/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19314/tools/JediDoc/source Modified Files: JediDoc.System.Xml.Reflection.pas Log Message: * Changed remaining instances of 'translationList' to 'replacementList' * Added: custom tag 'ctor'. It will automatically generate the common text for a constructor. If the <ctor> tag contains something, the contents of the <ctor> tag is appended to the common contructor text (which will have a comma at the end in this case). * Modified: include expansion now also happens at the highest level. Previously this would only happen once inside a <member> tag. Index: JediDoc.System.Xml.Reflection.pas =================================================================== RCS file: /cvsroot/jedidotnet/tools/JediDoc/source/JediDoc.System.Xml.Reflection.pas,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JediDoc.System.Xml.Reflection.pas 19 Jun 2005 16:00:18 -0000 1.3 --- JediDoc.System.Xml.Reflection.pas 23 Jun 2005 17:27:11 -0000 1.4 *************** *** 41,47 **** {$REGION 'Private static methods'} strict private ! class function GetParameterNames(doc: XmlDocument): StringArray; static; ! class function GetParameters(doc: XmlDocument): XmlNodeList; static; ! class procedure ProcessXmlMember(reader: XmlReader; filePath: string; docs: DocOverview; fileList: HashTable); static; {$ENDREGION} --- 41,47 ---- {$REGION 'Private static methods'} strict private ! class function GetParameterNames(member: XmlElement): StringArray; static; ! class function GetParameters(member: XmlElement): XmlNodeList; static; ! class procedure ProcessXmlMember(member: XmlElement; filePath: string; docs: DocOverview; fileList: HashTable); static; {$ENDREGION} *************** *** 62,65 **** --- 62,66 ---- {$REGION 'Custom tag processing methods'} strict private + class procedure ProcessCtor(doc: XmlDocument); static; class procedure ProcessRef(doc: XmlDocument); static; class procedure ProcessTrueIf(doc: XmlDocument); static; *************** *** 67,74 **** {$REGION 'Static methods'} public class procedure CustomTagProcessing(doc: XmlDocument); static; class procedure ExpandIncludeNodes(doc: XmlDocument; fileList: HashTable); static; class procedure Replace(element: XmlElement); overload; static; ! class procedure Replace(element: XmlElement; translationList: IDictionary); overload; static; class procedure ReplaceCommonMemberReferences(element: XmlElement); static; {$ENDREGION} --- 68,76 ---- {$REGION 'Static methods'} public + class function GetDocument(path: string; fileList: HashTable): XmlDocument; static; class procedure CustomTagProcessing(doc: XmlDocument); static; class procedure ExpandIncludeNodes(doc: XmlDocument; fileList: HashTable); static; class procedure Replace(element: XmlElement); overload; static; ! class procedure Replace(element: XmlElement; replacementList: IDictionary); overload; static; class procedure ReplaceCommonMemberReferences(element: XmlElement); static; {$ENDREGION} *************** *** 81,85 **** {$REGION 'XmlReflector'} ! class function XmlReflector.GetParameterNames(doc: XmlDocument): StringArray; var paramList: XmlNodeList; --- 83,87 ---- {$REGION 'XmlReflector'} ! class function XmlReflector.GetParameterNames(member: XmlElement): StringArray; var paramList: XmlNodeList; *************** *** 87,91 **** node: XmlNode; begin ! paramList := GetParameters(doc); nameList := ArrayList.Create(paramList.Count); for node in paramList do --- 89,93 ---- node: XmlNode; begin ! paramList := GetParameters(member); nameList := ArrayList.Create(paramList.Count); for node in paramList do *************** *** 94,100 **** end; ! class function XmlReflector.GetParameters(doc: XmlDocument): XmlNodeList; begin ! Result := doc.GetElementsByTagName('param'); end; --- 96,102 ---- end; ! class function XmlReflector.GetParameters(member: XmlElement): XmlNodeList; begin ! Result := member.SelectNodes('param'); end; *************** *** 102,171 **** var fileList: HashTable; ! savedDirectory: string; ! xr: XmlReader; begin ! savedDirectory := System.Environment.CurrentDirectory; ! xr := XmlTextReader.Create(StreamReader.Create(path)); ! try ! System.Environment.CurrentDirectory := System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(path)); fileList := Hashtable.Create(CaseInsensitiveHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant); ! if System.IO.Path.GetFileNameWithoutExtension(path).ToLower.StartsWith('namespacedoc.') then ! begin ! docs.AddXmlMember('N:' + System.IO.path.GetFileNameWithoutExtension(path).Substring('namespacedoc.'.Length), ! path, [], False); ! end ! else ! begin ! if xr.MoveToContent = XmlNodeType.Element then ! begin ! xr.ReadStartElement('members'); ! while xr.IsStartElement do ! begin ! if xr.IsStartElement('member') then ! ProcessXmlMember(xr, path, docs, fileList) ! else ! xr.Skip; ! end; ! xr.ReadEndElement; ! end; ! end; ! finally ! xr.Close; // release the file ! System.Environment.CurrentDirectory := savedDirectory; end; end; ! class procedure XmlReflector.ProcessXmlMember(reader: XmlReader; filePath: string; docs: DocOverview; fileList: HashTable); var - line: Integer; - pos: Integer; memberId: string; - tmpXml: string; - doc: XmlDocument; params: array of string; begin ! if reader is XmlTextReader then ! begin ! line := XmlTextReader(reader).LineNumber; ! pos := XmlTextReader(reader).LinePosition; ! end else ! begin ! line := 0; ! pos := 0; ! end; ! memberId := reader.GetAttribute('name'); ! if memberId = '' then ! raise Exception.Create(System.String.Format('Nameless member found. File ''{0}'', Line {1}, column {2}', ! filePath, line, pos)); ! doc := XmlDocument.Create; ! tmpXml := reader.ReadOuterXml; ! doc.LoadXml(tmpXml); ! XmlUtils.ExpandIncludeNodes(doc, fileList); ! params := GetParameterNames(doc); ! docs.AddXmlMember(memberId, filePath, params, Assigned(doc.DocumentElement.SelectSingleNode('exclude'))); ! reader.Skip; end; {$ENDREGION} --- 104,137 ---- var fileList: HashTable; ! doc: XmlDocument; ! memberNode: XmlNode; begin ! if System.IO.Path.GetFileNameWithoutExtension(path).ToLower.StartsWith('namespacedoc.') then ! begin ! docs.AddXmlMember('N:' + System.IO.path.GetFileNameWithoutExtension(path).Substring('namespacedoc.'.Length), ! path, [], False); ! end ! else ! begin fileList := Hashtable.Create(CaseInsensitiveHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant); ! doc := XmlUtils.GetDocument(path, fileList); ! for memberNode in doc.SelectNodes('/members/member') do ! ProcessXmlMember(XmlElement(memberNode), path, docs, fileList); end; end; ! class procedure XmlReflector.ProcessXmlMember(member: XmlElement; filePath: string; docs: DocOverview; fileList: HashTable); var memberId: string; params: array of string; begin ! if member.Attributes['name'] <> nil then ! memberId := member.Attributes['name'].Value else ! raise Exception.Create('Nameless member found.'); ! params := GetParameterNames(member); ! docs.AddXmlMember(memberId, filePath, params, Assigned(member.SelectSingleNode('exclude'))); end; {$ENDREGION} *************** *** 174,177 **** --- 140,144 ---- class procedure XmlUtils.CustomTagProcessing(doc: XmlDocument); begin + ProcessCtor(doc); ProcessRef(doc); ProcessTrueIf(doc); *************** *** 201,204 **** --- 168,173 ---- raise Exception.Create('Missing ''path'' attribute in the ''include'' tag'); includedNodes := GetIncludedNodes(fileAttr.Value, pathAttr.Value, fileList); + if includedNodes.Count = 0 then + Console.WriteLine('Warning: nothing included for tag {0}', includeNode.OuterXml); for includedNode in includedNodes do begin *************** *** 213,231 **** end; ! class function XmlUtils.GetIncludedNodes(filename, xpath: string; fileList: HashTable): XmlNodeList; var ! doc: XmlDocument; begin ! if fileList.ContainsKey(filename) then ! Result := XmlDocument(fileList[filename]).SelectNodes(xpath) else begin ! doc := XmlDocument.Create; ! doc.PreserveWhitespace := True; ! doc.Load(filename); ! fileList.Add(filename, doc); ! ExpandIncludeNodes(doc, fileList); ! Result := doc.SelectNodes(xpath); end; end; --- 182,236 ---- end; ! class function XmlUtils.GetDocument(path: string; fileList: HashTable): XmlDocument; var ! fi: FileInfo; ! savePath: string; begin ! fi := FileInfo.Create(path); ! if fileList.ContainsKey(fi.FullName) then ! Result := XmlDocument(fileList[fi.FullName]) else begin ! Result := XmlDocument.Create; ! Result.PreserveWhitespace := True; ! Result.Load(fi.FullName); ! savePath := Environment.CurrentDirectory; ! try ! Environment.CurrentDirectory := fi.DirectoryName; ! fileList.Add(fi.FullName, Result); ! ExpandIncludeNodes(Result, fileList); ! finally ! Environment.CurrentDirectory := savePath; ! end; ! end; ! end; ! ! class function XmlUtils.GetIncludedNodes(filename, xpath: string; fileList: HashTable): XmlNodeList; ! begin ! Result := GetDocument(filename, fileList).SelectNodes(xpath); ! end; ! ! class procedure XmlUtils.ProcessCtor(doc: XmlDocument); ! var ! removeList: ArrayList; ! ctorNode: XmlNode; ! frag: XmlDocumentFragment; ! obj: &Object; ! begin ! removeList := ArrayList.Create; ! for ctorNode in doc.GetElementsByTagName('ctor') do ! begin ! frag := doc.CreateDocumentFragment; ! if ctorNode.InnerText.Trim.Length = 0 then ! frag.InnerXml := 'Initializes a new instance of the <see-class /> class.' ! else ! frag.InnerXml := System.String.Format( ! 'Initializes a new instance of the <see-class /> class, {0}.', ! ctorNode.InnerText.Trim); ! ctorNode.ParentNode.InsertBefore(frag, ctorNode); ! removeList.Add(ctorNode); end; + for obj in removeList do + XmlNode(obj).ParentNode.RemoveChild(XmlNode(obj)); end; *************** *** 326,342 **** end; ! class procedure XmlUtils.Replace(element: XmlElement; translationList: IDictionary); var ! nodeInner: string; entry: DictionaryEntry; begin if element = nil then raise ArgumentNullException.Create('element'); ! if translationList = nil then ! raise ArgumentNullException.Create('translationList'); ! nodeInner := element.InnerXml; ! for entry in translationList do ! nodeInner := nodeInner.Replace(string(entry.Key), string(entry.Value)); ! element.InnerXml := nodeInner; end; --- 331,355 ---- end; ! class procedure XmlUtils.Replace(element: XmlElement; replacementList: IDictionary); var ! content: string; entry: DictionaryEntry; + xmlAttr: XmlAttribute; begin if element = nil then raise ArgumentNullException.Create('element'); ! if replacementList = nil then ! raise ArgumentNullException.Create('replacementList'); ! content := element.InnerXml; ! for entry in replacementList do ! content := content.Replace(string(entry.Key), string(entry.Value)); ! element.InnerXml := content; ! for xmlAttr in element.Attributes do ! begin ! content := xmlAttr.Value; ! for entry in replacementList do ! content := content.Replace(string(entry.Key), string(entry.Value)); ! xmlAttr.Value := content; ! end; end; |