当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxToken.GetKind方法代码示例

本文整理汇总了C#中SyntaxToken.GetKind方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.GetKind方法的具体用法?C# SyntaxToken.GetKind怎么用?C# SyntaxToken.GetKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxToken的用法示例。


在下文中一共展示了SyntaxToken.GetKind方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddToken

        private void AddToken(TreeViewItem parentItem, SyntaxToken token)
        {
            var kind = token.GetKind();
            var tag = new SyntaxTag()
            {
                SyntaxToken = token,
                Category = SyntaxCategory.SyntaxToken,
                Span = token.Span,
                FullSpan = token.FullSpan,
                Kind = kind,
                ParentItem = parentItem
            };

            var item = new TreeViewItem()
            {
                Tag = tag,
                IsExpanded = false,
                Foreground = Brushes.DarkGreen,
                Background = token.ContainsDiagnostics ? Brushes.Pink : Brushes.White,
                Header = tag.Kind + " " + token.Span.ToString()
            };

            if (SyntaxTree != null && token.ContainsDiagnostics)
            {
                item.ToolTip = string.Empty;
                foreach (var diagnostic in SyntaxTree.GetDiagnostics(token))
                {
                    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 = token.GetType().Name;
                kindValueLabel.Content = kind;
                _propertyGrid.SelectedObject = token;

                item.IsExpanded = true;

                if (!_isNavigatingFromSourceToTree && SyntaxTokenNavigationToSourceRequested != null)
                {
                    SyntaxTokenNavigationToSourceRequested(token);
                }

                _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);
                    foreach (var trivia in token.LeadingTrivia)
                    {
                        AddTrivia(item, trivia, true);
                    }

                    foreach (var trivia in token.TrailingTrivia)
                    {
                        AddTrivia(item, trivia, false);
                    }
                }
            });

            if (parentItem == null)
            {
                treeView.Items.Clear();
                treeView.Items.Add(item);
            }
            else
            {
                parentItem.Items.Add(item);
            }

            if (token.HasLeadingTrivia || token.HasTrailingTrivia)
            {
                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.
                    foreach (var trivia in token.LeadingTrivia)
                    {
                        AddTrivia(item, trivia, true);
                    }

                    foreach (var trivia in token.TrailingTrivia)
                    {
                        AddTrivia(item, trivia, false);
//.........这里部分代码省略.........
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:101,代码来源:SyntaxVisualizerControl.xaml.cs

示例2: ValidateToken

        private bool ValidateToken(SyntaxToken token, SyntaxTree tree, string filename = "", List<Failure> failures = null)
        {
            var retVal = true;
            foreach (var leadingTrivia in token.LeadingTrivia)
            {
                retVal = retVal & ValidateTrivia(leadingTrivia, tree, filename, failures);
            }

            foreach (var trailingTrivia in token.TrailingTrivia)
            {
                retVal = retVal & ValidateTrivia(trailingTrivia, tree, filename, failures);
            }

            bool pass = false;
            foreach (var rule in m_TokenRules.Values)
            {
                var errorText = string.Empty;
                pass = rule.Test(token, tree, ref errorText);
                if (!pass)
                {
                    if (failures != null)
                    {
                        failures.Add(new Failure(filename, rule, token.GetKind(), errorText, new FailureLocation(token.Span, tree)));
                    }

                    ValidationFailed(errorText, rule);
                }

                retVal = retVal & pass;
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:33,代码来源:TreeValidator.cs

示例3: BadTokens

        public bool BadTokens(SyntaxToken token, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            var kind = token.GetKind();
            if (tree.GetDiagnostics().Any())
            {
                if (kind.Contains("Bad"))
                {
                    if (tree.GetDiagnostics(token).Any())
                    {
                    }
                    else
                    {
                        retVal = false;
                        errorText = "Bad tokens should have at least one error on them";
                    }
                }
            }
            else if (kind.Contains("Bad"))
            {
                retVal = false;
                errorText = "A tree with 0 errors should not contain Bad tokens";
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:26,代码来源:NodeRules.cs

示例4: WhiteSpaceInTokens

        public bool WhiteSpaceInTokens(SyntaxToken token, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            var kind = token.GetKind();
            if (kind != "StatementTerminatorToken" && kind != "DateLiteralToken" && kind != "StringLiteralToken" && kind != "CharacterLiteralToken" && kind != "XmlTextLiteralToken" && kind != "XmlAttributeDataToken" && kind != "XmlCommentDataToken" && kind != "XmlCDataToken" && kind != "XmlProcessingInstructionDataToken" && kind != "XmlTextLiteralNewLineToken" && kind != "LessThanEqualsToken" && kind != "GreaterThanEqualsToken" && kind != "LessThanGreaterThanToken" && kind != "ColonEqualsToken" && kind != "CaretEqualsToken" && kind != "AsteriskEqualsToken" && kind != "PlusEqualsToken" && kind != "MinusEqualsToken" && kind != "SlashEqualsToken" && kind != "BackslashEqualsToken" && kind != "LessThanLessThanToken" && kind != "GreaterThanGreaterThanToken" && kind != "LessThanLessThanEqualsToken" && kind != "GreaterThanGreaterThanEqualsToken" && kind != "AmpersandEqualsToken")
            {
                var text = token.ToString();
                if ((text.Contains(" ") || text.Contains('\t') || text.Contains('\r') || text.Contains('\n') || text.Contains("\r\n")))
                {
                    retVal = false;
                    errorText = "The text of this token should not contain any whitespace";
                }
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:16,代码来源:NodeRules.cs

示例5: ZeroWidthOrMissingTokens

        public bool ZeroWidthOrMissingTokens(SyntaxToken token, SyntaxTree tree, ref string errorText)
        {
            var retVal = true;
            if (token.ContainsDiagnostics || tree.GetDiagnostics().Any())
            {
                if (token.IsMissing)
                {
                    if (token.Span.Length == 0)
                    {
                        if (token.LeadingTrivia.Any() || token.TrailingTrivia.Any())
                        {
                            var atleastOneSkippedTrivia = (
                                from leadingTrivia in token.LeadingTrivia
                                let kind = leadingTrivia.GetKind()
                                where kind == "SkippedTextTrivia" || kind == "SkippedTokens"
                                select new
                                {
                                    leadingTrivia,
                                    kind
                                }

                            ).Any();
                            if (!atleastOneSkippedTrivia)
                            {
                                atleastOneSkippedTrivia = (
                                    from trailingTrivia in token.TrailingTrivia
                                    let kind = trailingTrivia.GetKind()
                                    where kind == "SkippedTextTrivia" || kind == "SkippedTokens"
                                    select new
                                    {
                                        trailingTrivia,
                                        kind
                                    }

                                ).Any();
                                if (!atleastOneSkippedTrivia)
                                {
                                    retVal = false;
                                    errorText = "Missing tokens should have at least one trivia with kind SkippedTextTrivia OR SkippedTokens";
                                }
                            }
                        }
                    }
                    else
                    {
                        retVal = false;
                        errorText = "Missing tokens should have 0 Span width";
                    }
                }
                else if (token.Span.Length == 0)
                {
                    var kind = token.GetKind();
                    if (!(kind == "EndOfFileToken" || kind == "EmptyToken" || kind == "EndOfDocumentationCommentToken" || kind == "EndOfDirectiveToken" || kind.Contains("Bad")))
                    {
                        //BadToken only appears in error trees for C#.
                        retVal = false;
                        errorText = "Tokens with 0 Span width should have IsMissing set to 'True'";
                    }
                }
            }
            else
            {
                if (token.IsMissing)
                {
                    retVal = false;
                    errorText = "A tree with 0 errors should not contain missing tokens";
                }
                else if (token.Span.Length == 0)
                {
                    var kind = token.GetKind();
                    if (!(kind == "EndOfFileToken" || kind == "EmptyToken" || kind == "EndOfDocumentationCommentToken" || kind == "EndOfDirectiveToken"))
                    {
                        //EmptyToken can be present even in non-error cases in VB (it is used for OmittedArgument).
                        retVal = false;
                        errorText = "A tree with 0 errors should not contain tokens with 0 width";
                    }
                }
            }

            return retVal;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:81,代码来源:NodeRules.cs


注:本文中的SyntaxToken.GetKind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。