Beispiel #1
0
        private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
        {
            if (context.IsFromGeneratedCode())
            {
                return;
            }
            var tree = context.SemanticModel.SyntaxTree;
            var root = tree.GetRoot();
            var unncessaryImports = GetUnnecessaryImports(context.SemanticModel, root);

            if (unncessaryImports != null && unncessaryImports.Any())
            {
                Func <SyntaxNode, SyntaxToken> getLastTokenFunc = GetLastTokenDelegateForContiguousSpans();
                var contiguousSpans = unncessaryImports.GetContiguousSpans(getLastTokenFunc);
                var diagnostics     = CreateClassificationDiagnostics(contiguousSpans, tree).Concat(
                    CreateFixableDiagnostics(unncessaryImports, tree));
                var spans = new List <TextSpan> ();
                foreach (var diagnostic in diagnostics)
                {
                    if (spans.Any(s => s.OverlapsWith(diagnostic.Location.SourceSpan)))
                    {
                        continue;
                    }
                    spans.Add(diagnostic.Location.SourceSpan);
                    context.ReportDiagnostic(diagnostic);
                }
            }
        }
		private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
		{
			if (context.IsFromGeneratedCode ())
				return;
			var tree = context.SemanticModel.SyntaxTree;
			var root = tree.GetRoot();
			var unncessaryImports = GetUnnecessaryImports(context.SemanticModel, root);
			if (unncessaryImports != null && unncessaryImports.Any())
			{
				Func<SyntaxNode, SyntaxToken> getLastTokenFunc = GetLastTokenDelegateForContiguousSpans();
				var contiguousSpans = unncessaryImports.GetContiguousSpans(getLastTokenFunc);
				var diagnostics = CreateClassificationDiagnostics(contiguousSpans, tree).Concat(
					CreateFixableDiagnostics(unncessaryImports, tree));
				var spans = new List<TextSpan> ();
				foreach (var diagnostic in diagnostics)
				{
					if (spans.Any (s => s.OverlapsWith (diagnostic.Location.SourceSpan)))
						continue;
					spans.Add (diagnostic.Location.SourceSpan);
					context.ReportDiagnostic(diagnostic);
				}
			}
		}