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


C# SymbolAnalysisContext.ReportDiagnosticIfNonGenerated方法代码示例

本文整理汇总了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));
                }
            }
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:21,代码来源:MethodParameterUnused.cs

示例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));
         }
     }
 }
开发者ID:andwi,项目名称:sonarlint-vs,代码行数:12,代码来源:ClassShouldNotBeAbstract.cs

示例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);
            }
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:51,代码来源:UnusedPrivateMember.cs

示例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);
                }
            }
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:21,代码来源:ClassWithOnlyStaticMember.cs

示例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);
                    }
                }
            }
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:28,代码来源:ClassWithOnlyStaticMember.cs

示例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));
                }
            }
        }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:34,代码来源:ClassNotInstantiatable.cs

示例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));
     }
 }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:9,代码来源:DisposeNotImplementingDispose.cs


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