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


C# SyntaxNodeOrToken.AsToken方法代码示例

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


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

示例1: Run

        public override Match Run(SyntaxNodeOrToken nodeOrToken)
        {
            if (nodeOrToken.Kind() != _kind)
                return Match.NoMatch;

            return nodeOrToken.AsToken().ValueText == _text ? Match.Success : Match.NoMatch;
        }
开发者ID:terrajobst,项目名称:apiporter,代码行数:7,代码来源:TokenMatcher.cs

示例2: ClassifyNodeOrToken

        private void ClassifyNodeOrToken(SyntaxNodeOrToken nodeOrToken)
        {
            if (nodeOrToken.IsToken)
            {
                ClassifyToken(nodeOrToken.AsToken());
                return;
            }

            ClassifyNode(nodeOrToken.AsNode());
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:10,代码来源:Worker.cs

示例3: SourceLabelSymbol

 public SourceLabelSymbol(
     MethodSymbol containingMethod,
     SyntaxNodeOrToken identifierNodeOrToken,
     ConstantValue switchCaseLabelConstant = null)
     : base(identifierNodeOrToken.IsToken ? identifierNodeOrToken.AsToken().ValueText : identifierNodeOrToken.ToString())
 {
     this.containingMethod = containingMethod;
     this.identifierNodeOrToken = identifierNodeOrToken;
     this.switchCaseLabelConstant = switchCaseLabelConstant;
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:SourceLabelSymbol.cs

示例4: Run

        public override Match Run(SyntaxNodeOrToken nodeOrToken)
        {
            if (nodeOrToken.Kind() != SyntaxKind.IdentifierToken)
                return Match.NoMatch;

            var identifier = nodeOrToken.AsToken().ValueText;
            var regex = _variable.Regex;
            if (!string.IsNullOrEmpty(regex))
            {
                var regexOptions = _variable.CaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase;
                if (!Regex.IsMatch(identifier, regex, regexOptions))
                    return Match.NoMatch;
            }

            return Match.Success.AddCapture(_variable, nodeOrToken);
        }
开发者ID:terrajobst,项目名称:apiporter,代码行数:16,代码来源:IdentifierRegexMatcher.cs

示例5: CheckParents

        public static void CheckParents(SyntaxNodeOrToken nodeOrToken, SyntaxTree expectedSyntaxTree)
        {
            Assert.Equal(expectedSyntaxTree, nodeOrToken.SyntaxTree);

            var span = nodeOrToken.Span;

            if (nodeOrToken.IsToken)
            {
                var token = nodeOrToken.AsToken();
                foreach (var trivia in token.LeadingTrivia)
                {
                    var tspan = trivia.Span;
                    var parentToken = trivia.Token;
                    Assert.Equal(parentToken, token);
                    if (trivia.HasStructure)
                    {
                        var parentTrivia = trivia.GetStructure().Parent;
                        Assert.Null(parentTrivia);
                        CheckParents((CSharpSyntaxNode)trivia.GetStructure(), expectedSyntaxTree);
                    }
                }

                foreach (var trivia in token.TrailingTrivia)
                {
                    var tspan = trivia.Span;
                    var parentToken = trivia.Token;
                    Assert.Equal(parentToken, token);
                    if (trivia.HasStructure)
                    {
                        var parentTrivia = trivia.GetStructure().Parent;
                        Assert.Null(parentTrivia);
                        CheckParents(trivia.GetStructure(), expectedSyntaxTree);
                    }
                }
            }
            else
            {
                var node = nodeOrToken.AsNode();
                foreach (var child in node.ChildNodesAndTokens())
                {
                    var parent = child.Parent;
                    Assert.Equal(node, parent);
                    CheckParents(child, expectedSyntaxTree);
                }
            }
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:46,代码来源:ParentChecker.cs

示例6: AddNodeOrToken

        // Helpers for populating the treeview.

        private void AddNodeOrToken(TreeViewItem parentItem, SyntaxNodeOrToken nodeOrToken)
        {
            if (nodeOrToken.IsNode)
            {
                AddNode(parentItem, nodeOrToken.AsNode());
            }
            else
            {
                AddToken(parentItem, nodeOrToken.AsToken());
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:13,代码来源:SyntaxVisualizerControl.xaml.cs

示例7: SourceLocationWithAssociatedNode

 public SourceLocationWithAssociatedNode(SyntaxTree syntaxTree, SyntaxNodeOrToken nodeOrToken, bool associateInParent = false)
     : this(syntaxTree, nodeOrToken.Span, nodeOrToken.IsNode ? nodeOrToken.AsNode() : nodeOrToken.AsToken().Parent, associateInParent)
 {
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:4,代码来源:SourceLocationWithAssociatedNode.cs

示例8: CanReuse

            private bool CanReuse(SyntaxNodeOrToken nodeOrToken)
            {
                // Zero width nodes and tokens always indicate that the parser had to do
                // something tricky, so don't reuse them.
                // NOTE: this is slightly different from IsMissing because of omitted type arguments
                // and array size expressions.
                if (nodeOrToken.FullWidth == 0)
                {
                    return false;
                }

                // As of 2013/03/14, the compiler never attempts to incrementally parse a tree containing
                // annotations.  Our goal in instituting this restriction is to prevent API clients from
                // taking a depedency on the survival of annotations.
                if (nodeOrToken.ContainsAnnotations)
                {
                    return false;
                }

                // We can't reuse a node or token if it intersects a changed text range.
                if (this.IntersectsNextChange(nodeOrToken))
                {
                    return false;
                }

                // don't reuse nodes or tokens with skipped text or diagnostics attached to them
                if (nodeOrToken.ContainsDiagnostics ||
                    (nodeOrToken.IsToken && ((CSharpSyntaxNode)nodeOrToken.AsToken().Node).ContainsSkippedText && nodeOrToken.Parent.ContainsDiagnostics))
                {
                    return false;
                }

                // fabricated tokens did not come from the lexer (likely from parser)
                if (IsFabricatedToken(nodeOrToken.CSharpKind()))
                {
                    return false;
                }

                // don't reuse nodes that are incomplete. this helps cases were an incomplete node
                // completes differently after a change with far look-ahead.
                //
                // NOTE(cyrusn): It is very unfortunate that we even need this check given that we
                // have already checked for ContainsDiagnostics above.  However, there is a case where we
                // can have a node with a missing token *and* there are no diagnostics.
                // Specifically, this happens in the REPL when you have the last statement without a
                // trailing semicolon.  We treat this as an ExpressionStatement with a missing
                // semicolon, but we do not report errors.  It would be preferable to fix that so
                // that the semicolon can be optional rather than abusing the system.
                if ((nodeOrToken.IsToken && nodeOrToken.AsToken().IsMissing) ||
                    (nodeOrToken.IsNode && IsIncomplete((CSharp.CSharpSyntaxNode)nodeOrToken.AsNode())))
                {
                    return false;
                }

                if (!nodeOrToken.ContainsDirectives)
                {
                    return true;
                }

                return this.newDirectives.IncrementallyEquivalent(this.oldDirectives);
            }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:61,代码来源:Blender.Reader.cs

示例9: TryGetVariable

 public bool TryGetVariable(SyntaxNodeOrToken nodeOrToken, out PatternVariable variable)
 {
     return nodeOrToken.IsToken
         ? TryGetVariable(nodeOrToken.AsToken(), out variable)
         : TryGetVariable(nodeOrToken.AsNode(), out variable);
 }
开发者ID:terrajobst,项目名称:apiporter,代码行数:6,代码来源:Pattern.cs

示例10: ClassifyNodeOrToken

 private void ClassifyNodeOrToken(SyntaxNodeOrToken nodeOrToken)
 {
     var node = nodeOrToken.AsNode();
     if (node != null)
     {
         ClassifyNode(node);
     }
     else
     {
         ClassifyToken(nodeOrToken.AsToken());
     }
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:AbstractClassificationService.Worker.cs

示例11: VisitImpl

        private void VisitImpl(SyntaxNodeOrToken nodeOrToken)
        {
            greatestChildPosition.Add(nodeOrToken, 0);

            SyntaxNode node = nodeOrToken.AsNode();

            IList<string> identity;
            if (node is CompilationUnitSyntax)
            {
                identity = new List<string>();
                identity.Add("CompilationUnit");
                identities.Add(nodeOrToken, identity);
            }
            else
            {
                identity = identities[nodeOrToken.Parent].ToList();
            }

            string name = null;
            if (node is NamespaceDeclarationSyntax)
            {
                name = ((NamespaceDeclarationSyntax)node).Name.ToString();
            }
            else if (node is ClassDeclarationSyntax)
            {
                name = ((ClassDeclarationSyntax)node).Identifier.ValueText;
            }
            else if (node is VariableDeclaratorSyntax)
            {
                name = ((VariableDeclaratorSyntax)node).Identifier.ValueText;
            }
            else if (node is MethodDeclarationSyntax)
            {
                name = ((MethodDeclarationSyntax)node).Identifier.ValueText;
            }
            else if (node is PropertyDeclarationSyntax)
            {
                name = ((PropertyDeclarationSyntax)node).Identifier.ValueText;
            }
            else if (node is UsingDirectiveSyntax)
            {
                name = ((UsingDirectiveSyntax)node).Name.ToFullString().Replace(".", string.Empty) ;
            }
            else if (nodeOrToken.IsToken)
            {
                name = nodeOrToken.AsToken().ValueText;
            }

            if (!(node is CompilationUnitSyntax))
            {
                identity.Add(
                    string.Format("{0}{1}", name,
                    (++greatestChildPosition[nodeOrToken.Parent]).ToString()));
                identities.Add(nodeOrToken, identity);
            }
        }
开发者ID:dpetillo,项目名称:genesis,代码行数:56,代码来源:IdentifyingSyntaxVisitor.cs

示例12: ValidateNodeOrToken

        private bool ValidateNodeOrToken(SyntaxNodeOrToken nodeOrtoken, SyntaxTree tree, string filename = "", List<Failure> failures = null)
        {
            var retVal = true;
            if (nodeOrtoken.IsNode)
            {
                retVal = ValidateNonTerminal(nodeOrtoken.AsNode(), tree, filename, failures);
            }
            else
            {
                retVal = ValidateToken(nodeOrtoken.AsToken(), tree, filename, failures);
            }

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

示例13: VisitNodeOrToken

            private SyntaxNodeOrToken VisitNodeOrToken(SyntaxNodeOrToken nodeOrToken)
            {
                if (nodeOrToken.IsNode)
                    return Visit(nodeOrToken.AsNode());

                return VisitToken(nodeOrToken.AsToken());
            }
开发者ID:terrajobst,项目名称:apiporter,代码行数:7,代码来源:PatternReplacement.RunAsync.cs

示例14: GetDepth

 private static int GetDepth(SyntaxNodeOrToken syntax, int depth = 0)
 {
     if (syntax.IsNode)
     {
         return syntax.ChildNodesAndTokens().Count == 0 ? depth : syntax.ChildNodesAndTokens().Max(x => GetDepth(x, depth + 1));
     }
     return (syntax.AsToken().HasLeadingTrivia || syntax.AsToken().HasTrailingTrivia) ? depth + 1 : depth;
 }
开发者ID:modulexcite,项目名称:LINQPad.CodeAnalysis,代码行数:8,代码来源:SyntaxTreePanel.cs


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