//============================================================ // <T>解析单个文件</T> // // @param file 要解析的文件 //============================================================ public void ParserSingleFile(FileInfo file) { FStrings strLines = FAsParser.GetLines(file.FullName); for (int n = 0; n < strLines.Count; n++) { if (FAsPackage.IsPackage(strLines, n)) { string package = string.Empty; int endindex = FAsPackage.ParserPackage(strLines, n, out package); int start, end = CheckParaAnnotate(strLines, n, out start); for (int i = n; i < endindex; i++) { if (IsInInterregional(i, start, end)) { continue; } if (FAsClass.IsClass(strLines, i)) { string classStr = FAsClass.ParserClass(strLines, i); FMapNode node = new FMapNode(classStr, package); AddNode(node); n = i; } } } } }
//============================================================ // <T>建立输出XML文件的根节点。</T> // // @param package 当前类所在包的包对象 // @return 包含包对象的根节点 //============================================================ public FXmlNode RootPackageNode(FAsPackage package) { FXmlDocument doc = new FXmlDocument(); FXmlNode config = doc.Root; FXmlNode nodeSpace = package.XMLMaker(config); return(nodeSpace); }
//============================================================ // <T>解析包。</T> // // @param strlines 所在代码行集合 // @param index 当前索引 // @param out string 包名 // @return 包的结束行索引 //============================================================ public static int ParserPackage(FStrings strLines, int index, out string spaceString) { FAsPackage package = new FAsPackage(); package._strLines = strLines; package._beginIndex = index; string strTemp = strLines[index].ToString().Trim(); spaceString = package.PackageString; int end = package.GetPairNum(strLines, index); return(end); }
//============================================================ // <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); }