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


C# SonarAnalysisContext.RegisterSyntaxTreeActionInNonGenerated方法代码示例

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


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

示例1: Initialize

 protected override void Initialize(SonarAnalysisContext context)
 {
     context.RegisterSyntaxTreeActionInNonGenerated(
         c =>
         {
             foreach (var token in c.Tree.GetRoot().DescendantTokens())
             {
                 CheckTrivias(token.LeadingTrivia, c);
                 CheckTrivias(token.TrailingTrivia, c);
             }
         });
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:12,代码来源:CommentedOutCode.cs

示例2: Initialize

 protected override void Initialize(SonarAnalysisContext context)
 {
     context.RegisterSyntaxTreeActionInNonGenerated(
         c =>
         {
             foreach (var asyncOrAwaitToken in GetAsyncOrAwaitTokens(c.Tree.GetRoot())
                 .Where(token => !token.Parent.AncestorsAndSelf().OfType<IdentifierNameSyntax>().Any()))
             {
                 c.ReportDiagnostic(Diagnostic.Create(Rule, asyncOrAwaitToken.GetLocation(), asyncOrAwaitToken.ToString()));
             }
         });
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:12,代码来源:AsyncAwaitIdentifier.cs

示例3: Initialize

        protected override void Initialize(SonarAnalysisContext context)
        {
            context.RegisterSyntaxTreeActionInNonGenerated(
                c =>
                {
                    var lineContinuations = c.Tree.GetRoot().DescendantTokens()
                        .SelectMany(token => token.TrailingTrivia)
                        .Where(trivia => trivia.IsKind(SyntaxKind.LineContinuationTrivia));

                    foreach (var lineContinuation in lineContinuations)
                    {
                        c.ReportDiagnostic(Diagnostic.Create(Rule, lineContinuation.GetLocation()));
                    }
                });
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:15,代码来源:LineContinuation.cs

示例4: Initialize

 protected override void Initialize(SonarAnalysisContext context)
 {
     context.RegisterSyntaxTreeActionInNonGenerated(
         c =>
         {
             var root = c.Tree.GetRoot();
             foreach (var closeBraceToken in GetDescendantCloseBraceTokens(root)
                 .Where(closeBraceToken =>
                     !StartsLine(closeBraceToken) &&
                     !IsOnSameLineAsOpenBrace(closeBraceToken) &&
                     !IsInitializer(closeBraceToken.Parent)))
             {
                 c.ReportDiagnostic(Diagnostic.Create(Rule, closeBraceToken.GetLocation()));
             }
         });
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:16,代码来源:RightCurlyBraceStartsLine.cs

示例5: Initialize

        protected override void Initialize(SonarAnalysisContext context)
        {
            context.RegisterSyntaxTreeActionInNonGenerated(
                GeneratedCodeRecognizer,
                c =>
                {
                    var offset = c.Tree.GetText().ToString().IndexOf('\t');
                    if (offset < 0)
                    {
                        return;
                    }

                    var location = c.Tree.GetLocation(TextSpan.FromBounds(offset, offset));
                    c.ReportDiagnostic(Diagnostic.Create(Rule, location));
                });
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:16,代码来源:TabCharacterBase.cs

示例6: Initialize

        protected override void Initialize(SonarAnalysisContext context)
        {
            // in order to let the tests work properly, we do this in a tree action
            // https://github.com/dotnet/roslyn/issues/4745 was fixed in Roslyn 1.1,
            // so in the IDE it should already be fine.
            context.RegisterSyntaxTreeActionInNonGenerated(
                c =>
                {
                    var namespaces = c.Tree.GetCompilationUnitRoot().DescendantNodes()
                        .OfType<NamespaceDeclarationSyntax>()
                        .Where(ns=> !ns.Members.Any());

                    foreach (var ns in namespaces)
                    {
                        c.ReportDiagnostic(Diagnostic.Create(Rule, ns.GetLocation()));
                    }
                });
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:18,代码来源:EmptyNamespace.cs

示例7: Initialize

        protected override void Initialize(SonarAnalysisContext context)
        {
            context.RegisterSyntaxTreeActionInNonGenerated(
                c =>
                {
                    var comments = c.Tree.GetCompilationUnitRoot().DescendantTrivia()
                        .Where(trivia => IsComment(trivia));

                    foreach (var comment in comments)
                    {
                        var text = comment.ToString();

                        foreach (var i in AllCaseInsensitiveIndexesOf(text, Word).Where(i => IsWordAt(text, i, Word.Length)))
                        {
                            var startLocation = comment.SpanStart + i;
                            var location = Location.Create(
                                c.Tree,
                                TextSpan.FromBounds(startLocation, startLocation + Word.Length));

                            c.ReportDiagnostic(Diagnostic.Create(Rule, location));
                        }
                    }
                });
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:24,代码来源:CommentWordBase.cs


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