Beispiel #1
0
 public static void ReportDiagnosticIfNonGenerated(
     this SymbolAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Diagnostic diagnostic)
 {
     context.ReportDiagnosticIfNonGenerated(generatedCodeRecognizer, diagnostic, context.Compilation);
 }
Beispiel #2
0
 public static void RegisterSyntaxTreeActionInNonGenerated(this ParameterLoadingAnalysisContext context,
                                                           GeneratedCodeRecognizer generatedCodeRecognizer,
                                                           Action <SyntaxTreeAnalysisContext> action) =>
 context.RegisterCompilationStartAction(csac =>
                                        csac.RegisterSyntaxTreeAction(c =>
 {
     if (ShouldAnalyze(context.GetInnerContext(), generatedCodeRecognizer, c.GetSyntaxTree(), csac.Compilation, c.Options))
     {
         action(c);
     }
 }));
Beispiel #3
0
 public static void ReportDiagnosticIfNonGenerated(
     this SymbolAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Diagnostic diagnostic,
     Compilation compilation)
 {
     if (!diagnostic.Location.SourceTree.IsGenerated(generatedCodeRecognizer, compilation))
     {
         context.ReportDiagnosticWhenActive(diagnostic);
     }
 }
 public static void ReportDiagnosticIfNonGenerated(
     this CompilationAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Diagnostic diagnostic,
     Compilation compilation)
 {
     if (ShouldAnalyze(context, generatedCodeRecognizer, diagnostic.Location.SourceTree, context.Compilation, context.Options))
     {
         context.ReportDiagnosticWhenActive(diagnostic);
     }
 }
Beispiel #5
0
 public static void RegisterCodeBlockStartActionInNonGenerated <TLanguageKindEnum>(
     this ParameterLoadingAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <CodeBlockStartAnalysisContext <TLanguageKindEnum> > action) where TLanguageKindEnum : struct
 {
     context.RegisterCodeBlockStartAction <TLanguageKindEnum>(
         c =>
     {
         if (!c.CodeBlock.SyntaxTree.IsGenerated(generatedCodeRecognizer, c.SemanticModel.Compilation))
         {
             action(c);
         }
     });
 }
 public static void RegisterCodeBlockStartActionInNonGenerated <TLanguageKindEnum>(
     this SonarAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <CodeBlockStartAnalysisContext <TLanguageKindEnum> > action) where TLanguageKindEnum : struct
 {
     context.RegisterCodeBlockStartAction <TLanguageKindEnum>(
         c =>
     {
         if (ShouldAnalyze(context, generatedCodeRecognizer, c.GetSyntaxTree(), c.SemanticModel.Compilation, c.Options))
         {
             action(c);
         }
     });
 }
Beispiel #7
0
 public static void RegisterSyntaxNodeActionInNonGenerated <TLanguageKindEnum>(
     this CompilationStartAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <SyntaxNodeAnalysisContext> action,
     params TLanguageKindEnum[] syntaxKinds) where TLanguageKindEnum : struct
 {
     context.RegisterSyntaxNodeAction(
         c =>
     {
         if (!c.Node.SyntaxTree.IsGenerated(generatedCodeRecognizer, c.SemanticModel.Compilation))
         {
             action(c);
         }
     },
         syntaxKinds);
 }
 public static void RegisterSyntaxNodeActionInNonGenerated <TLanguageKindEnum>(
     this CompilationStartAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <SyntaxNodeAnalysisContext> action,
     params TLanguageKindEnum[] syntaxKinds) where TLanguageKindEnum : struct
 {
     context.RegisterSyntaxNodeAction(
         c =>
     {
         if (ShouldAnalyze(context, generatedCodeRecognizer, c.GetSyntaxTree(), c.Compilation, c.Options))
         {
             action(c);
         }
     },
         syntaxKinds);
 }
Beispiel #9
0
 public static void RegisterSyntaxNodeActionInNonGenerated <TLanguageKindEnum>(
     this ParameterLoadingAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <SyntaxNodeAnalysisContext> action,
     params TLanguageKindEnum[] syntaxKinds) where TLanguageKindEnum : struct
 {
     context.RegisterSyntaxNodeAction(
         c =>
     {
         if (!c.GetSyntaxTree().IsGenerated(generatedCodeRecognizer, c.SemanticModel.Compilation))
         {
             action(c);
         }
     },
         syntaxKinds.ToImmutableArray());
 }
Beispiel #10
0
 public static void RegisterSyntaxTreeActionInNonGenerated(
     this SonarAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <SyntaxTreeAnalysisContext> action)
 {
     context.RegisterCompilationStartAction(
         csac =>
     {
         csac.RegisterSyntaxTreeAction(
             c =>
         {
             if (!c.Tree.IsGenerated(generatedCodeRecognizer, csac.Compilation))
             {
                 action(c);
             }
         });
     });
 }
 public static void RegisterSyntaxTreeActionInNonGenerated(
     this SonarAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <SyntaxTreeAnalysisContext> action)
 {
     context.RegisterCompilationStartAction(
         csac =>
     {
         csac.RegisterSyntaxTreeAction(
             c =>
         {
             if (ShouldAnalyze(context, generatedCodeRecognizer, c.GetSyntaxTree(), csac.Compilation, c.Options))
             {
                 action(c);
             }
         });
     });
 }
Beispiel #12
0
        public static bool IsGenerated(this SyntaxTree tree, GeneratedCodeRecognizer generatedCodeRecognizer, Compilation compilation)
        {
            if (tree == null)
            {
                return(false);
            }

            // this is locking if the compilation is not present in the Cache.
            var cache = Cache.GetOrCreateValue(compilation);

            if (cache.TryGetValue(tree, out var result))
            {
                return(result);
            }

            var generated = generatedCodeRecognizer.IsGenerated(tree);

            cache.TryAdd(tree, generated);
            return(generated);
        }
 internal static bool ShouldAnalyze(GeneratedCodeRecognizer generatedCodeRecognizer, SyntaxTree syntaxTree, Compilation c, AnalyzerOptions options) =>
 options.ShouldAnalyzeGeneratedCode(c.Language) ||
 !syntaxTree.IsGenerated(generatedCodeRecognizer, c);
 private static bool ShouldAnalyze(CompilationAnalysisContext context, GeneratedCodeRecognizer generatedCodeRecognizer, SyntaxTree syntaxTree, Compilation c, AnalyzerOptions options) =>
 SonarAnalysisContext.ShouldAnalyzeGenerated(context, c, options) ||
 !syntaxTree.IsGenerated(generatedCodeRecognizer, c);
Beispiel #15
0
 public static void RegisterSyntaxNodeActionInNonGenerated <TLanguageKindEnum>(this ParameterLoadingAnalysisContext context,
                                                                               GeneratedCodeRecognizer generatedCodeRecognizer,
                                                                               Action <SyntaxNodeAnalysisContext> action,
                                                                               params TLanguageKindEnum[] syntaxKinds) where TLanguageKindEnum : struct =>
 context.RegisterSyntaxNodeAction(c =>
 {
     if (ShouldAnalyze(context.GetInnerContext(), generatedCodeRecognizer, c.GetSyntaxTree(), c.Compilation, c.Options))
     {
         action(c);
     }
 }, syntaxKinds.ToImmutableArray());
Beispiel #16
0
 public static bool ShouldAnalyze(GeneratedCodeRecognizer generatedCodeRecognizer, SyntaxTree syntaxTree, Compilation c, AnalyzerOptions options) =>
 PropertiesHelper.ReadAnalyzeGeneratedCodeProperty(PropertiesHelper.GetSettings(options), c.Language) || !syntaxTree.IsGenerated(generatedCodeRecognizer, c);