Exemplo n.º 1
0
        private void GetCode()
        {
            string fullFileName = Global.mainForm.subSysDirectory + "\\" + cloneSourceInfo.sourcePath;

            this.label_fileName.Text = fullFileName;
            this.fullCode            = Global.GetFileContent(fullFileName);
            this.cloneFragment       = CloneRegionDescriptor.GetCFSourceFromSourcInfo(this.fullCode, cloneSourceInfo);
        }
        public void GenerateForCF(XmlElement sourceElement)
        {
            CloneSourceInfo sourceInfo = new CloneSourceInfo();

            //这个判断其实是不必要的,因为合法的克隆代码xml文件,必定具有这三个属性
            if (sourceElement.HasAttribute("file") && sourceElement.HasAttribute("startline") && sourceElement.HasAttribute("endline"))
            {
                sourceInfo.sourcePath = sourceElement.GetAttribute("file");
                this.fileName         = sourceElement.GetAttribute("file"); //确定文件分布
                Int32.TryParse(sourceElement.GetAttribute("startline"), out sourceInfo.startLine);
                Int32.TryParse(sourceElement.GetAttribute("endline"), out sourceInfo.endLine);
                this.lineNumOfCF = sourceInfo.endLine - sourceInfo.startLine + 1;   //确定克隆代码行数
            }
            //对于Java或C#文件,直接从文件名中提取类名,确定CRD的ClassName字段;否则,将该字段置null。不考虑C++语言,因为nicad不能处理C++语言
            if (Options.Language == ProgLanguage.Java || Options.Language == ProgLanguage.CSharp)
            {
                //考虑从源代码获得类信息,而不是简单通过文件名
                this.className = CloneRegionDescriptor.GetClassNameFromFileName(this.FileName); //使用CRD类的方法
            }
            else
            {
                this.className = null;
            }

            #region 获取克隆片段源代码
            //此处使用GetCFSourceFromSourcInfo,而不用GetCFSourceFromCRD的原因是CRD正在构造中
            //获取目标系统文件夹起始路径
            string subSysStartPath = Global.mainForm.subSysDirectory;
            //绝对路径=起始路径+相对路径
            string subSysPath = subSysStartPath + "\\" + sourceInfo.sourcePath;
            //保存源代码文件的List<string>对象
            List <string> fileContent   = new List <string>();
            List <string> cloneFragment = new List <string>();
            fileContent   = Global.GetFileContent(subSysPath);
            cloneFragment = CloneRegionDescriptor.GetCFSourceFromSourcInfo(fileContent, sourceInfo);
            #endregion
        }