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


C# SyntaxTrivia.GetStructure方法代码示例

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


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

示例1: StructuredTrivia

            public StructuredTrivia(SyntaxTrivia trivia, int initialColumn) :
                base(trivia.GetStructure())
            {
                Contract.ThrowIfFalse(trivia.HasStructure);

                _trivia = trivia;

                var root = trivia.GetStructure();
                var text = GetText();

                _initialColumn = initialColumn;
                _treeData = (text == null) ? (TreeData)new Node(root) : new NodeAndText(root, text);
            }
开发者ID:RoryVL,项目名称:roslyn,代码行数:13,代码来源:TreeData.StructuredTrivia.cs

示例2: VisitTrivia

 public virtual void VisitTrivia(SyntaxTrivia trivia)
 {
     if (this.Depth >= SyntaxWalkerDepth.StructuredTrivia && trivia.HasStructure)
     {
         this.Visit((CSharpSyntaxNode)trivia.GetStructure());
     }
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:7,代码来源:CSharpSyntaxWalker.cs

示例3: Format

 public static IFormattingResult Format(
     SyntaxTrivia trivia,
     int initialColumn,
     OptionSet optionSet,
     ChainedFormattingRules formattingRules,
     CancellationToken cancellationToken)
 {
     var root = trivia.GetStructure();
     var formatter = new CSharpStructuredTriviaFormatEngine(trivia, initialColumn, optionSet, formattingRules, root.GetFirstToken(includeZeroWidth: true), root.GetLastToken(includeZeroWidth: true));
     return formatter.FormatAsync(cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:11,代码来源:CSharpStructuredTriviaFormatEngine.cs

示例4: HandleDocumentationCommentTrivia

        private static void HandleDocumentationCommentTrivia(SyntaxTreeAnalysisContext context, SyntaxTrivia trivia)
        {
            foreach (var token in trivia.GetStructure().DescendantTokens(descendIntoTrivia: true))
            {
                switch (token.Kind())
                {
                case SyntaxKind.XmlTextLiteralToken:
                    HandleWhitespaceToken(context, token);
                    break;

                default:
                    break;
                }
            }
        }
开发者ID:umaranis,项目名称:StyleCopAnalyzers,代码行数:15,代码来源:SA1027TabsMustNotBeUsed.cs

示例5: IsEndOfLineOrContainsEndOfLine

 private static bool IsEndOfLineOrContainsEndOfLine(SyntaxTrivia trivia, AbstractSuppressionCodeFixProvider fixer)
 {
     return fixer.IsEndOfLine(trivia) ||
         (trivia.HasStructure && trivia.GetStructure().DescendantTrivia().Any(t => fixer.IsEndOfLine(t)));
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:5,代码来源:AbstractSuppressionCodeFixProvider.PragmaHelpers.cs

示例6: ClassifyTrivia

 private void ClassifyTrivia(SyntaxTrivia trivia)
 {
     if (trivia.IsRegularComment())
     {
         AddClassification(trivia, ClassificationTypeNames.Comment);
     }
     else if (trivia.Kind() == SyntaxKind.DisabledTextTrivia)
     {
         AddClassification(trivia, ClassificationTypeNames.ExcludedCode);
     }
     else if (trivia.Kind() == SyntaxKind.SkippedTokensTrivia)
     {
         ClassifySkippedTokens((SkippedTokensTriviaSyntax)trivia.GetStructure());
     }
     else if (trivia.IsDocComment())
     {
         ClassifyDocumentationComment((DocumentationCommentTriviaSyntax)trivia.GetStructure());
     }
     else if (trivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
     {
         AddClassification(trivia, ClassificationTypeNames.XmlDocCommentDelimiter);
     }
     else if (SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
     {
         ClassifyPreprocessorDirective((DirectiveTriviaSyntax)trivia.GetStructure());
     }
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:27,代码来源:Worker.cs

示例7: IsEndOfLineOrHasTrailingEndOfLine

 private static bool IsEndOfLineOrHasTrailingEndOfLine(SyntaxTrivia trivia, AbstractSuppressionCodeFixProvider fixer)
 {
     return fixer.IsEndOfLine(trivia) ||
         (trivia.HasStructure && fixer.IsEndOfLine(trivia.GetStructure().DescendantTrivia().LastOrDefault()));
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:5,代码来源:AbstractSuppressionCodeFixProvider.PragmaHelpers.cs

示例8: QuoteTrivia

    private ApiCall QuoteTrivia(SyntaxTrivia syntaxTrivia)
    {
        string factoryMethodName = "SyntaxFactory.Trivia";
        string text = syntaxTrivia.ToString();
        if (syntaxTrivia.FullSpan.Length == 0 ||
            (syntaxTrivia.Kind() == SyntaxKind.WhitespaceTrivia && UseDefaultFormatting))
        {
            return null;
        }

        PropertyInfo triviaFactoryProperty = null;
        if (triviaFactoryProperties.TryGetValue(syntaxTrivia.ToString(), out triviaFactoryProperty) &&
            ((SyntaxTrivia)triviaFactoryProperty.GetValue(null)).Kind() == syntaxTrivia.Kind())
        {
            if (UseDefaultFormatting)
            {
                return null;
            }

            return new ApiCall(null, "SyntaxFactory." + triviaFactoryProperty.Name);
        }

        if (!string.IsNullOrEmpty(text) &&
            string.IsNullOrWhiteSpace(text) &&
            syntaxTrivia.Kind() == SyntaxKind.WhitespaceTrivia)
        {
            if (UseDefaultFormatting)
            {
                return null;
            }

            factoryMethodName = "SyntaxFactory.Whitespace";
        }

        if (syntaxTrivia.Kind() == SyntaxKind.SingleLineCommentTrivia ||
            syntaxTrivia.Kind() == SyntaxKind.MultiLineCommentTrivia)
        {
            factoryMethodName = "SyntaxFactory.Comment";
        }

        if (syntaxTrivia.Kind() == SyntaxKind.PreprocessingMessageTrivia)
        {
            factoryMethodName = "SyntaxFactory.PreprocessingMessage";
        }

        if (syntaxTrivia.Kind() == SyntaxKind.DisabledTextTrivia)
        {
            factoryMethodName = "SyntaxFactory.DisabledText";
        }

        if (syntaxTrivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
        {
            factoryMethodName = "SyntaxFactory.DocumentationCommentExterior";
        }

        object argument = "@\"" + Escape(syntaxTrivia.ToString()) + "\"";

        if (syntaxTrivia.HasStructure)
        {
            argument = QuoteNode(syntaxTrivia.GetStructure(), "Structure");
        }

        return new ApiCall(null, factoryMethodName, CreateArgumentList(argument));
    }
开发者ID:SkightTeam,项目名称:RoslynQuoter,代码行数:64,代码来源:Quoter.cs

示例9: VisitTrivia

            public override void VisitTrivia(SyntaxTrivia trivia)
            {
                if (trivia.HasStructure)
                    Visit(trivia.GetStructure());

                switch (trivia.CSharpKind())
                {
                    case SyntaxKind.MultiLineCommentTrivia:
                    case SyntaxKind.SingleLineCommentTrivia:
                    case SyntaxKind.SingleLineDocumentationCommentTrivia:
                    case SyntaxKind.MultiLineDocumentationCommentTrivia:
                    case SyntaxKind.DocumentationCommentExteriorTrivia:
                        Mark(trivia, "comment"); break;

                    case SyntaxKind.EndOfLineTrivia:
                    case SyntaxKind.WhitespaceTrivia:
                        Mark(trivia, "whitespace"); break;

                    case SyntaxKind.RegionDirectiveTrivia:
                        Mark(trivia, "begin-region"); break;

                    case SyntaxKind.EndRegionDirectiveTrivia:
                        Mark(trivia, "end-region"); break;

                    case SyntaxKind.DisabledTextTrivia:
                        Mark(trivia, "disabled-text"); break;
                }
            }
开发者ID:Runt-Editor,项目名称:Runt,代码行数:28,代码来源:Highlighter.cs

示例10: ValidateTrivia

        private bool ValidateTrivia(SyntaxTrivia trivia, SyntaxTree tree, string filename = "", List<Failure> failures = null)
        {
            var retVal = true;
            if (trivia.HasStructure)
            {
                retVal = retVal & ValidateNonTerminal(trivia.GetStructure(), tree, filename, failures);
            }

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

                    ValidationFailed(errorText, rule);
                }

                retVal = retVal & pass;
            }

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

示例11: VisitTrivia

            public override void VisitTrivia(SyntaxTrivia trivia)
            {
                bool isDocComment = SyntaxFacts.IsDocumentationCommentTrivia(trivia.Kind());
                if (isDocComment ||
                    trivia.Kind() == SyntaxKind.SingleLineCommentTrivia ||
                    trivia.Kind() == SyntaxKind.MultiLineCommentTrivia)
                {
                    Results.AppendLine();
                    Results.Append(trivia.ToFullString().Trim());
                    Results.Append(" (Parent Token: ");
                    Results.Append(trivia.Token.Kind());
                    Results.Append(")");
                    if (isDocComment)
                    {
                        // Trivia for xml documentation comments have additional 'structure'
                        // available under a child DocumentationCommentSyntax.
                        Assert.True(trivia.HasStructure);
                        var documentationComment =
                            (DocumentationCommentTriviaSyntax)trivia.GetStructure();
                        Assert.True(documentationComment.ParentTrivia == trivia);
                        Results.Append(" (Structured)");
                    }
                }

                base.VisitTrivia(trivia);
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:26,代码来源:FAQ.cs

示例12: ShouldFormatSingleLineDocumentationComment

            private static bool ShouldFormatSingleLineDocumentationComment(int indentation, int tabSize, SyntaxTrivia trivia)
            {
                var xmlComment = (DocumentationCommentTriviaSyntax)trivia.GetStructure();

                var sawFirstOne = false;
                foreach (var token in xmlComment.DescendantTokens())
                {
                    foreach (var xmlTrivia in token.LeadingTrivia)
                    {
                        if (xmlTrivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
                        {
                            // skip first one since its leading whitespace will belong to syntax tree's syntax token
                            // not xml doc comment's token
                            if (!sawFirstOne)
                            {
                                sawFirstOne = true;
                                break;
                            }

                            var xmlCommentText = xmlTrivia.ToString();

                            // "///" == 3.
                            if (xmlCommentText.GetColumnFromLineOffset(xmlCommentText.Length - 3, tabSize) != indentation)
                            {
                                return true;
                            }

                            break;
                        }
                    }
                }

                return false;
            }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:34,代码来源:TriviaDataFactory.CodeShapeAnalyzer.cs

示例13: AddTrivia

        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());
                }
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:92,代码来源:SyntaxVisualizerControl.xaml.cs

示例14: TryGetLastTokenForStructuredTrivia

        private bool TryGetLastTokenForStructuredTrivia(
            SyntaxTrivia trivia,
            Func<SyntaxToken, bool> predicate,
            Func<SyntaxTrivia, bool> stepInto,
            out SyntaxToken token)
        {
            token = default(SyntaxToken);

            if (!trivia.HasStructure || stepInto == null || !stepInto(trivia))
            {
                return false;
            }

            token = GetLastToken(trivia.GetStructure(), predicate, stepInto);

            return token.RawKind != None;
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:17,代码来源:AbstractSyntaxNavigator.cs

示例15: QuoteTrivia

    private ApiCall QuoteTrivia(SyntaxTrivia syntaxTrivia)
    {
        string factoryMethodName = SyntaxFactoryMethod("Trivia");
        string text = syntaxTrivia.ToString();
        if (syntaxTrivia.FullSpan.Length == 0 ||
            (syntaxTrivia.Kind() == SyntaxKind.WhitespaceTrivia && UseDefaultFormatting))
        {
            return null;
        }

        PropertyInfo triviaFactoryProperty = null;
        if (triviaFactoryProperties.TryGetValue(syntaxTrivia.ToString(), out triviaFactoryProperty) &&
            ((SyntaxTrivia)triviaFactoryProperty.GetValue(null)).Kind() == syntaxTrivia.Kind())
        {
            if (UseDefaultFormatting)
            {
                return null;
            }

            return new ApiCall(null, SyntaxFactoryMethod(triviaFactoryProperty.Name));
        }

        if (!string.IsNullOrEmpty(text) &&
            string.IsNullOrWhiteSpace(text) &&
            syntaxTrivia.Kind() == SyntaxKind.WhitespaceTrivia)
        {
            if (UseDefaultFormatting)
            {
                return null;
            }

            factoryMethodName = SyntaxFactoryMethod("Whitespace");
        }

        if (syntaxTrivia.Kind() == SyntaxKind.SingleLineCommentTrivia ||
            syntaxTrivia.Kind() == SyntaxKind.MultiLineCommentTrivia)
        {
            factoryMethodName = SyntaxFactoryMethod("Comment");
        }

        if (syntaxTrivia.Kind() == SyntaxKind.PreprocessingMessageTrivia)
        {
            factoryMethodName = SyntaxFactoryMethod("PreprocessingMessage");
        }

        if (syntaxTrivia.Kind() == SyntaxKind.DisabledTextTrivia)
        {
            factoryMethodName = SyntaxFactoryMethod("DisabledText");
        }

        if (syntaxTrivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
        {
            factoryMethodName = SyntaxFactoryMethod("DocumentationCommentExterior");
        }

        var t = syntaxTrivia.ToString();
        var verbatim = t.Contains("\r") || t.Contains("\n");
        object argument = EscapeAndQuote(t, verbatim: verbatim);

        if (syntaxTrivia.HasStructure)
        {
            argument = QuoteNode(syntaxTrivia.GetStructure(), "Structure");
        }

        return new ApiCall(null, factoryMethodName, CreateArgumentList(argument));
    }
开发者ID:RikkiGibson,项目名称:RoslynQuoter,代码行数:66,代码来源:Quoter.cs


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