public void SelectPreviousNextCommandsTest() { var codeFlow = new CodeFlow { Locations = new List<AnnotatedCodeLocation> { new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration } } }; CallTree callTree = new CallTree(CodeFlowToTreeConverter.Convert(codeFlow)); callTree.FindPrevious().Should().Be(null); callTree.FindNext().Should().Be(null); callTree.SelectedItem = callTree.TopLevelNodes[0]; callTree.FindPrevious().Should().Be(callTree.TopLevelNodes[0]); callTree.FindNext().Should().Be(callTree.TopLevelNodes[0].Children[0]); callTree.SelectedItem = callTree.TopLevelNodes[0].Children[0]; callTree.FindPrevious().Should().Be(callTree.TopLevelNodes[0]); callTree.FindNext().Should().Be(callTree.TopLevelNodes[0].Children[1]); callTree.SelectedItem = callTree.TopLevelNodes[0].Children[2]; callTree.FindPrevious().Should().Be(callTree.TopLevelNodes[0].Children[1]); callTree.FindNext().Should().Be(callTree.TopLevelNodes[1]); callTree.SelectedItem = callTree.TopLevelNodes[1]; callTree.FindPrevious().Should().Be(callTree.TopLevelNodes[0].Children[2]); callTree.FindNext().Should().Be(callTree.TopLevelNodes[2]); callTree.SelectedItem = callTree.TopLevelNodes[2]; callTree.FindPrevious().Should().Be(callTree.TopLevelNodes[1]); callTree.FindNext().Should().Be(callTree.TopLevelNodes[2]); }
/// <summary> /// Initializes a new instance of the <see cref="CodeFlow" /> class from the specified instance. /// </summary> /// <param name="other"> /// The instance from which the new instance is to be initialized. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="other" /> is null. /// </exception> public CodeFlow(CodeFlow other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } Init(other.Message, other.Locations, other.Properties); }
public virtual CodeFlow VisitCodeFlow(CodeFlow node) { if (node != null) { if (node.Locations != null) { for (int index_0 = 0; index_0 < node.Locations.Count; ++index_0) { node.Locations[index_0] = VisitNullChecked(node.Locations[index_0]); } } } return(node); }
public virtual CodeFlow VisitCodeFlow(CodeFlow node) { if (node != null) { node.Message = VisitNullChecked(node.Message); if (node.ThreadFlows != null) { for (int index_0 = 0; index_0 < node.ThreadFlows.Count; ++index_0) { node.ThreadFlows[index_0] = VisitNullChecked(node.ThreadFlows[index_0]); } } } return(node); }
private static List<CallTreeNode> GetChildren(CodeFlow codeFlow, ref int currentCodeFlowIndex, CallTreeNode parent) { currentCodeFlowIndex++; List<CallTreeNode> children = new List<CallTreeNode>(); bool foundCallReturn = false; while (currentCodeFlowIndex < codeFlow.Locations.Count && !foundCallReturn) { switch (codeFlow.Locations[currentCodeFlowIndex].Kind) { case AnnotatedCodeLocationKind.Call: var newNode = new CallTreeNode { Location = codeFlow.Locations[currentCodeFlowIndex], Parent = parent }; newNode.Children = GetChildren(codeFlow, ref currentCodeFlowIndex, newNode); children.Add(newNode); break; case AnnotatedCodeLocationKind.CallReturn: children.Add(new CallTreeNode { Location = codeFlow.Locations[currentCodeFlowIndex], Children = new List<CallTreeNode>(), Parent = parent }); foundCallReturn = true; break; default: children.Add(new CallTreeNode { Location = codeFlow.Locations[currentCodeFlowIndex], Children = new List<CallTreeNode>(), Parent = parent }); currentCodeFlowIndex++; break; } } currentCodeFlowIndex++; return children; }
private CallTree CreateCallTree() { var codeFlow = new CodeFlow { Locations = new List<AnnotatedCodeLocation> { new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Importance = AnnotatedCodeLocationImportance.Unimportant, }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration, Importance = AnnotatedCodeLocationImportance.Important, }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration, Importance = AnnotatedCodeLocationImportance.Essential, }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn, Importance = AnnotatedCodeLocationImportance.Unimportant, }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration, Importance = AnnotatedCodeLocationImportance.Unimportant, }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration, Importance = AnnotatedCodeLocationImportance.Essential, } } }; CallTree callTree = new CallTree(CodeFlowToTreeConverter.Convert(codeFlow)); return callTree; }
internal static List<CallTreeNode> Convert(CodeFlow codeFlow) { int currentCodeFlowIndex = -1; return GetChildren(codeFlow, ref currentCodeFlowIndex, null); }
public void CanConvertCodeFlowToTree() { var codeFlow = new CodeFlow { Locations = new List<AnnotatedCodeLocation> { new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Message = "first parent" }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Message = "second parent" }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Message = "third parent" }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Message = "fourth parent" }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Message = "fifth parent" }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn, }, } }; List<CallTreeNode> topLevelNodes = CodeFlowToTreeConverter.Convert(codeFlow); topLevelNodes.Count.Should().Be(2); topLevelNodes[0].Children.Count.Should().Be(4); topLevelNodes[0].Children[2].Children.Count.Should().Be(1); // Check that we have the right nodes at the right places in the tree. topLevelNodes[0].Location.Kind.Should().Be(AnnotatedCodeLocationKind.Call); topLevelNodes[0].Children[0].Location.Kind.Should().Be(AnnotatedCodeLocationKind.Call); topLevelNodes[0].Children[0].Children[0].Location.Kind.Should().Be(AnnotatedCodeLocationKind.CallReturn); topLevelNodes[0].Children[1].Location.Kind.Should().Be(AnnotatedCodeLocationKind.Call); topLevelNodes[0].Children[1].Children[0].Location.Kind.Should().Be(AnnotatedCodeLocationKind.CallReturn); topLevelNodes[0].Children[2].Location.Kind.Should().Be(AnnotatedCodeLocationKind.Call); topLevelNodes[0].Children[2].Children[0].Location.Kind.Should().Be(AnnotatedCodeLocationKind.CallReturn); topLevelNodes[0].Children[3].Location.Kind.Should().Be(AnnotatedCodeLocationKind.CallReturn); topLevelNodes[1].Location.Kind.Should().Be(AnnotatedCodeLocationKind.Call); topLevelNodes[1].Children[0].Location.Kind.Should().Be(AnnotatedCodeLocationKind.CallReturn); // Check parents topLevelNodes[0].Parent.Should().Be(null); topLevelNodes[0].Children[0].Parent.Location.Message.Should().Be("first parent"); topLevelNodes[0].Children[0].Children[0].Parent.Location.Message.Should().Be("second parent"); topLevelNodes[0].Children[1].Parent.Location.Message.Should().Be("first parent"); topLevelNodes[0].Children[1].Children[0].Parent.Location.Message.Should().Be("third parent"); topLevelNodes[0].Children[2].Parent.Location.Message.Should().Be("first parent"); topLevelNodes[0].Children[2].Children[0].Parent.Location.Message.Should().Be("fourth parent"); topLevelNodes[0].Children[3].Parent.Location.Message.Should().Be("first parent"); topLevelNodes[1].Parent.Should().Be(null); topLevelNodes[1].Children[0].Parent.Location.Message.Should().Be("fifth parent"); }
public void CanConvertCodeFlowToTreeOnlyDeclarations() { var codeFlow = new CodeFlow { Locations = new List<AnnotatedCodeLocation> { new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration }, new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Declaration }, } }; List<CallTreeNode> topLevelNodes = CodeFlowToTreeConverter.Convert(codeFlow); topLevelNodes.Count.Should().Be(3); topLevelNodes[0].Children.Should().BeEmpty(); topLevelNodes[1].Children.Should().BeEmpty(); topLevelNodes[2].Children.Should().BeEmpty(); topLevelNodes[0].Location.Kind.Should().Be(AnnotatedCodeLocationKind.Declaration); topLevelNodes[1].Location.Kind.Should().Be(AnnotatedCodeLocationKind.Declaration); topLevelNodes[2].Location.Kind.Should().Be(AnnotatedCodeLocationKind.Declaration); topLevelNodes[0].Parent.Should().Be(null); topLevelNodes[1].Parent.Should().Be(null); topLevelNodes[2].Parent.Should().Be(null); }
public bool ValueEquals(CodeFlow other) => ValueComparer.Equals(this, other);