public void AnalyzeSymbol(ISymbol symbol, Compilation compilation, Action <Diagnostic> addDiagnostic, CancellationToken cancellationToken)
        {
            //var tree = compilation.SyntaxTrees.ToList()[2];
            //var model = compilation.GetSemanticModel(tree);

            var methodSymbol = (IMethodSymbol)symbol;

            ((CSharpRecognitionContext)RecognitionContextManager.ctx).Compilations = new List <Compilation> {
                compilation
            };
            RecognitionContextManager.InitLogger();


            RecognitionContextManager.ctx.Init(RecognitionContextManager.GetLogger(), false);
            FactoryMethodRecognizer fmrec = new FactoryMethodRecognizer();

            fmrec.Context = RecognitionContextManager.ctx;


            var methods = fmrec.Context.Types.Where(t => t.Methods != null).SelectMany(t => t.Methods);

            foreach (var m in methods.Cast <CSharpMethod>())
            {
                if (m.SourceSymbol == methodSymbol)
                {
                    if (fmrec.IsInstance(m))
                    {
                        var diagnostic = Diagnostic.Create(Rule, methodSymbol.Locations[0], methodSymbol.Name);
                        addDiagnostic(diagnostic);
                    }
                }
            }
        }
Пример #2
0
        public void AnalyzeSymbol(ISymbol symbol, Compilation compilation, Action <Diagnostic> addDiagnostic, CancellationToken cancellationToken)
        {
            //var tree = compilation.SyntaxTrees.ToList()[2];
            //var model = compilation.GetSemanticModel(tree);


            var typeSymbol = (INamedTypeSymbol)symbol;

            ((CSharpRecognitionContext)RecognitionContextManager.ctx).Compilations = new List <Compilation> {
                compilation
            };
            RecognitionContextManager.InitLogger();

            RecognitionContextManager.ctx.Init(RecognitionContextManager.GetLogger(), false);

            SingletonRecognizer fmrec = new SingletonRecognizer();

            fmrec.Context = RecognitionContextManager.ctx;

            foreach (var m in RecognitionContextManager.ctx.Types.Cast <CSharpNamedType>())
            {
                if (m.SourceSymbol == typeSymbol)
                {
                    if (fmrec.IsInstance(m))
                    {
                        var diagnostic = Diagnostic.Create(Rule, typeSymbol.Locations[0], typeSymbol.Name);
                        addDiagnostic(diagnostic);
                    }
                }
            }
        }