示例#1
0
        // creates and returns the YoYo graph
        public YoYoGraph CreateYoYoGraph()
        {
            YoYoGraph graph = new YoYoGraph();

            // create a node for each method
            List <MethodDeclarationSyntax> methods = codeAnalysis.GetAllMethods();

            foreach (MethodDeclarationSyntax method in methods)
            {
                graph.AddNode(new YoYoNode(codeAnalysis.GetMethodId(method), codeAnalysis.GetFullMethodName(method), method));
            }

            // create a node for each invocation and add the links
            List <Node> methodNodes = new List <Node>(graph.Nodes);

            foreach (YoYoNode methodNode in methodNodes)
            {
                int invocCount = 0;
                List <StaticCodeAnalysis.Invocation> invocations = codeAnalysis.GetInvocations(methodNode.Method);
                foreach (StaticCodeAnalysis.Invocation invocation in invocations)
                {
                    YoYoNode invocNode = new YoYoNode(methodNode.Id + "_I" + invocCount.ToString(), $"invocs (L {String.Join(", ", invocation.Lines.Select(l => l + 1))})", invocation);
                    graph.AddNode(invocNode);
                    invocCount++;
                    graph.AddLink(new YoYoLink(methodNode.Id, invocNode.Id));

                    foreach (MethodDeclarationSyntax invocOption in invocation.Methods)
                    {
                        graph.AddLink(new YoYoLink(invocNode.Id, graph.GetNode(codeAnalysis.GetMethodId(invocOption)).Id));
                    }
                }
            }

            return(graph);
        }
示例#2
0
        public void GetAllMethodsTest()
        {
            var expected = new List <MethodDeclarationSyntax>
            {
                testAnalysis.GetMethodDeclSyntax("int ExampleCode2.BaseClass.Method1(int)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode2.DerivedAbstractClass.Method1(int)"),
                testAnalysis.GetMethodDeclSyntax("double ExampleCode2.DerivedAbstractClass.Method2()"),
                testAnalysis.GetMethodDeclSyntax("double ExampleCode2.DerivedConcreteClass.Method2()"),
                testAnalysis.GetMethodDeclSyntax("bool ExampleCode2.DerivedConcreteClass.Method3(bool)")
            };
            var actual = testAnalysis.GetAllMethods();

            CollectionAssert.AreEqual(expected, actual);
        }
        public void GetAllMethodsTest()
        {
            var expected = new List <MethodDeclarationSyntax>
            {
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C1.M1(int)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C1.M2(int, int)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C1.M3(int, bool, string)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C2.M2(int, int)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C2.M3(int, bool, string)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C2.M4(int, int)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C3_1.M3(int, bool, string)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C3_1.M4(int, int)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C3_2.M4(int, int)"),
                testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C3_2.M5(int)")
            };
            var actual = testAnalysis.GetAllMethods();

            CollectionAssert.AreEqual(expected, actual);
        }