예제 #1
0
        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);
        }
예제 #2
0
        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));
                }
            }
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
 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)));
         }
     }
 }
예제 #5
0
        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)));
                    }
                }
            }
        }