Exemplo n.º 1
0
 //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ������ȡ����
 public SignedFoldingCodes[] GetPackage(string packageName, SignedFoldingCodes mainCode)
 {
     ArrayList packageList = new ArrayList();
     packageList.Add(mainCode);
     int[] arrIndex = m_arrIndex.Clone() as int[];
     int[] arrLevel = m_arrLevel.Clone() as int[];
     string str = m_stText;
     string stPreFix = "package " + packageName + "{\r\n";
     string stPostFix = "\r\n}";
     for (int i = 0; i < arrIndex.Length; i++)
     {
         int index = arrIndex[i];
         int indexClass = str.LastIndexOf("class ", index);
         int indexInterface = str.LastIndexOf("interface ", index);
         if (indexClass > -1 || indexInterface > -1)
         {
             int indexStart = str.LastIndexOf("\r\n", index);
             if (indexStart == -1)
                 indexStart = 0;
             int level = arrLevel[i];
             i++;
             while (arrLevel[i] > level)
             {
                 if (i < arrLevel.Length - 1)
                     i++;
                 else
                     break;
             }
             int length = arrIndex[i] - indexStart + 1;
             string strPackage = str.Substring(indexStart, length);
             str = str.Remove(indexStart, length);
             for (int j = i; j < arrIndex.Length; j++)
             {
                 arrIndex[j] = arrIndex[j] - length;
             }
             packageList.Add(new SignedFoldingCodes(stPreFix + strPackage + stPostFix));
         }
     }
     if (str.IndexOf(";") > -1 || str.IndexOf("=") > -1 || str.IndexOf("function ") > -1)
         packageList.Add(new SignedFoldingCodes(stPreFix + str + stPostFix));
     return packageList.ToArray(typeof(SignedFoldingCodes)) as SignedFoldingCodes[];
 }
Exemplo n.º 2
0
 //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ��ĵ����ɺ���
 public void MakeDocument(bool useTemplate)
 {
     if (Directory.Exists(m_stAsPath))
     {
         DirectoryInfo folder = new DirectoryInfo(m_stAsPath);
         FileInfo[] arrFiles = folder.GetFiles("*.as", SearchOption.AllDirectories);
         int count = arrFiles.Length;
         ArrayList arrClasses = new ArrayList();
         for (int i = 0; i < arrFiles.Length; i++)
         {
             FileInfo file = arrFiles[i];
             FileStream fs = new FileStream(file.FullName, FileMode.Open);
             StreamReader sr = new StreamReader(fs);
             string text = sr.ReadToEnd();
             SignedFoldingCodes code = new SignedFoldingCodes(text);
             SignedFoldingCodes[] codeList = code.split();
             for (int j = 0; j < codeList.Length; j++)
             {
                 code = codeList[j];
                 string packageName = code.PackageName;
                 string packagePath = packageName.Replace(".", "\\");
                 string path = m_stTargetPath + "\\";
                 if (useTemplate)
                     path = m_stTemplatePath + "\\";
                 if (packagePath != "")
                     path += packagePath + "\\";
                 string className = "_toplevel";
                 bool useAppend = true;
                 if (code.ClassName != null)
                 {
                     useAppend = false;
                     className = code.ClassName;
                 }
                 bool isNewClass = makeTemplate(path, className, code, !useTemplate, useAppend);
                 if (isNewClass)
                 {
                     if (packageName == "")
                         arrClasses.Add(className);
                     else
                         arrClasses.Add(packageName.Replace(".", "/") + "/" + className);
                 }
                 else
                     count--;
                 if (j > 0)
                     count++;
             }
             sr.Close();
             fs.Close();
         }
         string info = arrFiles.Length.ToString() + " fiels to " + count.ToString();
         if (useTemplate)
             info += " saved ";
         else
         {
             info += " maked ";
             FileStream fs = new FileStream(m_stTargetPath + "\\" + ClassList_name, FileMode.Create);
             StreamWriter sw = new StreamWriter(fs);
             sw.Write(m_stXmlStart + ">");
             for (int i = 0; i < arrClasses.Count; i++)
             {
                 sw.WriteLine(ClassList_start + arrClasses[i] + Xml_end);
             }
             sw.Write(m_stXmlEnd);
             sw.Close();
             fs.Close();
         }
         ErrorBox.Show(info, "DocumentDataMakerError");
     }
 }
Exemplo n.º 3
0
 //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ���ʱ�ļ�����
 private bool makeTemplate(string path, string className, SignedFoldingCodes code, bool useXml, bool useAppend)
 {
     bool isNewClass = true;
     if (!Directory.Exists(path))
         Directory.CreateDirectory(path);
     if (useXml)
         path += className + ".xhtml";
     else
         path += className + ".as";
     string strCode = code.clearClass();
     if (code.HasClass())
         strCode = code.clearFunction();
     if (useXml)
         strCode = GetMemberList(strCode, className, code.IsClass());
     if (useAppend)
     {
         FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
         StreamReader sr = new StreamReader(fs);
         string savedStr = sr.ReadToEnd();
         string startStr = "{";
         string endStr = "}";
         if (useXml)
         {
             startStr = m_stXmlStart;
             endStr = m_stXmlEnd;
         }
         string[] segMent = SignedFoldingCodes.GetInsertPos(savedStr, true, startStr, endStr);
         if (useXml)
         {
             //��ȡ��������ǰ�˷ָ��,��ΪHxmlģʽ����Ҫ����
             startStr = ">";
         }
         string mainCode = SignedFoldingCodes.GetMainString(strCode, startStr, endStr, RootConfig.HxmlDataStart);
         if (savedStr.Length > 0)
         {
             if (savedStr.IndexOf(mainCode) == -1)
             {
                 string insertSign = "//>>\r\n";
                 if (useXml)
                     insertSign = RootConfig.Xml_tabStop + "<!--Separator-->\r\n";
                 strCode = segMent[0] + insertSign + mainCode + segMent[1];
                 isNewClass = false;
             }
         }
         sr.Close();
         fs.Close();
     }
     FileStream saver = new FileStream(path, FileMode.Create);
     StreamWriter sw = new StreamWriter(saver);
     sw.Write(strCode);
     sw.Close();
     saver.Close();
     return isNewClass;
 }
Exemplo n.º 4
0
 //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ�������뺯��
 public SignedFoldingCodes[] split()
 {
     int count = 0;
     for (int i = 0; i < m_arrIndex.Length; i++)
     {
         int level = m_arrLevel[i];
         if (level == 0)
         {
             count++;
             if (count == 3)
             {
                 int index = m_arrIndex[i - 1] + 1;
                 string mainCode = m_stText.Substring(0, index);
                 SignedFoldingCodes outPackage = new SignedFoldingCodes(m_stText.Substring(index));
                 return outPackage.GetPackage(this.PackageName, new SignedFoldingCodes(mainCode));
             }
         }
     }
     return new SignedFoldingCodes[] { this };
 }