//============================================================ // <T>构造方法,有参数的构造。</T> // // @param nodeParent 字段节点的父节点(类节点) // @param indextable 类全名的索引表 // @param swPrint 用于打印警告结果的StreamWriter对象 // @param relative 当前解析文件所在的目录的路径 // @param file 当前解析的文件 //============================================================ public void XMLMaker(FXmlNode nodeParent, FAsClassesIndexTable indextable, StreamWriter swPrint, FileInfo file, string relative) { if (!IsFieldAnnoFine()) { PrintAnnoWarning(swPrint, file, relative); } FXmlNode nodeField = new FXmlNode("Field"); nodeField.Set("name", this.FieldName); nodeField.Set("full_name", this.FullName); nodeField.Set("access_level", this.AccessLevel); nodeField.Set("type", this.Type); FFileNode type = new FFileNode(this.Type, GetUsing(_strLines)); string fulltype = indextable.LookInMap(type, this.Type); if (Type != this.Type) { nodeField.Set("return_type", fulltype); } if (Description != "") { nodeField.Set("description", Description); } nodeParent.Push(nodeField); }
//============================================================ // <T>对方法字符串进行解析。</T> // // @param nodeClass 需要连接上的父节点也是类节点 // @param indextable 类的全名(命名空间+类名)和类名的索引表 // @param relative 当前解析文件所在的目录的路径 // @param package 类所在包的包对象 // @param file 当前解析的文件 //============================================================ public void ParserMethod(FXmlNode nodeClass, FAsClassesIndexTable indextable, StreamWriter swPrint, FileInfo file, string relative) { _methodStr = _strLine[_beginIndex].ToString().Trim(); int paraStart = _methodStr.IndexOf('(') + 1; int paraEnd = _methodStr.IndexOf(')'); string paramstring = _methodStr.Substring(paraStart, paraEnd - paraStart).Trim(); FXmlNode nodeMethod = XMLMaker(nodeClass, indextable, swPrint, file, relative); FXmlNode parameters = new FXmlNode("Parameters"); nodeMethod.Push(parameters); if (paramstring != "") { string[] pa = paramstring.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int n = 0; n < pa.Length; n++) { FAsParameter asParameter = new FAsParameter(pa[n].Trim(), _strLine, _beginIndex); asParameter.ParserParameter(indextable, parameters, swPrint, file, relative); this.Parameter.Add(asParameter); } MethodReturnNode(indextable, nodeMethod); } FXmlNode methodCode = new FXmlNode("Source"); methodCode.Text = MethodCode; nodeMethod.Push(methodCode); }
//============================================================ // <T>生成节点时,将此对象生成的节点连接到上层节点上</T> // @param node 需要连接的父节点。 // @return 本对象生成的节点。 //============================================================ public FXmlNode XMLMaker(FXmlNode node, FAsClassesIndexTable indextable) { FXmlNode classNode = new FXmlNode("Class"); classNode.Set("name", this.ClassName); if (this.AccessLevel != "") { classNode.Set("access_level", this.AccessLevel); } if (this.Annotates != null && Annotates.Count > 0) { ParserClassAnnotate(); if (Label.Trim() != "") { classNode.Set("label", Label.Trim()); } if (Description.Trim() != "") { classNode.Set("description", Description.Trim()); } } if (this.ParentName != string.Empty) { FFileNode type = new FFileNode(this.ParentName.Trim(), GetUsing(_strLine)); string parent = indextable.LookInMap(type, this._parentName.Trim()); classNode.Set("parent_class", parent); } FXmlNode classCode = new FXmlNode("Source"); classCode.Text = ClassCode; classNode.Push(classCode); node.Push(classNode); return(classNode); }
//============================================================ // <T>构造方法,有参数的构造。</T> // // @param nodeParent 属性对象的生成的节点的父节点 // @param indextable 类全名的索引表 // @param swPrint 用于打印警告结果的StreamWriter对象 // @param relative 当前解析文件所在的目录的路径 // @param file 当前解析的文件 //============================================================ public void XMLMaker(FXmlNode nodeParent, FAsClassesIndexTable indextable, StreamWriter swPrint, FileInfo file, string relative) { if (!IsProAnnoFine()) { PrintAnnoWarning(swPrint, file, relative); } FXmlNode nodeProperty = new FXmlNode("Property"); nodeProperty.Set("name", this.PropertyName); nodeProperty.Set("type", this.PropertyType); FFileNode type = new FFileNode(this.PropertyType, GetUsing(_strLine)); string fulltype = indextable.LookInMap(type, this.PropertyType); if (fulltype != this.PropertyType) { nodeProperty.Set("full_name", fulltype); } if (this.AnnotateLable != "") { nodeProperty.Set("label", AnnotateLable); } if (this.AnnotateDescription != "") { nodeProperty.Set("description", AnnotateDescription); } nodeProperty.Set("access_level", AccessLevel); FXmlNode code = new FXmlNode("Source"); code.Text = this.PropertyCode; nodeProperty.Push(code); nodeParent.Push(nodeProperty); }
//============================================================ // <T>构造方法,有参数的构造。</T> // // @param indextable 类全名的索引表 // @param nodeMethod 参数节点所属的方法节点 // @param swPrint 用于打印警告结果的StreamWriter对象 // @param relative 当前解析文件所在的目录的路径 // @param file 当前解析的文件 //============================================================ public void ParserParameter(FAsClassesIndexTable indextable, FXmlNode nodeMethod, StreamWriter swPrint, FileInfo file, string relative) { string[] pa = _parameterStr.Split(':'); if (pa.Length == 2 && pa[0] != "" && pa[1] != "") { this._parameterName = pa[0].Trim(); this._parameterType = pa[1].Trim(); FFileNode type = new FFileNode(_parameterType, GetImport(_strLines)); this._fulltype = indextable.LookInMap(type, this._parameterType); XMLMaker(nodeMethod, swPrint, file, relative); } }
//============================================================ // <T>根据方法的返回值信息生成方法的返回值节点,并附加到方法节点上</T> // // @param nodeClass 需要连接上的父节点也是类节点 // @param indextable 类的全名(命名空间+类名)和类名的索引表 //============================================================ public void MethodReturnNode(FAsClassesIndexTable indextable, FXmlNode nodeMethod) { if (MethodType != "" && MethodType != "void") { FXmlNode methodTypeNode = new FXmlNode("Return"); methodTypeNode.Set("type", MethodType); FFileNode type = new FFileNode(MethodType, GetImport(_strLine)); string _fulltype = indextable.LookInMap(type, this.MethodType); if (_fulltype != MethodType) { methodTypeNode.Set("full_type", _fulltype); } nodeMethod.Push(methodTypeNode); } }
//============================================================ // <T>解析文件。</T> // @parame fileinfo 要解析的文件 // @param index 解析对象 //============================================================ public void ParserFile(FileInfo file, string outputPath, FAsClassesIndexTable indextable, StreamWriter swPrint, string relative) { FStrings lines = GetLines(file.DirectoryName + "\\" + file.Name); _savePath = outputPath; for (int n = 0; n < lines.Count; n++) { if (FAsPackage.IsPackage(lines, n)) { FAsPackage package = new FAsPackage(lines, n, GetPairNum(lines, n)); string path = outputPath + "\\" + package.PackageString.Trim(); package.ParserPackage(indextable, path, swPrint, file, relative); } } }
//============================================================ // <T>解析类。</T> // // @param indextable 类全名的索引表 // @param path 解析结果的输出路径 // @param swPrint 用于打印警告结果的StreamWriter对象 // @param relative 当前解析文件所在的目录的路径 // @param package 类所在包的包对象 // @param file 当前解析的文件 //============================================================ public void ParserClass(FAsClassesIndexTable indextable, FAsPackage package, string path, StreamWriter swPrint, FileInfo file, string relative) { FXmlDocument doc = new FXmlDocument(); FXmlNode config = doc.Root; FXmlNode nodePackage = package.XMLMaker(config); FXmlNode xmlClass = XMLMaker(nodePackage, indextable); MakeInterfaceNode(xmlClass, indextable); FXmlNode methods = new FXmlNode("Methods"); FXmlNode fields = new FXmlNode("Fields"); FXmlNode properties = new FXmlNode("Properties"); xmlClass.Push(fields); xmlClass.Push(properties); xmlClass.Push(methods); //判断并得到段落注释的行号区间 int start, end = CheckParaAnnotate(_strLine, _startIndex, out start); for (int n = _startIndex; n < _endIndex; n++) { //如果在区间中则推出当前循环继续执行 if (IsInInterregional(n, start, end)) { continue; } if (FAsField.IsField(_strLine, n)) { FAsField field = new FAsField(_strLine, n); field.Parser(fields, indextable, swPrint, file, relative); } if (FAsProperty.IsProperty(_strLine, n)) { int endindex = GetPairNum(_strLine, n); FAsProperty property = new FAsProperty(_strLine, n, endindex); property.ParserPorperty(properties, indextable, swPrint, file, relative); } if (FAsMethod.IsMethod(_strLine, n)) { int methodEnd = GetPairNum(_strLine, n); FAsMethod asMethod = new FAsMethod(_strLine, n, methodEnd); asMethod.ParserMethod(methods, indextable, swPrint, file, relative); this.Method.Add(asMethod); } } SaveXMLFile(doc, path); }
//============================================================ //<T>将类所继承的接口作为子节点连接到类的节点下面</T> // @param interface 接口的字符串组 // @param nodeClass 要连接的父节点,也就是类的节点 //============================================================ public void MakeInterfaceNode(FXmlNode nodeClass, FAsClassesIndexTable indextable) { if (InterfaceStrings == null || InterfaceStrings.Count < 1) { return; } FXmlNode nodeInterface = new FXmlNode("Inherts"); foreach (string str in InterfaceStrings) { FXmlNode inhert = new FXmlNode("Inhert"); string inhertstr = str.Trim(); FFileNode type = new FFileNode(inhertstr, GetUsing(_strLine)); inhertstr = indextable.LookInMap(type, inhertstr); inhert.Set("name", inhertstr.Trim()); nodeInterface.Push(inhert); } nodeClass.Push(nodeInterface); }
//============================================================ // <T>解析包。</T> // // @param indextable 类全名的索引表 // @param path 解析结果的输出路径 // @param swPrint 用于打印警告结果的StreamWriter对象 // @param relative 当前解析文件所在的目录的路径 //============================================================ public void ParserPackage(FAsClassesIndexTable indextable, string path, StreamWriter swPrint, FileInfo file, string relative) { int start, endIndex = CheckParaAnnotate(_strLines, _beginIndex, out start); for (int n = 0; n < _endIndex; n++) { if (IsInInterregional(n, start, endIndex)) { continue; } if (FAsClass.IsClass(_strLines, n)) { int caonima = GetPairNum(_strLines, n); FAsClass asClass = new FAsClass(_strLines, n, caonima); asClass.ParserClass(indextable, this, path, swPrint, file, relative); this.AsClass = AsClass; } } }
//============================================================ // <T>根据方法的信息生成方法的节点,并附加到类节点上。</T> // // @param nodeClass 需要连接上的父节点也是类节点 // @param indextable 类的全名(命名空间+类名)和类名的索引表 // @param path 解析结果的输出路径 // @param swPrint 用于打印警告结果的StreamWriter对象 // @param relative 当前解析文件所在的目录的路径 // @param package 类所在包的包对象 // @param file 当前解析的文件 // @return 返回自身的方法节点 //============================================================ public FXmlNode XMLMaker(FXmlNode nodeClass, FAsClassesIndexTable indextable, StreamWriter swPrint, FileInfo file, string relative) { if (!IsMethodAnnoFine()) { PrintAnnoWarning(swPrint, file, relative); } FXmlNode nodeMethod = new FXmlNode("Method"); nodeMethod.Set("name", MethodName); nodeMethod.Set("full_name", FullMethodName); if (AnnotateLabel != "") { nodeMethod.Set("label", AnnotateLabel); } if (AnnotateDescription != "") { nodeMethod.Set("description", AnnotateDescription); } nodeClass.Push(nodeMethod); return(nodeMethod); }
//============================================================ // <T>构造方法,有参数的构造。</T> // // @param indextable 类全名的索引表 // @param nodeParent 字段节点的父节点(类节点) // @param swPrint 用于打印警告结果的StreamWriter对象 // @param relative 当前解析文件所在的目录的路径 // @param file 当前解析的文件 //============================================================ public void Parser(FXmlNode nodeParent, FAsClassesIndexTable indextable, StreamWriter swPrint, FileInfo file, string relative) { XMLMaker(nodeParent, indextable, swPrint, file, relative); }