本文整理汇总了C#中SymbolAnalysisContext.ReportDiagnosticIfNonGenerated方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolAnalysisContext.ReportDiagnosticIfNonGenerated方法的具体用法?C# SymbolAnalysisContext.ReportDiagnosticIfNonGenerated怎么用?C# SymbolAnalysisContext.ReportDiagnosticIfNonGenerated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolAnalysisContext
的用法示例。
在下文中一共展示了SymbolAnalysisContext.ReportDiagnosticIfNonGenerated方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReportUnusedParametersOnMethod
private static void ReportUnusedParametersOnMethod(IMethodSymbol methodSymbol, SymbolAnalysisContext context)
{
if (!MethodCanBeSafelyChanged(methodSymbol))
{
return;
}
var unusedParameters = GetUnusedParameters(methodSymbol, context.Compilation);
if (!unusedParameters.Any() || IsUsedAsEventHandlerFunctionOrAction(methodSymbol, context.Compilation))
{
return;
}
foreach (var unusedParameter in unusedParameters)
{
foreach (var unusedParameterDeclaration in unusedParameter.DeclaringSyntaxReferences.Select(r => r.GetSyntax()))
{
context.ReportDiagnosticIfNonGenerated(Diagnostic.Create(Rule, unusedParameterDeclaration.GetLocation(), unusedParameter.Name));
}
}
}
示例2: ReportClass
private static void ReportClass(INamedTypeSymbol symbol, string message, SymbolAnalysisContext c)
{
foreach (var declaringSyntaxReference in symbol.DeclaringSyntaxReferences)
{
var classDeclaration = declaringSyntaxReference.GetSyntax() as ClassDeclarationSyntax;
if (classDeclaration != null)
{
c.ReportDiagnosticIfNonGenerated(Diagnostic.Create(Rule, classDeclaration.Identifier.GetLocation(),
message));
}
}
}
示例3: ReportIssues
private static void ReportIssues(SymbolAnalysisContext context, HashSet<ISymbol> usedSymbols,
HashSet<ISymbol> declaredPrivateSymbols, HashSet<ISymbol> emptyConstructors,
BidirectionalDictionary<ISymbol, SyntaxNode> fieldLikeSymbols)
{
var unusedSymbols = declaredPrivateSymbols
.Except(usedSymbols.Union(emptyConstructors))
.ToList();
var alreadyReportedFieldLikeSymbols = new HashSet<ISymbol>();
var unusedSymbolSyntaxPairs = unusedSymbols
.SelectMany(unusedSymbol => unusedSymbol.DeclaringSyntaxReferences
.Select(r =>
new
{
Syntax = r.GetSyntax(),
Symbol = unusedSymbol
}));
foreach (var unused in unusedSymbolSyntaxPairs)
{
var location = unused.Syntax.GetLocation();
var canBeFieldLike = unused.Symbol is IFieldSymbol || unused.Symbol is IEventSymbol;
if (canBeFieldLike)
{
if (alreadyReportedFieldLikeSymbols.Contains(unused.Symbol))
{
continue;
}
var variableDeclaration = GetVariableDeclaration(unused.Syntax);
if (variableDeclaration == null)
{
continue;
}
var declarations = variableDeclaration.Variables
.Select(v => fieldLikeSymbols.GetByB(v))
.ToList();
if (declarations.All(d => unusedSymbols.Contains(d)))
{
location = unused.Syntax.Parent.Parent.GetLocation();
alreadyReportedFieldLikeSymbols.UnionWith(declarations);
}
}
context.ReportDiagnosticIfNonGenerated(Diagnostic.Create(Rule, location), context.Compilation);
}
}
示例4: CheckClasses
private static void CheckClasses(INamedTypeSymbol utilityClass, SymbolAnalysisContext c)
{
if (!ClassIsRelevant(utilityClass))
{
return;
}
var reportMessage = string.Format(MessageFormatStaticClass,
utilityClass.IsSealed ? "private" : "protected");
foreach (var syntaxReference in utilityClass.DeclaringSyntaxReferences)
{
var classDeclarationSyntax = syntaxReference.GetSyntax() as ClassDeclarationSyntax;
if (classDeclarationSyntax != null)
{
c.ReportDiagnosticIfNonGenerated(
Diagnostic.Create(Rule, classDeclarationSyntax.Identifier.GetLocation(), reportMessage),
c.Compilation);
}
}
}
示例5: CheckConstructors
private static void CheckConstructors(INamedTypeSymbol utilityClass, SymbolAnalysisContext c)
{
if (!ClassQualifiesForIssue(utilityClass) ||
!HasMembersAndAllAreStaticExceptConstructors(utilityClass))
{
return;
}
var reportMessage = string.Format(MessageFormatConstructor,
utilityClass.IsSealed ? "private" : "protected");
foreach (var constructor in utilityClass.GetMembers()
.Where(IsConstructor)
.Where(symbol => ProblematicConstructorAccessibility.Contains(symbol.DeclaredAccessibility)))
{
var syntaxReferences = constructor.DeclaringSyntaxReferences;
foreach (var syntaxReference in syntaxReferences)
{
var constructorDeclaration = syntaxReference.GetSyntax() as ConstructorDeclarationSyntax;
if (constructorDeclaration != null)
{
c.ReportDiagnosticIfNonGenerated(
Diagnostic.Create(Rule, constructorDeclaration.Identifier.GetLocation(), reportMessage),
c.Compilation);
}
}
}
}
示例6: CheckClassWithOnlyUnusedPrivateConstructors
private static void CheckClassWithOnlyUnusedPrivateConstructors(SymbolAnalysisContext context)
{
var namedType = context.Symbol as INamedTypeSymbol;
if (!namedType.IsClass() ||
namedType.IsStatic)
{
return;
}
var members = namedType.GetMembers();
var constructors = GetConstructors(members).ToList();
if (!constructors.Any() ||
HasNonPrivateConstructor(constructors) ||
HasOnlyStaticMembers(members.Except(constructors).ToList()))
{
return;
}
var classDeclarations = new RemovableDeclarationCollector(namedType, context.Compilation).ClassDeclarations;
if (!IsAnyConstructorCalled(namedType, classDeclarations))
{
var message = constructors.Count > 1
? "at least one of its constructors"
: "its constructor";
foreach (var classDeclaration in classDeclarations)
{
context.ReportDiagnosticIfNonGenerated(Diagnostic.Create(Rule, classDeclaration.SyntaxNode.Identifier.GetLocation(),
message));
}
}
}
示例7: ReportDisposeMethods
private static void ReportDisposeMethods(IEnumerable<IMethodSymbol> disposeMethods,
SymbolAnalysisContext context)
{
foreach (var location in disposeMethods.SelectMany(m => m.Locations))
{
context.ReportDiagnosticIfNonGenerated(Diagnostic.Create(
Rule, location));
}
}