private void TryParseSyntaxTree() { SyntaxTree syntaxTree; if (this.Document.TryGetSyntaxTree(out syntaxTree)) { IEnumerable<SyntaxNode> nodes = syntaxTree.GetRoot().DescendantNodes(); foreach (SyntaxNode node in nodes) { if (node is MemberDeclarationSyntax) { PropertyDeclarationSyntax property = node as PropertyDeclarationSyntax; if (property != null) { PropertyComponent propertyComponent = new PropertyComponent(); propertyComponent.Name = property.Identifier.ToString(); propertyComponent.LineNumber = this.GetStartLinePosition(property.SyntaxTree, property.Span); this.Compoents.Add(propertyComponent); } MethodDeclarationSyntax method = node as MethodDeclarationSyntax; if (method != null) { MethodComponent methodComponent = new MethodComponent(); methodComponent.Name = method.Identifier.ToString(); methodComponent.LineNumber = this.GetStartLinePosition(method.SyntaxTree, method.Span); this.Compoents.Add(methodComponent); } } } } }
static void Main(string[] args) { using (var arch = ZipFile.OpenRead(args[0])) { DescriptorComponent desc = null; MethodComponent methods = null; var methodCap = arch.Entries.Where(v => v.Name.ToLower() == "method.cap").SingleOrDefault(); using (BinaryReader rd = new BinaryReader(methodCap.Open())) { StreamNavigator sn = new StreamNavigator(rd.ReadBytes((int)rd.BaseStream.Length), 0); methods = MethodComponent.Factory(sn); } var descriptorCap = arch.Entries.Where(v => v.Name.ToLower() == "descriptor.cap").SingleOrDefault(); using (BinaryReader rd = new BinaryReader(descriptorCap.Open())) { StreamNavigator sn = new StreamNavigator(rd.ReadBytes((int)rd.BaseStream.Length), 0); desc = DescriptorComponent.Factory(sn, methods); } using (TextWriter wr = new StreamWriter(File.Create(args[0] + ".txt"))) { TextDump dump = new TextDump(wr); desc.Dump(dump, 0); wr.Flush(); } } }
protected void CreateMethodClip(MethodComponent method, int maxLength, int x, int y, int w, int h) { MovieClip clip = m_panelClip.CreateSubMovieClip(x, y, w, h); clip.Object = method; // Back rectangle clip.Graphics.FillRectangle(m_backBrush, 0, 0, w, h); double length = method.Lines.Count; double smell_width = w * (length / maxLength); // Smell rectangle clip.Graphics.FillRectangle(m_smellBrush, 0, 0, (int)smell_width, h); // Iteration/Conditional/Comment markings int lineCount = 0; foreach (LineModel model in method.Lines) { Pen pen = GetPen(model); // Hack if (pen != null) { double ratio = lineCount / length; int mark_x = (int)(ratio * smell_width); clip.Graphics.DrawLine(pen, mark_x, 0, mark_x, h); } lineCount++; } clip.CenteredString(method.Name + "() " + method.Lines.Count); }
protected void OnMouseClickMethod(object sender, MouseEventArgs e) { MovieClip clip = (MovieClip)sender; if (clip.Object != null) { MethodComponent mc = (MethodComponent)clip.Object; if (mc.CodeFunction != null) { CodeFunction cf = (CodeFunction)mc.CodeFunction; SelectObjectMethod(cf); } } }
/// <summary> /// 在接口代理方法内自定义执行实例接口方法及数据处理代码 /// </summary> /// <param name="method">接口方法信息对象</param> /// <returns>string类型,返回自定义执行接口方法及数据处理代码字符串</returns> public virtual string ExecuteInterfaceMethodCodeString(MethodInformation method) { MethodComponent mc = method.methodComponent; string code = ""; if (null == method.ofInstanceType) { method.append(ref code, LeftSpaceLevel.one, "throw new Exception(\"接口 {0} 不存在对应的实例\");", method.ofInterfaceType.FullName); return(code); } string resultVarName = string.IsNullOrEmpty(mc.ResultVariantName) ? "" : (mc.ResultVariantName + " = "); method.append(ref code, LeftSpaceLevel.one, "{0}{1}.{2}{3}({4});", resultVarName, mc.InstanceVariantName, mc.InterfaceMethodName, mc.GenericityParas, mc.MethodParas); return(code); }
protected void CollectTemporaryFieldDefs(Hashtable htDefs, Hashtable htUses, MethodComponent m, LineModel line, string strLine) { if (line.HasCode && line.HasAssignment) { foreach (FieldComponent tempfield in htUses.Keys) { int idx = strLine.IndexOf(tempfield.Name); if (idx > -1 && idx < strLine.IndexOf("=")) { if (htDefs[tempfield] == null) { htDefs[tempfield] = new ArrayList(); } if (!((ArrayList)htDefs[tempfield]).Contains(m)) { ((ArrayList)htDefs[tempfield]).Add(m); } } } } }
protected void WalkElements(CodeElement cein, AbstractComponent parent) { CodeElements ces; switch (cein.Kind) { // Handle namespaces case EnvDTE.vsCMElement.vsCMElementNamespace: { CodeNamespace cn = (CodeNamespace)cein; ces = cn.Members; foreach (CodeElement ce in ces) { WalkElements(ce, parent); } break; } // Handle classes case EnvDTE.vsCMElement.vsCMElementClass: { CodeClass cc = (CodeClass)cein; ClassComponent cls = new ClassComponent(cc.FullName, cc.Name); cls.CodeClass = cc; parent.Visit(cls); ces = cc.Members; foreach (CodeElement ce in ces) { WalkElements(ce, cls); } break; } // Handle interfaces case EnvDTE.vsCMElement.vsCMElementInterface: { CodeInterface ci = (CodeInterface)cein; // nothing for now. break; } // Handle methods (functions) case EnvDTE.vsCMElement.vsCMElementFunction: { CodeFunction cf = (CodeFunction)cein; MethodComponent mc = new MethodComponent(cf.FullName, cf.Name); parent.Visit(mc); mc.CreateRepresentation(GetFunctionText(cf)); mc.CodeFunction = cf; break; } // Handle properties case EnvDTE.vsCMElement.vsCMElementProperty: { CodeProperty cp = (CodeProperty)cein; PropertyComponent pc = new PropertyComponent(cp.FullName, cp.Name); parent.Visit(pc); break; } // Handle fields (variables) case EnvDTE.vsCMElement.vsCMElementVariable: { CodeVariable cv = (CodeVariable)cein; FieldComponent fc = new FieldComponent(cv.FullName, cv.Name); parent.Visit(fc); break; } } }
public SwitchStatementComponent(MethodComponent unit, string name) : base(name, name) { this.MethodComponent = unit; }
protected void CollectTemporaryFieldUses(Hashtable htUses, ClassComponent cls, MethodComponent m, LineModel line, string strLine) { if (line.HasConditional) { foreach (FieldComponent field in cls.Fields) { if (strLine.IndexOf(field.Name) > -1) { if (htUses[field] == null) { htUses[field] = new ArrayList(); } if (!((ArrayList)htUses[field]).Contains(m)) { ((ArrayList)htUses[field]).Add(m); } } } } }