private static Trivia.TriviaTypes GetTriviaType(SyntaxTrivia t) { if (t.Kind() == SyntaxKind.RegionDirectiveTrivia) { return(Trivia.TriviaTypes.RegionDirectiveTriviaSyntaxType); } else if (t.Kind() == SyntaxKind.SingleLineCommentTrivia) { return(Trivia.TriviaTypes.SingleLineCommentTriviaType); } else if (t.Kind() == SyntaxKind.EndRegionDirectiveTrivia) { return(Trivia.TriviaTypes.EndRegionDirectiveTriviaType); } else if (t.Kind() == SyntaxKind.MultiLineCommentTrivia) { return(Trivia.TriviaTypes.MultiLineCommentTriviaType); } else if (t.Kind() == SyntaxKind.SingleLineDocumentationCommentTrivia) { return(Trivia.TriviaTypes.SingleLineDocumentationCommentTriviaType); } else if (t.Kind() == SyntaxKind.IfDirectiveTrivia) { return(Trivia.TriviaTypes.IfDirectiveTriviaType); } else if (t.Kind() == SyntaxKind.DisabledTextTrivia) { return(Trivia.TriviaTypes.DisabledTextTriviaType); } else if (t.Kind() == SyntaxKind.ElseDirectiveTrivia) { return(Trivia.TriviaTypes.ElseDirectiveTriviaType); } else if (t.Kind() == SyntaxKind.PragmaChecksumDirectiveTrivia) { return(Trivia.TriviaTypes.PragmaChecksumDirectiveTriviaType); } else if (t.Kind() == SyntaxKind.LineDirectiveTrivia) { return(Trivia.TriviaTypes.LineDirectiveTriviaType); } else { #if DEBUG Console.WriteLine(t.GetType().Name); var code = t.ToString().Length > 50 ? t.ToString().Substring(0, 50) : t.ToString(); Console.WriteLine(code); throw new Exception(t.Kind().ToString()); #else return(Trivia.TriviaTypes.UnknownTriviaSyntaxType); #endif } }
public static NodeInfo GetNodeInfo(this SyntaxTrivia trivia) { var typeObject = trivia.GetType(); var nodeClassName = typeObject.Name; var properties = typeObject.GetTypeInfo().DeclaredProperties; return(new NodeInfo(typeObject.Name, ( from p in properties where IsField(p) select GetFieldInfo(p, trivia)).ToArray())); }
public static NodeInfo GetNodeInfo(this SyntaxTrivia trivia) { var typeObject = trivia.GetType(); var nodeClassName = typeObject.Name; var properties = typeObject.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); return(new NodeInfo(typeObject.Name, ( from p in properties where IsField(p) select GetFieldInfo(p, trivia)).ToArray())); }
private void AddTrivia(TreeViewItem parentItem, SyntaxTrivia trivia, bool isLeadingTrivia) { var kind = trivia.GetKind(); var tag = new SyntaxTag() { SyntaxTrivia = trivia, Category = SyntaxCategory.SyntaxTrivia, Span = trivia.Span, FullSpan = trivia.FullSpan, Kind = kind, ParentItem = parentItem }; var item = new TreeViewItem() { Tag = tag, IsExpanded = false, Foreground = Brushes.Maroon, Background = trivia.ContainsDiagnostics ? Brushes.Pink : Brushes.White, Header = (isLeadingTrivia ? "Lead: " : "Trail: ") + tag.Kind + " " + trivia.Span.ToString() }; if (SyntaxTree != null && trivia.ContainsDiagnostics) { item.ToolTip = string.Empty; foreach (var diagnostic in SyntaxTree.GetDiagnostics(trivia)) { item.ToolTip += diagnostic.ToString() + "\n"; } item.ToolTip = item.ToolTip.ToString().Trim(); } item.Selected += new RoutedEventHandler((sender, e) => { _isNavigatingFromTreeToSource = true; typeTextLabel.Visibility = Visibility.Visible; kindTextLabel.Visibility = Visibility.Visible; typeValueLabel.Content = trivia.GetType().Name; kindValueLabel.Content = kind; _propertyGrid.SelectedObject = trivia; item.IsExpanded = true; if (!_isNavigatingFromSourceToTree && SyntaxTriviaNavigationToSourceRequested != null) { SyntaxTriviaNavigationToSourceRequested(trivia); } _isNavigatingFromTreeToSource = false; e.Handled = true; }); item.Expanded += new RoutedEventHandler((sender, e) => { if (item.Items.Count == 1 && item.Items[0] == null) { // Remove placeholder child and populate real children. item.Items.RemoveAt(0); AddNode(item, trivia.GetStructure()); } }); if (parentItem == null) { treeView.Items.Clear(); treeView.Items.Add(item); typeTextLabel.Visibility = Visibility.Hidden; kindTextLabel.Visibility = Visibility.Hidden; typeValueLabel.Content = string.Empty; kindValueLabel.Content = string.Empty; } else { parentItem.Items.Add(item); } if (trivia.HasStructure) { if (IsLazy) { // Add placeholder child to indicate that real children need to be populated on expansion. item.Items.Add(null); } else { // Recursively populate all descendants. AddNode(item, trivia.GetStructure()); } } }
private void AddTrivia(TreeViewItem parentItem, SyntaxTrivia trivia, bool isLeadingTrivia) { var kind = trivia.GetKind(); var tag = new SyntaxTag() { SyntaxTrivia = trivia, Category = SyntaxCategory.SyntaxTrivia, Span = trivia.Span, FullSpan = trivia.FullSpan, Kind = kind, ParentItem = parentItem }; var item = CreateTreeViewItem(tag, (isLeadingTrivia ? "Lead: " : "Trail: ") + tag.Kind + " " + trivia.Span.ToString(), trivia.ContainsDiagnostics); item.SetResourceReference(ForegroundProperty, SyntaxTriviaTextBrushKey); if (SyntaxTree != null && trivia.ContainsDiagnostics) { item.ToolTip = string.Empty; foreach (var diagnostic in SyntaxTree.GetDiagnostics(trivia)) { item.ToolTip += diagnostic.ToString() + "\n"; } item.ToolTip = item.ToolTip.ToString().Trim(); } item.Selected += new RoutedEventHandler((sender, e) => { _isNavigatingFromTreeToSource = true; typeTextLabel.Visibility = Visibility.Visible; kindTextLabel.Visibility = Visibility.Visible; typeValueLabel.Content = trivia.GetType().Name; kindValueLabel.Content = kind; _propertyGrid.SelectedObject = trivia; item.IsExpanded = true; if (!_isNavigatingFromSourceToTree && SyntaxTriviaNavigationToSourceRequested != null) { SyntaxTriviaNavigationToSourceRequested(trivia); } _isNavigatingFromTreeToSource = false; e.Handled = true; }); item.Expanded += new RoutedEventHandler((sender, e) => { if (item.Items.Count == 1 && item.Items[0] == null) { // Remove placeholder child and populate real children. item.Items.RemoveAt(0); AddNode(item, trivia.GetStructure()); } }); if (parentItem == null) { treeView.Items.Clear(); treeView.Items.Add(item); typeTextLabel.Visibility = Visibility.Hidden; kindTextLabel.Visibility = Visibility.Hidden; typeValueLabel.Content = string.Empty; kindValueLabel.Content = string.Empty; } else { parentItem.Items.Add(item); } if (trivia.HasStructure) { if (IsLazy) { // Add placeholder child to indicate that real children need to be populated on expansion. item.Items.Add(null); } else { // Recursively populate all descendants. AddNode(item, trivia.GetStructure()); } } }