public IEnumerable<CodeIssue> GetIssues(IDocument document, CommonSyntaxNode node, CancellationToken cancellationToken)
        {
            var classNode = (ClassDeclarationSyntax) node;

            if (classNode.BaseListOpt == null) return null;

            var walker = new MilSyntaxWalker();
            walker.Visit((SyntaxNode) document.GetSyntaxTree(cancellationToken).Root);
            var allCommandHandlersInProject = walker.CommandHandlers;

           
            if (!allCommandHandlersInProject.Any() && !allCommandHandlersInProject.Contains(node)) return null;

            var dupes = walker.CommandHandlers.SelectMany(x => x.BaseListOpt.Types).FindDuplicates();

            if (!dupes.Any())
            {
                var desc = "{0} is implemented by multiple handlers:{1}{2}";
                var issues = new List<CodeIssue>();
                foreach (var dupe in dupes)
                {
                    var listing = FormatHandlerListing(dupe.GetClassName(), allCommandHandlersInProject.ToDictionary(x => x, syntax => syntax.BaseListOpt.Types.OfType<GenericNameSyntax>()));
                    var text = string.Format(desc, dupe, Environment.NewLine, string.Join(Environment.NewLine, listing));
                    issues.Add(new CodeIssue(CodeIssue.Severity.Warning, classNode.Identifier.FullSpan, text));
                }
                return issues;
            }
            return null;

            //if (allCommandHandlersInProject.Contains(node as ClassDeclarationSyntax))
            //{
            //    return new CodeIssue[] { new CodeIssue(CodeIssue.Severity.Warning, node.FullSpan, "Command Handler detected") };
            //}
        }
        public MilSyntaxWalker ExtractMessagingSyntax(MilSyntaxWalker walk = null)
        {
            if (walk == null && walker == null)
                walker = new MilSyntaxWalker();
            else
                walker = walk;

            foreach (var tree in _compilation.SyntaxTrees)
            {
                walker.Visit(tree.GetRoot());
            }

            return walker;
        }
        public MilSyntaxWalker ExtractMessagingSyntax(MilSyntaxWalker walk = null)
        {
            if (walk == null && walker == null)
            {
                walker = new MilSyntaxWalker();
            }
            else
            {
                walker = walk;
            }

            foreach (var tree in _compilation.SyntaxTrees)
            {
                walker.Visit(tree.GetRoot());
            }

            return(walker);
        }
Exemple #4
0
 private void DumpSyntaxData(MilSyntaxWalker treeData)
 {
     SendMessage(Environment.NewLine + "# Aggregate roots" + Environment.NewLine);
     SendMessage((treeData.AggregateRoots.Any() ? treeData.DumpAggregateRoots() : new[] { "-- none --" } as dynamic));
     SendMessage(Environment.NewLine + "# Commands" + Environment.NewLine);
     SendMessage((treeData.Commands.Any() || treeData.CommandHandlers.Any() ? treeData.DumpCommandData() : new[] { "-- none --" } as dynamic));
     SendMessage(Environment.NewLine + "# Events" + Environment.NewLine);
     SendMessage((treeData.Events.Any() || treeData.EventHandlers.Any() ? treeData.DumpEventData() : new[] { "-- none --" } as dynamic));
     SendMessage(Environment.NewLine + "# Message publications" + Environment.NewLine);
     SendMessage(treeData.PublicationCalls.Any() ? treeData.DumpPublicationData() : new[] { "-- none --" });
 }
Exemple #5
0
        public void Run()
        {
            Solution sln = LoadSolution();

            //var externalProject = sln.Projects.FirstOrDefault(x => x.AssemblyName == externalNs);
            //if (externalProject == null)
            //{
            //    var msg = string.Format("Project for given external-facing namespace of {0} not found.", externalNs);
            //    messagePump.OnError(new ArgumentException(msg));
            //    return;
            //}

            SendMessage(string.Format("{1}Using {0} for process discovery{1}", processTypeName ?? DefaultProcessIfxName, Environment.NewLine));

            var token = new CancellationToken();
            var analyzer = new MIL.Services.ProcessAnalysisService(processIName);

            //ProcessDefinition processDefinition = null;
            var excludeList = sln.Projects.Where(x => ExcludedAssemblies.Any(e => x.AssemblyName.Contains(e))).ToList();
            if (excludeList.Any())
            {
                SendMessage(string.Format("Ignoring {0} Assemblies{1}", excludeList.Count, Environment.NewLine),
                    () => "Ignored assemblies: " + Environment.NewLine + string.Join(Environment.NewLine, excludeList.Select(x => x.AssemblyName)) + Environment.NewLine);
            }

            MilSyntaxWalker treeData = new MilSyntaxWalker();
            foreach (var proj in sln.Projects.Except(excludeList))
            {
                SendMessage(".", () => Environment.NewLine + "# Processing assembly " + proj.AssemblyName + Environment.NewLine);

                MilSemanticAnalyzer semantics = null;
                MetadataFileReferenceProvider provider = new MetadataFileReferenceProvider();
                Compilation compilation = (Compilation)proj.GetCompilationAsync(token).Result
                    .AddReferences(new MetadataFileReference(typeof(object).Assembly.Location))
                    .AddReferences(new MetadataFileReference(typeof(IEnumerable<>).Assembly.Location)); ;

                try
                {
                    semantics = new MilSemanticAnalyzer(compilation);
                }
                catch (InvalidOperationException ex)
                {
                    SendMessage("x", () => string.Join(Environment.NewLine, compilation.GetDeclarationDiagnostics().Select(x => x.ToString())) + Environment.NewLine);
                    continue;
                }

                semantics.ExtractMessagingSyntax(treeData);

                //if (proj.AssemblyName == externalProject.AssemblyName)
                //    continue;

                //processDefinition = analyzer.GetProcessDefinition(compilation, processTypeName);


                //if (processDefinition != null)
                //{
                //    var procToke = ProcessDefinition.GetTokenFromDefinition(processDefinition);

                //    if (procToke.Token != MilTypeConstant.EmptyToken)
                //        SendMessage(procToke.ToString());
                //}
                //foreach (var pubCall in semantics.GetMessagePublicationData())
                //{
                //    SendMessage(pubCall.ToString());
                //}
            }

            DumpSyntaxData(treeData);

            messagePump.OnCompleted();
        }
            public given_a_syntax_tree()
            {
                declarationTree = SyntaxFactory.ParseSyntaxTree(declarationCode);
                logicTree = SyntaxFactory.ParseSyntaxTree(programCode);
                infraTree = SyntaxFactory.ParseSyntaxTree(infraCode);
                compilation = CSharpCompilation.Create("test.exe")
                    .AddSyntaxTrees(infraTree)
                    .AddSyntaxTrees(declarationTree)
                    .AddSyntaxTrees(logicTree)
                    .AddReferences(new MetadataFileReference(typeof(object).Assembly.Location));

                sut = new MilSyntaxWalker();
            }