internal static bool UsesUnderscoreNames(this SyntaxNode node, SemanticModel semanticModel, CancellationToken cancellationToken) { using (var pooled = Walker.Create(node, semanticModel, cancellationToken)) { if (pooled.Item.UsesThis == Result.Yes) { return(false); } if (pooled.Item.UsesUnderScore == Result.Yes) { return(true); } } foreach (var tree in semanticModel.Compilation.SyntaxTrees) { using (var pooled = Walker.Create(tree.GetRoot(cancellationToken), semanticModel, cancellationToken)) { if (pooled.Item.UsesThis == Result.Yes) { return(false); } if (pooled.Item.UsesUnderScore == Result.Yes) { return(true); } } } return(false); }
private static void HandleDeclaration(SyntaxNodeAnalysisContext context) { if (context.IsExcludedFromAnalysis()) { return; } var attributeSyntax = context.Node as AttributeSyntax; if (attributeSyntax == null || attributeSyntax.IsMissing) { return; } var type = context.SemanticModel.GetTypeInfoSafe(attributeSyntax, context.CancellationToken).Type; if (type != KnownSymbol.XmlnsDefinitionAttribute) { return; } using (var walker = Walker.Create(context.Compilation, context.SemanticModel, context.CancellationToken)) { if (walker.Item.NotMapped.Count != 0) { var missing = ImmutableDictionary.CreateRange( walker.Item.NotMapped.Select(x => new KeyValuePair <string, string>(x, x))); context.ReportDiagnostic(Diagnostic.Create(Descriptor, attributeSyntax.GetLocation(), missing)); } } }
internal static bool UsesUnderscoreNames(this SyntaxNode node, SemanticModel semanticModel, CancellationToken cancellationToken) { using (var pooled = Walker.Create(node, semanticModel, cancellationToken)) { return(pooled.Item.UsesUnderScore == Result.Yes || pooled.Item.UsesThis == Result.No); } }
private static void Handle(SyntaxNodeAnalysisContext context) { if (!context.IsExcludedFromAnalysis() && context.Node is AttributeSyntax attribute && context.SemanticModel.TryGetNamedType(attribute, KnownSymbols.XmlnsDefinitionAttribute, context.CancellationToken, out _)) { using var walker = Walker.Create(context.Compilation, context.SemanticModel, context.CancellationToken); if (walker.NotMapped.Count != 0) { var missing = ImmutableDictionary.CreateRange(walker.NotMapped.Select(x => new KeyValuePair <string, string>(x, x))); context.ReportDiagnostic(Diagnostic.Create(Descriptors.WPF0052XmlnsDefinitionsDoesNotMapAllNamespaces, attribute.GetLocation(), missing, string.Join(Environment.NewLine, walker.NotMapped))); } } }
private static void Handle(SyntaxNodeAnalysisContext context) { if (context.IsExcludedFromAnalysis()) { return; } if (context.Node is AttributeSyntax attribute && Gu.Roslyn.AnalyzerExtensions.Attribute.IsType(attribute, KnownSymbol.XmlnsDefinitionAttribute, context.SemanticModel, context.CancellationToken)) { using (var walker = Walker.Create(context.Compilation, context.SemanticModel, context.CancellationToken)) { if (walker.NotMapped.Count != 0) { var missing = ImmutableDictionary.CreateRange(walker.NotMapped.Select(x => new KeyValuePair <string, string>(x, x))); context.ReportDiagnostic(Diagnostic.Create(Descriptor, attribute.GetLocation(), missing, string.Join(Environment.NewLine, walker.NotMapped))); } } } }