コード例 #1
0
        static void Main(string[] args)
        {
            var inputFolders           = new string[] { "../extractor" };
            IEnumerable <string> files = inputFolders.SelectMany(folder
                                                                 => Directory.EnumerateFiles(folder, "*.cs", SearchOption.AllDirectories));


            StringBuilder builder = new StringBuilder();

            foreach (string filename in files)
            {
                builder.Append(File.ReadAllText(filename));
            }
            string sourceCode = builder.ToString();


            SyntaxTree tree     = SyntaxFactory.ParseSyntaxTree(sourceCode);
            var        registry = new DeclarationRegistry(tree);

            var method = new MethodExtraction(registry, "GetReferenced");

            Console.WriteLine("digraph d {");
            foreach (var mthd in method.GetCalls())
            {
                Console.WriteLine($"{method.Name} -> {mthd.Name}");
            }
            foreach (var mthd in method.GetCallees())
            {
                Console.WriteLine($"{mthd.Name} -> {method.Name}");
            }
            Console.WriteLine("}");
        }
コード例 #2
0
        public void Calls()
        {
            string code = @"
            class A
            {
                public A()
                {
                    _b = new B();
                }
                public void f()
                {
                    return _b.g();
                }
                private B _b;
            }
            class B
            {
                public void g() { }
            }
            ";

            SyntaxTree tree     = SyntaxFactory.ParseSyntaxTree(code);
            var        registry = new DeclarationRegistry(tree);

            ITypeExtraction  b  = new ClassExtraction(registry, "B");
            MethodExtraction g1 = b.GetMethods().First();
            MethodExtraction f  = g1.GetCallees().First();
            MethodExtraction g2 = f.GetCalls().First();

            Assert.Equal("g", g1.Name);
            Assert.Equal("f", f.Name);
            Assert.Equal("g", g2.Name);
        }