public void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) { XmlNodeList childNodes; if (inXmlNode.HasChildNodes) { childNodes = inXmlNode.ChildNodes; foreach (XmlNode xNode in childNodes) { TreeNode tNode = new TreeNode(xNode.Name); tNode.Name = xNode.Name; //保存节点名称(注:名称与Text不同) //在Tag中保存必要的信息 if (xNode.Name == "source") { CloneSourceInfo info = new CloneSourceInfo(); info.sourcePath = xNode.Attributes[0].Value; Int32.TryParse(xNode.Attributes[1].Value, out info.startLine); Int32.TryParse(xNode.Attributes[2].Value, out info.endLine); tNode.Tag = info; } int index = inTreeNode.Nodes.Add(tNode); //添加新的树节点并获取其索引号 AddNode(xNode, inTreeNode.Nodes[index]); } } else { //OuterXml:the markup containing the current node and all its child(but there is not child). //Trim method remove the leading and trailing space of a string. inTreeNode.Text = (inXmlNode.OuterXml).Trim(); } }
public void ShowXml(int c, List <int> result, ref TreeNode treeRoot) { //由根节点的孩子节点名称,判断要显示的文件内容 for (int i = 0; i < result.Count; i++) { TreeNode tNode = new TreeNode("file=" + xtemp_matrix[(resulttemp[c][i])][32] + " startline=" + xtemp_matrix[(resulttemp[c][i])][33] + " endline=" + xtemp_matrix[(resulttemp[c][i])][34]); tNode.Name = xtemp_matrix[(resulttemp[c][i])][35]; //保存节点名称(注:名称与Text不同) CloneSourceInfo info = new CloneSourceInfo(); info.sourcePath = xtemp_matrix[(resulttemp[c][i])][32]; Int32.TryParse(xtemp_matrix[(resulttemp[c][i])][33], out info.startLine); Int32.TryParse(xtemp_matrix[(resulttemp[c][i])][34], out info.endLine); tNode.Tag = info; treeRoot.Nodes.Add(tNode); //添加新的树节点并获取其索引号 } }
public void ShowXml(List <XmlElement> xmlNode, ref TreeNode treeRoot) { //由根节点的孩子节点名称,判断要显示的文件内容 for (int i = 0; i < xmlNode.Count; i++) { if (xmlNode[i].Name == "source") { TreeNode tNode = new TreeNode(((XmlNode)xmlNode[i]).OuterXml.Substring(0, ((XmlNode)xmlNode[i]).OuterXml.IndexOf(">"))); tNode.Name = xmlNode[i].Name; //保存节点名称(注:名称与Text不同) CloneSourceInfo info = new CloneSourceInfo(); info.sourcePath = xmlNode[i].Attributes[0].Value; Int32.TryParse(xmlNode[i].Attributes[1].Value, out info.startLine); Int32.TryParse(xmlNode[i].Attributes[2].Value, out info.endLine); tNode.Tag = info; treeRoot.Nodes.Add(tNode); //添加新的树节点并获取其索引号 } } }
public void ShowXml(List <XmlElement> xmlNode, ref TreeView treeViewControl) { treeViewControl.Nodes.Clear(); TreeNode treeRoot = new TreeNode("ShowResult(" + xmlNode.Count.ToString() + ")"); treeViewControl.Nodes.Add(treeRoot); //由根节点的孩子节点名称,判断要显示的文件内容 for (int i = 0; i < xmlNode.Count; i++) { if (xmlNode[i].Name == "class") //显示的是-classes.xml或-withCRD.xml文件 { TreeNode treeNode = new TreeNode(((XmlElement)xmlNode[i].ParentNode.SelectSingleNode("systeminfo")).GetAttribute("system")); treeNode.Name = ((XmlElement)xmlNode[i].ParentNode).GetAttribute("system"); //树节点名字为版本名 TreeNode attr1 = new TreeNode("classid = " + xmlNode[i].GetAttribute("classid")); treeNode.Nodes.Add(attr1); AddNode(xmlNode[i], attr1); treeNode.Expand(); treeViewControl.Nodes[0].Nodes.Add(treeNode); treeViewControl.Nodes[0].Expand(); } else if (xmlNode[i].Name == "source") { TreeNode tNode = new TreeNode(((XmlNode)xmlNode[i]).OuterXml.Substring(0, ((XmlNode)xmlNode[i]).OuterXml.IndexOf(">"))); tNode.Name = xmlNode[i].Name; //保存节点名称(注:名称与Text不同) CloneSourceInfo info = new CloneSourceInfo(); info.sourcePath = xmlNode[i].Attributes[0].Value; Int32.TryParse(xmlNode[i].Attributes[1].Value, out info.startLine); Int32.TryParse(xmlNode[i].Attributes[2].Value, out info.endLine); tNode.Tag = info; treeViewControl.Nodes[0].Nodes.Add(tNode); //添加新的树节点并获取其索引号 //!!!!!!!! treeNode.Text = ((XmlNode)xmlNode[i]).OuterXml.Substring(0, ((XmlNode)xmlNode[i]).OuterXml.IndexOf(">")); } } }
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 }
public void SetCloneSourceInfo(CloneSourceInfo info) { cloneSourceInfo = new CloneSourceInfo(); cloneSourceInfo = info; }
/// <summary> /// 显示两段克隆代码diff的结果(行号从startline开始)(与showFileDiff唯一区别) /// </summary> /// <param name="info1">输入参数为CloneSourceInfo对象</param> /// <param name="info2"></param> /// <param name="diffInfo"></param> internal void ShowCloneFragmentDiff(CloneSourceInfo info1, CloneSourceInfo info2, Diff.DiffInfo diffInfo) { this.label1.Text = Global.mainForm.subSysDirectory + "\\" + info1.sourcePath; this.label2.Text = Global.mainForm.subSysDirectory + "\\" + info2.sourcePath; int lineNo1 = info1.startLine - 1; int lineNo2 = info2.startLine - 1; this.richTextBox1.Text = ""; this.richTextBox3.Text = ""; foreach (Object item in diffInfo) { if (item is string) //相同的行 { lineNo1++; this.richTextBox1.SelectionColor = Color.Black; this.richTextBox1.AppendText(lineNo1.ToString() + "\r\n");//构建file1行号字符串 this.richTextBox3.SelectionColor = Color.Black; this.richTextBox3.AppendText((string)item + "\r\n"); //构建file1内容字符串 lineNo2++; this.richTextBox2.SelectionColor = Color.Black; this.richTextBox2.AppendText(lineNo2.ToString() + "\r\n");//构建file2行号字符串 this.richTextBox4.SelectionColor = Color.Black; this.richTextBox4.AppendText((string)item + "\r\n"); //构建file2内容字符串 } else//冲突的行 { if (((Diff.ConfictItem)item).contentA != null) { foreach (string line in ((Diff.ConfictItem)item).contentA) { lineNo1++; this.richTextBox1.SelectionColor = Color.Red; this.richTextBox1.SelectionBackColor = Color.LightYellow; this.richTextBox1.AppendText(lineNo1.ToString() + "\r\n"); this.richTextBox3.SelectionColor = Color.Red; //设定新增行颜色为红色(冲突行用红色显示) this.richTextBox3.SelectionBackColor = Color.LightYellow; //this.richTextBox3.SelectionFont = FontStyle.Bold; //设定新增行加粗 this.richTextBox3.AppendText(line + "\r\n"); } } if (((Diff.ConfictItem)item).contentB != null) { foreach (string line in ((Diff.ConfictItem)item).contentB) { lineNo2++; this.richTextBox2.SelectionColor = Color.Red; //设定新增行颜色为红色 this.richTextBox2.SelectionBackColor = Color.LightYellow; this.richTextBox2.AppendText(lineNo2.ToString() + "\r\n"); //this.richTextBox4.ForeColor = Color.Red; this.richTextBox4.SelectionColor = Color.Red; this.richTextBox4.SelectionBackColor = Color.LightYellow; this.richTextBox4.AppendText(line + "\r\n"); } } } } this.Show(); }