Esempio n. 1
0
 private static XElement ElementFromMessage(SuppressMessage message)
 {
     return(new XElement(SuppressMessageElement,
                         new XAttribute(IdAttribute, message.Id),
                         new XElement(TargetElement, message.Target),
                         new XElement(SyntaxNodeElement, message.SyntaxNode)));
 }
Esempio n. 2
0
        public static HashSet <SuppressMessage> LoadMessages(ISuppressionFileSystemService fileSystemService, string path)
        {
            XDocument document;

            lock (fileSystemService)
            {
                document = fileSystemService.Load(path);
            }

            if (document == null)
            {
                return(new HashSet <SuppressMessage>());
            }

            HashSet <SuppressMessage> suppressionMessages = new HashSet <SuppressMessage>();

            foreach (XElement suppressionMessageXml in document.Root.Elements(SuppressMessageElement))
            {
                SuppressMessage?suppressMessage = SuppressMessage.MessageFromElement(suppressionMessageXml);

                if (suppressMessage != null)
                {
                    suppressionMessages.Add(suppressMessage.Value);
                }
            }

            return(suppressionMessages);
        }
Esempio n. 3
0
        private bool IsSuppressedInSuppressionFile(SemanticModel semanticModel, Diagnostic diagnostic, CancellationToken cancellation)
        {
            cancellation.ThrowIfCancellationRequested();

            var(assembly, message) = SuppressMessage.GetSuppressionInfo(semanticModel, diagnostic, cancellation);

            if (assembly == null)
            {
                return(false);
            }

            SuppressionFile file = GetSuppressionFile(assembly);

            if (file == null)
            {
                return(false);
            }

            if (file.GenerateSuppressionBase)
            {
                if (IsSuppressableSeverity(diagnostic?.Descriptor.DefaultSeverity))
                {
                    file.AddMessage(message);
                }

                return(true);
            }

            return(file.ContainsMessage(message));
        }
Esempio n. 4
0
        public static bool SuppressDiagnostic(SemanticModel semanticModel, string diagnosticID, TextSpan diagnosticSpan,
                                              DiagnosticSeverity defaultDiagnosticSeverity, CancellationToken cancellation = default)
        {
            CheckIfInstanceIsInitialized(throwOnNotInitialized: true);

            if (!IsSuppressableSeverity(defaultDiagnosticSeverity))
            {
                return(false);
            }

            var(fileAssemblyName, suppressMessage) = SuppressMessage.GetSuppressionInfo(semanticModel, diagnosticID,
                                                                                        diagnosticSpan, cancellation);
            if (fileAssemblyName.IsNullOrWhiteSpace() || !suppressMessage.IsValid)
            {
                return(false);
            }

            lock (Instance._fileSystemService)
            {
                if (!Instance._fileByAssembly.TryGetValue(fileAssemblyName, out var file) || file == null)
                {
                    return(false);
                }

                file.AddMessage(suppressMessage);
                XDocument newSuppressionXmlFile = file.MessagesToDocument(Instance._fileSystemService);
                Instance._fileSystemService.Save(newSuppressionXmlFile, file.Path);
            }

            return(true);
        }
Esempio n. 5
0
 internal bool ContainsMessage(SuppressMessage message) => Messages.Contains(message);
Esempio n. 6
0
 internal void AddMessage(SuppressMessage message) => Messages.Add(message);
Esempio n. 7
0
 internal void AddMessage(SuppressMessage message) => Messages.TryAdd(message, null);