本文整理汇总了C#中CompilationAnalysisContext.ReportDiagnostic方法的典型用法代码示例。如果您正苦于以下问题:C# CompilationAnalysisContext.ReportDiagnostic方法的具体用法?C# CompilationAnalysisContext.ReportDiagnostic怎么用?C# CompilationAnalysisContext.ReportDiagnostic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CompilationAnalysisContext
的用法示例。
在下文中一共展示了CompilationAnalysisContext.ReportDiagnostic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeCompilation
private static void AnalyzeCompilation(CompilationAnalysisContext context)
{
if (AssemblyHasPublicTypes(context.Compilation.Assembly))
{
INamedTypeSymbol comVisibleAttributeSymbol = WellKnownTypes.ComVisibleAttribute(context.Compilation);
if (comVisibleAttributeSymbol == null)
{
return;
}
AttributeData attributeInstance = context.Compilation.Assembly.GetAttributes().FirstOrDefault(a => a.AttributeClass.Equals(comVisibleAttributeSymbol));
if (attributeInstance != null)
{
if (attributeInstance.ConstructorArguments.Length > 0 &&
attributeInstance.ConstructorArguments[0].Kind == TypedConstantKind.Primitive &&
attributeInstance.ConstructorArguments[0].Value != null &
attributeInstance.ConstructorArguments[0].Value.Equals(true))
{
// Has the attribute, with the value 'true'.
context.ReportDiagnostic(Diagnostic.Create(RuleA, Location.None, context.Compilation.Assembly.Name));
}
}
else
{
// No ComVisible attribute at all.
context.ReportDiagnostic(Diagnostic.Create(RuleB, Location.None, context.Compilation.Assembly.Name));
}
}
return;
}
示例2: AnalyzeCompilation
private void AnalyzeCompilation(CompilationAnalysisContext context)
{
if (AssemblyHasPublicTypes(context.Compilation.Assembly))
{
var comVisibleAttributeSymbol = WellKnownTypes.ComVisibleAttribute(context.Compilation);
if (comVisibleAttributeSymbol == null)
{
return;
}
var attributeInstance = context.Compilation.Assembly.GetAttributes().FirstOrDefault(a => a.AttributeClass.Equals(comVisibleAttributeSymbol));
if (attributeInstance != null)
{
if (attributeInstance.ConstructorArguments.Length > 0 &&
attributeInstance.ConstructorArguments[0].Kind == TypedConstantKind.Primitive &&
attributeInstance.ConstructorArguments[0].Value != null &
attributeInstance.ConstructorArguments[0].Value.Equals(true))
{
// Has the attribute, with the value 'true'.
context.ReportDiagnostic(Diagnostic.Create(Rule, Location.None, string.Format(SystemRuntimeAnalyzersResources.CA1017_AttributeTrue, context.Compilation.Assembly.Name)));
}
}
else
{
// No ComVisible attribute at all.
context.ReportDiagnostic(Diagnostic.Create(Rule, Location.None, string.Format(SystemRuntimeAnalyzersResources.CA1017_NoAttribute, context.Compilation.Assembly.Name)));
}
}
return;
}
示例3: AnalyzeCompilation
private void AnalyzeCompilation(CompilationAnalysisContext context)
{
Trace.WriteLine("AnalyzeCompilation");
try
{
INamedTypeSymbol dbContextTypeSymbol;
IEnumerable<INamedTypeSymbol> entityTypeSymbols = SymbolHelper.GetAllEntityTypesFromDbContext(context.Compilation, out dbContextTypeSymbol);
if (!entityTypeSymbols.Any())
{
return;
}
var allTypeSymbols = context.Compilation.GetSymbolsWithName(s => !s.EndsWith("DbContext"), SymbolFilter.Type).Cast<INamedTypeSymbol>();
var allMemberSymbols = allTypeSymbols.SelectMany(t => t.GetMembers().Where(m => m.Kind == SymbolKind.Property));
Trace.WriteLine("Class count: " + allTypeSymbols.Count());
Trace.WriteLine("Property count: " + allMemberSymbols.Count());
var efRoslynTheorem = new EFRoslynTheorem();
var result = efRoslynTheorem.Solve(entityTypeSymbols);
if (result.Status == Status.Unsatisfiable)
{
var classAssumptions = efRoslynTheorem.ClassAssumptions.ToList();
var propertyAssumptions = efRoslynTheorem.PropertyAssumptions.OrderBy(pa => pa.Rank).ToList();
do
{
result = TryToRemoveWrongAssumption(efRoslynTheorem, result, classAssumptions, propertyAssumptions);
} while (result != null && result.Status != Status.Satisfiable);
if (result == null || result.Status != Status.Satisfiable)
{
var diagnostic2 = Diagnostic.Create(UnsatisfiableRule, dbContextTypeSymbol.Locations[0], dbContextTypeSymbol.Name);
Trace.WriteLine("ReportDiagnostic " + diagnostic2.Descriptor.Id);
context.ReportDiagnostic(diagnostic2);
return;
}
var cacheId = EFRoslynTheoremCache.Add(context.Compilation, efRoslynTheorem, result);
var props = ImmutableDictionary.Create<string, string>();
props = props.Add("CacheId", cacheId);
var diagnostic = Diagnostic.Create(SatisfiableRule, dbContextTypeSymbol.Locations[0], props, dbContextTypeSymbol.Name);
Trace.WriteLine("ReportDiagnostic " + diagnostic.Descriptor.Id);
context.ReportDiagnostic(diagnostic);
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.ToString());
throw;
}
}
示例4: HandleCompilation
public void HandleCompilation(CompilationAnalysisContext context)
{
if (Volatile.Read(ref this.documentationAnalysisDisabled))
{
context.ReportDiagnostic(Diagnostic.Create(Descriptor, Location.None));
}
}
示例5: AnalyzeCompilation
private static void AnalyzeCompilation(CompilationAnalysisContext context)
{
var compilation = context.Compilation;
var allPlugins = compilation.SyntaxTrees
.Select(x => x.GetCompilationUnitRoot())
.SelectMany(x => x.FindSyntax<ClassDeclarationSyntax>())
.Where(x => x.IsPluginClass())
.ToArray();
var plugins = allPlugins.Where(x => x.IsExportIPlugin()).ToArray();
foreach (var p in allPlugins)
{
var semanticModel = compilation.GetSemanticModel(p.SyntaxTree);
var syntax = p.GetGuidMetadataValueSyntax();
if (syntax == null) continue; //GUID な Metadata がない場合はスルー
// GUID として解釈できない値か、IPlugin で未定義の GUID が指定されてたらアウト
var guidMetadata = syntax.GetGuidMetadata(semanticModel);
if (!guidMetadata.HasValue
|| plugins.All(x => x.GetGuidMetadataValueSyntax()?.GetGuidMetadata(compilation.GetSemanticModel(x.SyntaxTree)) != guidMetadata))
{
context.ReportDiagnostic(Diagnostic.Create(InvalidGuidMetadataRule, p.GetLocation()));
}
}
}
示例6: AnalyzeCompilation
private static void AnalyzeCompilation(CompilationAnalysisContext context)
{
var compilation = context.Compilation;
var plugins = compilation.SyntaxTrees
.Select(x => x.GetCompilationUnitRoot())
.SelectMany(x => x.FindSyntax<ClassDeclarationSyntax>())
.Where(x => x.IsExportIPlugin())
.ToArray();
var dupe = plugins
.GroupBy(x => x.GetGuidMetadataValue())
.Where(x => 1 < x.Count())
.ToArray();
if (!dupe.Any()) return;
foreach (var group in dupe)
{
foreach (var c in group)
{
var other = group.Except(new[] { c }).ToArray();
context.ReportDiagnostic(Diagnostic.Create(
DuplicateGuidRule,
c.GetLocation(),
string.Join(", ", other.Select(x => x.Identifier))));
}
}
}
示例7: OnCompilation
private static void OnCompilation(CompilationAnalysisContext context)
{
var diags = OnCompilationAsync(context.Compilation).Result;
foreach (var d in diags)
{
context.ReportDiagnostic(d);
}
}
示例8: AnalyzeCompilation
public void AnalyzeCompilation(CompilationAnalysisContext context)
{
foreach (var item in _fieldDisposedMap)
{
if (!item.Value)
{
context.ReportDiagnostic(item.Key.CreateDiagnostic(Rule));
}
}
}
示例9: AnalyzeCompilation
private static void AnalyzeCompilation(CompilationAnalysisContext context)
{
var compilation = context.Compilation;
var isDefined = compilation.SyntaxTrees
.Select(x => x.GetCompilationUnitRoot())
.SelectMany(x => x.DescendantNodes().OfType<SimpleBaseTypeSyntax>())
.Any(x => x.ToString() == "IPlugin" || x.ToString() == "Grabacr07.KanColleViewer.Composition.IPlugin")
;
if (!isDefined)
context.ReportDiagnostic(Diagnostic.Create(RequireIPluginRule, Location.None));
}
示例10: AnalyzeCompilation
private static void AnalyzeCompilation(CompilationAnalysisContext context)
{
// Get all the suppressed analyzer diagnostic IDs.
var suppressedAnalyzerDiagnosticIds = GetSuppressedAnalyzerDiagnosticIds(context.Compilation.Options.SpecificDiagnosticOptions);
foreach (var suppressedDiagnosticId in suppressedAnalyzerDiagnosticIds)
{
// For all such suppressed diagnostic IDs, produce a diagnostic.
var diagnostic = Diagnostic.Create(Rule, Location.None, suppressedDiagnosticId);
context.ReportDiagnostic(diagnostic);
}
}
示例11: AnalyzeCompilation
private static void AnalyzeCompilation(CompilationAnalysisContext context)
{
INamedTypeSymbol assemblyVersionAttributeSymbol = WellKnownTypes.AssemblyVersionAttribute(context.Compilation);
INamedTypeSymbol assemblyComplianceAttributeSymbol = WellKnownTypes.CLSCompliantAttribute(context.Compilation);
if (assemblyVersionAttributeSymbol == null && assemblyComplianceAttributeSymbol == null)
{
return;
}
bool assemblyVersionAttributeFound = false;
bool assemblyComplianceAttributeFound = false;
// Check all assembly level attributes for the target attribute
foreach (AttributeData attribute in context.Compilation.Assembly.GetAttributes())
{
if (attribute.AttributeClass.Equals(assemblyVersionAttributeSymbol))
{
// Mark the version attribute as found
assemblyVersionAttributeFound = true;
}
else if (attribute.AttributeClass.Equals(assemblyComplianceAttributeSymbol))
{
// Mark the compliance attribute as found
assemblyComplianceAttributeFound = true;
}
}
if (!assemblyVersionAttributeFound && assemblyVersionAttributeSymbol != null)
{
context.ReportDiagnostic(Diagnostic.Create(CA1016Rule, Location.None));
}
if (!assemblyComplianceAttributeFound && assemblyComplianceAttributeSymbol != null)
{
context.ReportDiagnostic(Diagnostic.Create(CA1014Rule, Location.None));
}
}
示例12: OnCompilationEnd
private void OnCompilationEnd(CompilationAnalysisContext context)
{
lock (_apisToEnsureExist)
{
if (_apisToEnsureExist.Count != 0)
{
// If we have not cleared the list of APIs that must exist then we need to give errors about them
foreach (var missingAPI in _apisToEnsureExist)
{
context.ReportDiagnostic(Diagnostic.Create(s_memberMustExistDiagnostic, Location.None, missingAPI));
}
}
}
}
示例13: HandleCompilation
private static void HandleCompilation(CompilationAnalysisContext context)
{
try
{
SettingsHelper.GetStyleCopSettings(context.Options, DeserializationFailureBehavior.ThrowException, context.CancellationToken);
}
catch (JsonException ex)
{
string details = ex.Message;
string completeDescription = string.Format(Description.ToString(CultureInfo.CurrentCulture), details);
var completeDescriptor = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.SpecialRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, completeDescription, HelpLink);
context.ReportDiagnostic(Diagnostic.Create(completeDescriptor, Location.None));
}
}
示例14: AnalizeCompilation
private void AnalizeCompilation(CompilationAnalysisContext context)
{
// Find CS0006: Metadata file '{0}' could not be found
Diagnostic invalidMetadataDiagnostic = context.Compilation
.GetDiagnostics().FirstOrDefault(d => string.Compare(d.Id, "CS0006") == 0);
if (invalidMetadataDiagnostic != null)
{
var argument = invalidMetadataDiagnostic.GetDiagnosticMessageArguments().First().ToString();
if (argument != null && string.Compare(Path.GetExtension(argument), ".dll") == 0)
{
var diagnostic = Diagnostic.Create(_supportedRule, invalidMetadataDiagnostic.Location,
argument, ".dll");
context.ReportDiagnostic(diagnostic);
}
}
}
示例15: AnalyzeCompilation
private static void AnalyzeCompilation(CompilationAnalysisContext context)
{
var compilation = context.Compilation;
var allPlugins = compilation.SyntaxTrees
.Select(x => x.GetCompilationUnitRoot())
.SelectMany(x => x.FindSyntax<ClassDeclarationSyntax>())
.Where(x => x.IsPluginClass())
.ToArray();
var plugins = allPlugins.Where(x => x.IsExportIPlugin()).ToArray();
foreach (var p in allPlugins)
{
var guidVaue = p.GetGuidMetadataValue();
if (guidVaue == null) continue; //GUID な Metadata がない場合はスルー
// GUID として解釈できない値か、IPlugin で未定義の GUID が指定されてたらアウト
Guid guid;
if (!Guid.TryParse(guidVaue, out guid)
|| plugins.All(x => x.GetGuidMetadataValue().ToUpper() != guidVaue.ToUpper()))
context.ReportDiagnostic(Diagnostic.Create(InvalidGuidMetadataRule, p.GetLocation()));
}
}