public void GetInheritanceTreeTest3() { var expected = new StaticCodeAnalysis.InheritanceTree( testAnalysis.GetMethodDeclSyntax("int ExampleCode3.A.O(int)"), new InheritanceNode( testAnalysis.GetClassDeclSyntax("ExampleCode3.A"), new List <InheritanceNode> { }) ); var actual = testAnalysis.GetInheritanceTree(testAnalysis.GetMethodDeclSyntax("int ExampleCode3.A.O(int)")); Assert.AreEqual(expected, actual); }
// creates and returns the inheritance graph public InheritanceGraph CreateInheritanceGraph() { InheritanceGraph graph = new InheritanceGraph(); string nodeId; foreach (NamespaceDeclarationSyntax ns in codeAnalysis.GetAllNamespaces()) { // create a group for each namespace nodeId = codeAnalysis.GetNamespaceId(ns); IHNode nsNode = new IHNode(nodeId, nodeId, Type.NAMESPACE); graph.AddNode(nsNode); foreach (ClassDeclarationSyntax cl in codeAnalysis.GetAllClasses(ns)) { // create a group for each class and link it to the namespace group nodeId = codeAnalysis.GetClassId(cl); IHNode clNode = new IHNode(nodeId, cl.Identifier.Text, Type.CLASS); graph.AddNode(clNode); graph.AddLink(new IHLink(nsNode.Id, clNode.Id, true)); foreach (MethodDeclarationSyntax method in codeAnalysis.GetAllMethods(cl)) { // create a group for each method and link it to the class group nodeId = codeAnalysis.GetMethodId(method); IHNode methodNode = new IHNode(nodeId, method.Identifier.Text, method); graph.AddNode(methodNode); graph.AddLink(new IHLink(clNode.Id, methodNode.Id, true)); // add the inheritance tree to the method group StaticCodeAnalysis.InheritanceTree tree = codeAnalysis.GetInheritanceTree(method); graph = Tree2Graph(graph, tree.rootClass, methodNode, null); } } } return(graph); }