コード例 #1
0
ファイル: Program.cs プロジェクト: nkcsgexi/SrcML.NET
        private static void OutputCallGraphByType(Scope globalScope, string jsonPath) {
            using(var writer = new JsonTextWriter(new StreamWriter(jsonPath))) {
                writer.WriteStartArray();
                foreach(var typeDefinition in globalScope.GetDescendantScopesAndSelf<TypeDefinition>()) {
                    writer.WriteStartObject();
                    writer.WritePropertyName("name");
                    writer.WriteValue(typeDefinition.GetFullName());
                    
                    
                    var calls = from scope in typeDefinition.GetDescendantScopesAndSelf()
                                from call in scope.MethodCalls
                                select call;
                    
                    writer.WritePropertyName("size");
                    writer.WriteValue(calls.Count());

                    // find the parent type of all the calls
                    var callMatches = from call in calls
                                      let match = call.FindMatches().FirstOrDefault()
                                      where match != null
                                      let parentOfMatch = match.GetFirstParent<TypeDefinition>()
                                      where parentOfMatch != null
                                      select parentOfMatch.GetFullName();
                    // output the calls property and array
                    writer.WritePropertyName("calls");
                    writer.WriteStartArray();
                    foreach (var call in callMatches)
	                {
                        writer.WriteValue(call);
	                }
                    writer.WriteEndArray();
                    writer.WriteEndObject();
                }
                writer.WriteEndArray();
            }
        }