internal void IntelligentExpand() { if (Location?.Importance == CodeFlowLocationImportance.Essential) { CallTreeNode current = this; while (current != null) { current.IsExpanded = true; current = current.Parent; } } else { IsExpanded = false; } if (Children != null) { foreach (CallTreeNode child in Children) { child.IntelligentExpand(); } } }
public void CallTreeNode_SelectedHighlightColor() { var callTreeNode = new CallTreeNode { Location = new AnnotatedCodeLocation(), }; callTreeNode.Location.Importance = AnnotatedCodeLocationImportance.Essential; callTreeNode.SelectedSourceHighlightColor.Should().Be("CodeAnalysisCurrentStatementSelection"); }
internal void IntelligentExpand() { foreach (CallTree callTree in this) { CallTreeNode selectedItem = callTree.SelectedItem; callTree.IntelligentExpand(); callTree.SelectedItem = selectedItem; } }
internal CallTreeNode FindNext() { CallTreeNode next = FindNext(this.SelectedItem, true); if (next == null) { // no next exists, current remains selected return(this.SelectedItem); } else { return(next); } }
// go to parent, find self, find previous/next, make sure not to roll off internal CallTreeNode FindPrevious() { CallTreeNode previous = FindPrevious(this.SelectedItem, true); if (previous == null) { // no previous exists, current remains selected return(this.SelectedItem); } else { return(previous); } }
internal void SetVerbosity(CodeFlowLocationImportance importance) { Visibility visibility = Visibility.Visible; CodeFlowLocationImportance myImportance = (Location?.Importance).GetValueOrDefault(CodeFlowLocationImportance.Unimportant); switch (importance) { case CodeFlowLocationImportance.Essential: if (myImportance != CodeFlowLocationImportance.Essential) { visibility = Visibility.Collapsed; } break; case CodeFlowLocationImportance.Important: if (myImportance == CodeFlowLocationImportance.Unimportant) { visibility = Visibility.Collapsed; } break; default: visibility = Visibility.Visible; break; } if (visibility == Visibility.Visible) { CallTreeNode current = this; while (current != null) { current.Visibility = Visibility.Visible; current = current.Parent; } } else { Visibility = Visibility.Collapsed; } if (Children != null) { foreach (CallTreeNode child in Children) { child.SetVerbosity(importance); } } }
public void CallTreeNode_DefaultHighlightColor() { var callTreeNode = new CallTreeNode { Location = new AnnotatedCodeLocation(), }; callTreeNode.Location.Importance = AnnotatedCodeLocationImportance.Essential; callTreeNode.DefaultSourceHighlightColor.Should().Be("CodeAnalysisKeyEventSelection"); callTreeNode.Location.Importance = AnnotatedCodeLocationImportance.Important; callTreeNode.DefaultSourceHighlightColor.Should().Be("CodeAnalysisLineTraceSelection"); callTreeNode.Location.Importance = AnnotatedCodeLocationImportance.Unimportant; callTreeNode.DefaultSourceHighlightColor.Should().Be("CodeAnalysisLineTraceSelection"); }
private static string MakeDisplayString(CallTreeNode node) { // Use the following preferences for the CallTreeNode text. // 1. AnnotatedCodeLocation.Message // 2. AnnotatedCodeLocation.Snippet // 3. Callee for calls // 4. "Return" for returns // 5. AnnotatedCodeLocation.Kind string text = string.Empty; AnnotatedCodeLocation annotatedLocation = node.Location; if (annotatedLocation != null) { if (!String.IsNullOrEmpty(annotatedLocation.Message)) { text = annotatedLocation.Message; } else if (!String.IsNullOrEmpty(annotatedLocation.Snippet)) { text = annotatedLocation.Snippet.Trim(); } else { switch (annotatedLocation.Kind) { case AnnotatedCodeLocationKind.Call: string callee = annotatedLocation.Target; text = !string.IsNullOrEmpty(callee) ? callee : Resources.UnknownCalleMessage; break; case AnnotatedCodeLocationKind.CallReturn: text = Resources.ReturnMessage; break; default: if (annotatedLocation.Kind != default(AnnotatedCodeLocationKind)) { text = annotatedLocation.Kind.ToString(); } break; } } } return text; }
internal void IntelligentExpand() { if (!SarifViewerPackage.IsUnitTesting) { #pragma warning disable VSTHRD108 // Assert thread affinity unconditionally ThreadHelper.ThrowIfNotOnUIThread(); #pragma warning restore VSTHRD108 // Assert thread affinity unconditionally } foreach (CallTree callTree in this) { CallTreeNode selectedItem = callTree.SelectedItem; callTree.IntelligentExpand(); callTree.SelectedItem = selectedItem; } }
internal static bool TryGetFirstItem(IList <CallTreeNode> items, out CallTreeNode firstItem) { firstItem = null; if (items != null) { for (int i = 0; i < items.Count; i++) { CallTreeNode nextNode = items[i]; if (nextNode.Visibility == System.Windows.Visibility.Visible) { firstItem = nextNode; break; } } } return(firstItem != null); }
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; }
public void CallTreeNodeToTextConverter_HandlesCallWithNoCallee() { var callTreeNode = new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, PhysicalLocation = new PhysicalLocation { Region = new Region { StartLine = 42 } } } }; VerifyConversion(callTreeNode, "<unknown callee>"); }
internal static bool TryGetLastItem(IList <CallTreeNode> items, out CallTreeNode lastItem) { lastItem = null; if (items != null) { for (int i = items.Count - 1; i >= 0; i--) { CallTreeNode nextNode = items[i]; if (nextNode.Visibility == System.Windows.Visibility.Visible) { lastItem = nextNode; break; } } } return(lastItem != null); }
internal static bool TryGetIndexInCallTreeNodeList(IList <CallTreeNode> list, CallTreeNode givenNode, out int index) { index = -1; if (list != null) { for (int i = 0; i < list.Count; i++) { CallTreeNode listNode = list[i]; if (listNode == givenNode) { index = i; break; } } } return(index != -1); }
internal CallTreeNode FindPrevious(CallTreeNode currentNode, bool includeChildren) { if (currentNode == null) { return(null); } CallTreeNode previousNode; // Find the next visible sibling. CallTreeNode currentParent = currentNode.Parent; IList <CallTreeNode> nodeList; if (currentParent == null) { nodeList = this.TopLevelNodes; } else { nodeList = currentParent.Children; } if (TryGetPreviousSibling(nodeList, currentNode, out previousNode)) { CallTreeNode previousNodeChild; if (includeChildren && TryGetLastItem(previousNode.Children, out previousNodeChild)) { return(previousNodeChild); } else { return(previousNode); } } else if (currentParent != null && currentParent.Visibility == System.Windows.Visibility.Visible) { return(currentParent); } // Walk up the tree trying to find the previous node. return(FindPrevious(currentParent, false)); }
public void CallTreeNodeToTextConverter_HandlesCall() { var callTreeNode = new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Target = "my_function", PhysicalLocation = new PhysicalLocation { Region = new Region { StartLine = 42 } } } }; VerifyConversion(callTreeNode, "my_function"); }
internal static bool TryGetNextSibling(IList <CallTreeNode> items, CallTreeNode currentItem, out CallTreeNode nextSibling) { nextSibling = null; int currentIndex; if (TryGetIndexInCallTreeNodeList(items, currentItem, out currentIndex)) { for (int i = currentIndex + 1; i < items.Count; i++) { CallTreeNode nextNode = items[i]; if (nextNode.Visibility == System.Windows.Visibility.Visible) { nextSibling = nextNode; break; } } } return(nextSibling != null); }
internal static bool TryGetPreviousSibling(IList <CallTreeNode> items, CallTreeNode currentItem, out CallTreeNode previousSibling) { previousSibling = null; int currentIndex; if (TryGetIndexInCallTreeNodeList(items, currentItem, out currentIndex)) { for (int i = currentIndex - 1; i >= 0; i--) { CallTreeNode previousNode = items[i]; if (previousNode.Visibility == System.Windows.Visibility.Visible) { previousSibling = previousNode; break; } } } return(previousSibling != null); }
internal CallTreeNode FindNext(CallTreeNode currentNode, bool includeChildren) { if (currentNode == null) { return(null); } // For Call nodes, find the first visible child. CallTreeNode nextNode; if (includeChildren && TryGetFirstItem(currentNode.Children, out nextNode)) { return(nextNode); } // For all other nodes or Call nodes without a visible child, find the next visible sibling. CallTreeNode currentParent = currentNode.Parent; IList <CallTreeNode> nodeList; if (currentParent == null) { nodeList = this.TopLevelNodes; } else { nodeList = currentParent.Children; } if (TryGetNextSibling(nodeList, currentNode, out nextNode)) { return(nextNode); } // Walk up the tree trying to find the next node. return(FindNext(currentParent, false)); }
public void CallTree_TryGetIndexInCallTreeNodeList_NullList() { List<CallTreeNode> list = null; CallTreeNode node = new CallTreeNode(); int index; bool result = CallTree.TryGetIndexInCallTreeNodeList(list, node, out index); result.Should().BeFalse(); }
public void CallTree_TryGetIndexInCallTreeNodeList_MiddleNode() { List<CallTreeNode> list = new List<CallTreeNode>(); CallTreeNode target = new CallTreeNode(); list.Add(new CallTreeNode()); list.Add(target); list.Add(new CallTreeNode()); int index; bool result = CallTree.TryGetIndexInCallTreeNodeList(list, target, out index); result.Should().BeTrue(); index.Should().Be(1); }
internal static bool TryGetPreviousSibling(IList<CallTreeNode> items, CallTreeNode currentItem, out CallTreeNode previousSibling) { previousSibling = null; int currentIndex; if (TryGetIndexInCallTreeNodeList(items, currentItem, out currentIndex)) { for (int i = currentIndex - 1; i >= 0; i--) { CallTreeNode previousNode = items[i]; if (previousNode.Visibility == System.Windows.Visibility.Visible) { previousSibling = previousNode; break; } } } return previousSibling != null; }
internal static bool TryGetNextSibling(IList<CallTreeNode> items, CallTreeNode currentItem, out CallTreeNode nextSibling) { nextSibling = null; int currentIndex; if (TryGetIndexInCallTreeNodeList(items, currentItem, out currentIndex)) { for (int i = currentIndex + 1; i < items.Count; i++) { CallTreeNode nextNode = items[i]; if (nextNode.Visibility == System.Windows.Visibility.Visible) { nextSibling = nextNode; break; } } } return nextSibling != null; }
internal static bool TryGetFirstItem(IList<CallTreeNode> items, out CallTreeNode firstItem) { firstItem = null; if (items != null) { for (int i = 0; i < items.Count; i++) { CallTreeNode nextNode = items[i]; if (nextNode.Visibility == System.Windows.Visibility.Visible) { firstItem = nextNode; break; } } } return firstItem != null; }
public void CallTreeNodeToTextConverter_HandlesMessage() { string snippet = " contentStores[0] = contentStores[index];"; string message = "The error happened here."; string sourceFile = @"file:///c:/dir1/dir%202\source%20file.cpp"; var callTreeNode = new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Snippet = snippet, Message = message, Target = "my_function", PhysicalLocation = new PhysicalLocation { Uri = new System.Uri(sourceFile), Region = new Region { StartLine = 42 } } } }; VerifyConversion(callTreeNode, message); }
public void CallTree_TryGetPreviousSibling_NoVisibleNodes() { List<CallTreeNode> list = new List<CallTreeNode>(); CallTreeNode target = new CallTreeNode(); list.Add(new CallTreeNode() { Visibility = Visibility.Collapsed }); list.Add(new CallTreeNode() { Visibility = Visibility.Hidden }); list.Add(target); list.Add(new CallTreeNode()); CallTreeNode resultNode; bool result = CallTree.TryGetPreviousSibling(list, target, out resultNode); result.Should().BeFalse(); }
public void CallTreeNodeToTextConverter_HandlesNullSnippet() { string snippet = null; string sourceFile = @"file:///c:/dir1/dir%202\source%20file.cpp"; var callTreeNode = new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Snippet = snippet, Target = "my_function", PhysicalLocation = new PhysicalLocation { Uri = new System.Uri(sourceFile), Region = new Region { StartLine = 42 } } } }; VerifyConversion(callTreeNode, "my_function"); }
internal CallTreeNode FindPrevious(CallTreeNode currentNode, bool includeChildren) { if (currentNode == null) { return null; } CallTreeNode previousNode; // Find the next visible sibling. CallTreeNode currentParent = currentNode.Parent; IList<CallTreeNode> nodeList; if (currentParent == null) { nodeList = this.TopLevelNodes; } else { nodeList = currentParent.Children; } if (TryGetPreviousSibling(nodeList, currentNode, out previousNode)) { CallTreeNode previousNodeChild; if (includeChildren && previousNode.Location.Kind == AnnotatedCodeLocationKind.Call && TryGetLastItem(previousNode.Children, out previousNodeChild)) { return previousNodeChild; } else { return previousNode; } } else if (currentParent != null && currentParent.Visibility == System.Windows.Visibility.Visible) { return currentParent; } // Walk up the tree trying to find the previous node. return FindPrevious(currentParent, false); }
public void CallTree_TryGetPreviousSibling_SkipNonVisibleNodes() { List<CallTreeNode> list = new List<CallTreeNode>(); CallTreeNode target = new CallTreeNode(); list.Add(new CallTreeNode() { FilePath = Expected }); list.Add(new CallTreeNode() { Visibility = Visibility.Collapsed }); list.Add(new CallTreeNode() { Visibility = Visibility.Hidden }); list.Add(target); list.Add(new CallTreeNode()); CallTreeNode resultNode; bool result = CallTree.TryGetPreviousSibling(list, target, out resultNode); result.Should().BeTrue(); resultNode.FilePath.Should().Be(Expected); }
internal static bool TryGetLastItem(IList<CallTreeNode> items, out CallTreeNode lastItem) { lastItem = null; if (items != null) { for (int i = items.Count - 1; i >= 0; i--) { CallTreeNode nextNode = items[i]; if (nextNode.Visibility == System.Windows.Visibility.Visible) { lastItem = nextNode; break; } } } return lastItem != null; }
public void CallTree_TryGetNextSibling_LastNode() { List<CallTreeNode> list = new List<CallTreeNode>(); CallTreeNode target = new CallTreeNode(); list.Add(new CallTreeNode()); list.Add(new CallTreeNode()); list.Add(target); CallTreeNode resultNode; bool result = CallTree.TryGetNextSibling(list, target, out resultNode); result.Should().BeFalse(); }
public void CallTreeNodeToTextConverter_HandlesNonCallOrReturnNodes() { var callTreeNode = new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Continuation, PhysicalLocation = new PhysicalLocation { Region = new Region { StartLine = 42 } } } }; VerifyConversion(callTreeNode, "Continuation"); }
public void CallTree_TryGetPreviousSibling_MiddleNode() { List<CallTreeNode> list = new List<CallTreeNode>(); CallTreeNode target = new CallTreeNode(); list.Add(new CallTreeNode() { FilePath = Expected }); list.Add(target); list.Add(new CallTreeNode()); CallTreeNode resultNode; bool result = CallTree.TryGetPreviousSibling(list, target, out resultNode); result.Should().BeTrue(); resultNode.FilePath.Should().Be(Expected); }
internal static bool TryGetIndexInCallTreeNodeList(IList<CallTreeNode> list, CallTreeNode givenNode, out int index) { index = -1; if (list != null) { for (int i = 0; i < list.Count; i++) { CallTreeNode listNode = list[i]; if (listNode == givenNode) { index = i; break; } } } return index != -1; }
public void CallTree_TryGetPreviousSibling_NullList() { List<CallTreeNode> list = null; CallTreeNode node = new CallTreeNode(); CallTreeNode resultNode; bool result = CallTree.TryGetPreviousSibling(list, node, out resultNode); result.Should().BeFalse(); }
private static void VerifyConversion(CallTreeNode callTreeNode, string expectedText) { var converter = new CallTreeNodeToTextConverter(); string text = (string)converter.Convert(callTreeNode, typeof(string), null, CultureInfo.CurrentCulture); text.Should().Be(expectedText); }
public void CallTreeNodeToTextConverter_HandlesMissingRegion() { var callTreeNode = new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn, PhysicalLocation = new PhysicalLocation() } }; VerifyConversion(callTreeNode, "Return"); }
internal CallTreeNode FindNext(CallTreeNode currentNode, bool includeChildren) { if (currentNode == null) { return null; } // For Call nodes, find the first visible child. CallTreeNode nextNode; if (includeChildren && currentNode.Location.Kind == AnnotatedCodeLocationKind.Call && TryGetFirstItem(currentNode.Children, out nextNode)) { return nextNode; } // For all other nodes or Call nodes without a visible child, find the next visible sibling. CallTreeNode currentParent = currentNode.Parent; IList<CallTreeNode> nodeList; if (currentParent == null) { nodeList = this.TopLevelNodes; } else { nodeList = currentParent.Children; } if (TryGetNextSibling(nodeList, currentNode, out nextNode)) { return nextNode; } // Walk up the tree trying to find the next node. return FindNext(currentParent, false); }