本文整理汇总了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);
}
});
}
示例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()));
}
});
}
示例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()));
}
});
}
示例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()));
}
});
}
示例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));
});
}
示例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()));
}
});
}
示例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));
}
}
});
}