本文整理汇总了C#中SyntaxNodeAnalysisContext.IsAnalyzerSuppressed方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNodeAnalysisContext.IsAnalyzerSuppressed方法的具体用法?C# SyntaxNodeAnalysisContext.IsAnalyzerSuppressed怎么用?C# SyntaxNodeAnalysisContext.IsAnalyzerSuppressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNodeAnalysisContext
的用法示例。
在下文中一共展示了SyntaxNodeAnalysisContext.IsAnalyzerSuppressed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandlePrefixUnaryExpression
private static void HandlePrefixUnaryExpression(SyntaxNodeAnalysisContext context)
{
var unaryExpression = (PrefixUnaryExpressionSyntax)context.Node;
var precedingToken = unaryExpression.OperatorToken.GetPreviousToken();
var followingToken = unaryExpression.OperatorToken.GetNextToken();
var followingTrivia = TriviaHelper.MergeTriviaLists(unaryExpression.OperatorToken.TrailingTrivia, followingToken.LeadingTrivia);
/* let the outer operator handle things like the following, so no error is reported for '++':
* c ^= *++buf4;
*
* if the unary expression is inside parenthesis or an indexer, there should be no leading space
*/
var mustHaveLeadingWhitespace = !(unaryExpression.Parent is PrefixUnaryExpressionSyntax)
&& !(unaryExpression.Parent is CastExpressionSyntax)
&& !precedingToken.IsKind(SyntaxKind.OpenParenToken)
&& !precedingToken.IsKind(SyntaxKind.OpenBracketToken)
&& !(precedingToken.IsKind(SyntaxKind.OpenBraceToken) && (precedingToken.Parent is InterpolationSyntax));
bool analyze;
switch (unaryExpression.OperatorToken.Kind())
{
case SyntaxKind.PlusToken:
analyze = context.IsAnalyzerSuppressed(SA1022PositiveSignsMustBeSpacedCorrectly.DiagnosticId);
break;
case SyntaxKind.MinusToken:
analyze = context.IsAnalyzerSuppressed(SA1021NegativeSignsMustBeSpacedCorrectly.DiagnosticId);
break;
case SyntaxKind.PlusPlusToken:
case SyntaxKind.MinusMinusToken:
analyze = context.IsAnalyzerSuppressed(SA1020IncrementDecrementSymbolsMustBeSpacedCorrectly.DiagnosticId);
break;
default:
analyze = true;
break;
}
if (analyze)
{
if (followingTrivia.Any(t => t.IsKind(SyntaxKind.SingleLineCommentTrivia)) || followingTrivia.Any(t => t.IsKind(SyntaxKind.MultiLineCommentTrivia)))
{
context.ReportDiagnostic(Diagnostic.Create(DescriptorNotFollowedByComment, unaryExpression.OperatorToken.GetLocation(), unaryExpression.OperatorToken.Text));
}
else
{
CheckToken(context, unaryExpression.OperatorToken, mustHaveLeadingWhitespace, false, false);
}
}
}
示例2: ProcessUsings
private static void ProcessUsings(SyntaxNodeAnalysisContext context, SyntaxList<UsingDirectiveSyntax> usings)
{
var usingDirectives = new List<UsingDirectiveSyntax>();
var systemUsingDirectives = new List<UsingDirectiveSyntax>();
foreach (var usingDirective in usings)
{
if (usingDirective.IsPrecededByPreprocessorDirective())
{
CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, usingDirectives);
CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, systemUsingDirectives);
usingDirectives.Clear();
systemUsingDirectives.Clear();
}
if (IsAliasOrStaticUsingDirective(usingDirective))
{
continue;
}
if (usingDirective.HasNamespaceAliasQualifier()
|| !usingDirective.IsSystemUsingDirective()
|| context.IsAnalyzerSuppressed(SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives.DiagnosticId))
{
usingDirectives.Add(usingDirective);
}
else
{
systemUsingDirectives.Add(usingDirective);
}
}
CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, usingDirectives);
CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, systemUsingDirectives);
}
开发者ID:hexuefengx,项目名称:StyleCopAnalyzers,代码行数:35,代码来源:SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace.cs
示例3: CheckChildStatement
private static void CheckChildStatement(SyntaxNodeAnalysisContext context, SyntaxNode node, StatementSyntax childStatement)
{
if (childStatement == null || childStatement.IsMissing)
{
return;
}
if (childStatement is BlockSyntax)
{
// BlockSyntax child statements are handled by HandleBlock
return;
}
// We are only interested in the first instance of this violation on a line.
if (!node.GetFirstToken().IsFirstInLine())
{
return;
}
// We are only interested in the case where statement and childStatement start on the same line. Use
// IsFirstInLine to detect this condition easily.
SyntaxToken firstChildToken = childStatement.GetFirstToken();
if (firstChildToken.IsMissingOrDefault() || firstChildToken.IsFirstInLine())
{
return;
}
if (!context.IsAnalyzerSuppressed(SA1519CurlyBracketsMustNotBeOmittedFromMultiLineChildStatement.DiagnosticId))
{
// diagnostics for multi-line statements is handled by SA1519, as long as it's not suppressed
FileLinePositionSpan lineSpan = childStatement.GetLineSpan();
if (lineSpan.StartLinePosition.Line != lineSpan.EndLinePosition.Line)
{
return;
}
}
context.ReportDiagnostic(Diagnostic.Create(Descriptor, childStatement.GetLocation()));
}
示例4: HandleQueryExpression
private static void HandleQueryExpression(SyntaxNodeAnalysisContext context)
{
var queryExpression = (QueryExpressionSyntax)context.Node;
var tokensToCheck = new List<SyntaxToken>();
HandleQueryClause(queryExpression.FromClause, tokensToCheck);
HandleQueryBody(queryExpression.Body, tokensToCheck);
bool isEnabledSA1102 = !context.IsAnalyzerSuppressed(SA1102Identifier);
bool isEnabledSA1103 = !context.IsAnalyzerSuppressed(SA1103Identifier);
bool isEnabledSA1104 = !context.IsAnalyzerSuppressed(SA1104Identifier);
bool isEnabledSA1105 = !context.IsAnalyzerSuppressed(SA1105Identifier);
bool allOnSameLine = true;
bool allOnSeparateLine = true;
bool suppressSA1103 = false;
for (var i = 0; i < tokensToCheck.Count - 1; i++)
{
var token1 = tokensToCheck[i];
var token2 = tokensToCheck[i + 1];
var parent1 = token1.Parent;
var parent2 = token2.Parent;
if (parent2 is QueryContinuationSyntax)
{
continue;
}
// The node before the query clause may encompass the entire query clause,
// so we need to use the token within that node for the line determination.
var location1 = !(parent1 is QueryContinuationSyntax) ? parent1.GetLineSpan() : token1.GetLineSpan();
var location2 = parent2.GetLineSpan();
if (((location2.StartLinePosition.Line - location1.EndLinePosition.Line) > 1)
&& isEnabledSA1102
&& !token2.LeadingTrivia.Any(trivia => trivia.IsDirective))
{
context.ReportDiagnostic(Diagnostic.Create(SA1102Descriptor, token2.GetLocation()));
}
var onSameLine = location1.EndLinePosition.Line == location2.StartLinePosition.Line;
if (onSameLine
&& isEnabledSA1104
&& !(parent1 is QueryContinuationSyntax)
&& parent1.SpansMultipleLines())
{
context.ReportDiagnostic(Diagnostic.Create(SA1104Descriptor, token2.GetLocation()));
// Make sure that SA1103 will not be reported, as there is a more specific diagnostic reported.
suppressSA1103 = true;
}
if (onSameLine
&& isEnabledSA1105
&& parent2.SpansMultipleLines())
{
context.ReportDiagnostic(Diagnostic.Create(SA1105Descriptor, token2.GetLocation()));
// Make sure that SA1103 will not be reported, as there is a more specific diagnostic reported.
suppressSA1103 = true;
}
allOnSameLine = allOnSameLine && onSameLine;
allOnSeparateLine = allOnSeparateLine && !onSameLine;
}
if (!allOnSameLine && !allOnSeparateLine && !suppressSA1103 && isEnabledSA1103)
{
context.ReportDiagnostic(Diagnostic.Create(SA1103Descriptor, queryExpression.FromClause.FromKeyword.GetLocation()));
}
}
示例5: HandleIfStatement
private static void HandleIfStatement(SyntaxNodeAnalysisContext context)
{
var ifStatement = (IfStatementSyntax)context.Node;
if (ifStatement.Parent.IsKind(SyntaxKind.ElseClause))
{
// this will be analyzed as a clause of the outer if statement
return;
}
List<StatementSyntax> clauses = new List<StatementSyntax>();
for (IfStatementSyntax current = ifStatement; current != null; current = current.Else?.Statement as IfStatementSyntax)
{
clauses.Add(current.Statement);
if (current.Else != null && !(current.Else.Statement is IfStatementSyntax))
{
clauses.Add(current.Else.Statement);
}
}
if (!context.IsAnalyzerSuppressed(SA1520UseCurlyBracketsConsistently.DiagnosticId))
{
// inconsistencies will be reported as SA1520, as long as it's not suppressed
if (clauses.OfType<BlockSyntax>().Any())
{
return;
}
}
foreach (StatementSyntax clause in clauses)
{
SyntaxNode node = clause.Parent;
if (node.IsKind(SyntaxKind.IfStatement) && node.Parent.IsKind(SyntaxKind.ElseClause))
{
node = node.Parent;
}
CheckChildStatement(context, node, clause);
}
}