private void onCompilation(CompilationAnalysisContext context) { if (!context.Options.AdditionalFiles.Any()) { return; } var srcFiles = FileFilter.GetFiles(context.Options.AdditionalFiles).ToList(); if (!srcFiles.Any()) { return; } foreach (IAdditionalTextAnalyzer analyzer in Analyzers) { var diagnosticInfo = analyzer.GetDiagnosticInfo(srcFiles, context.CancellationToken); foreach (var info in diagnosticInfo) { var supportedDiagnostic = GetSupportedDiagnosticAttribute(analyzer); var diagnostic = DiagnosticFactory.Create(supportedDiagnostic.GetDescriptor(), info); context.ReportDiagnostic(diagnostic); } } }
private void AnalyzeNode(SyntaxNodeAnalysisContext context, SyntaxKind kind) { var analyzersForKind = Analyzers.Where(p => ((ISyntaxNodeAnalyzer)p).Kind == kind); foreach (ISyntaxNodeAnalyzer syntaxNodeAnalyzer in analyzersForKind) { var diagnosticInfo = syntaxNodeAnalyzer.GetDiagnosticInfo(context); foreach (var info in diagnosticInfo) { var supportedDiagnostic = GetSupportedDiagnosticAttribute(syntaxNodeAnalyzer); var diagnostic = DiagnosticFactory.Create(supportedDiagnostic.GetDescriptor(), info); context.ReportDiagnostic(diagnostic); } } }
public Action <PumaCompilationAnalysisContext> Report(ISyntaxAnalyzer analyzer) { return(pumaContext => { try { var context = pumaContext.RosylnContext; analyzer.OnCompilationEnd(pumaContext); while (!analyzer.VulnerableSyntaxNodes.IsEmpty) { VulnerableSyntaxNode vulnerableSyntaxNode; if (!analyzer.VulnerableSyntaxNodes.TryPop(out vulnerableSyntaxNode)) { continue; } if (!context.Compilation.SyntaxTrees.Contains(vulnerableSyntaxNode.Sink.SyntaxTree)) { continue; } if (!vulnerableSyntaxNode.Suppressed) { var supportedDiagnostic = analyzer.GetSupportedDiagnosticAttribute(); var diagnosticInfo = new DiagnosticInfo(vulnerableSyntaxNode.Sink.GetLocation(), vulnerableSyntaxNode.MessageArgs); var diagnostic = _diagnosticFactory.Create(supportedDiagnostic.GetDescriptor(), diagnosticInfo); context.ReportDiagnostic(diagnostic); } } } catch (Exception ex) { Console.WriteLine(ex); } }); }