コード例 #1
0
        private static void ParseComments([NotNull] TransformationContext context, [NotNull] ModelContainer container)
        {
            Logger.Info("parsing comments");

            var sources         = context.Comments.GetSourcesWithComments();
            var notFoundCounter = 0;

            foreach (var sourceSnapshot in sources)
            {
                var models = container.GetAll <Model>().Where(model =>
                                                              model.Comments.FullPath == sourceSnapshot.File.FullName &&
                                                              model.ModelType != ModelType.Module);
                var comments = context.Comments.GetAllComments(sourceSnapshot).ToList();

                var results = new List <CommentBlock>();
                results.AddRange(models.SelectMany(model => model.FindCommentsForMembers(context.Comments)));

                Logger.Trace("finding parent for orphaned comments");
                var orphanedComments = comments
                                       .Where(comment => results.All(found => comment.Location != found.Location))
                                       .Select(comment => new CommentWrapper(comment))
                                       .ToArray();

                Logger.Info($"total orphaned: {orphanedComments.Length} in {sourceSnapshot.File.FullName}");
                var modules = container.GetAll <ModuleModel>().Where(model =>
                                                                     model.Comments.FullPath == sourceSnapshot.File.FullName)
                              .ToArray();
                foreach (var notFoundComment in orphanedComments)
                {
                    var targetModule =
                        modules.FirstOrDefault(module => module.Name == notFoundComment.Comment.Location.Source.File.FullName);
                    if (targetModule == null)
                    {
                        continue;
                    }

                    foreach (var member in targetModule.Items)
                    {
                        if (member.Comments.Location.HasValue &&
                            notFoundComment.Comment.Location.IntersectsWith(member.Comments.Location.Value))
                        {
                            member.Comments.AddComments(notFoundComment.Comment);
                            notFoundComment.WasFound = true;
                            break;
                        }
                    }
                }

                var notFoundComments = orphanedComments.Where(comm => !comm.WasFound).ToArray();
                Logger.Trace($"total not found: {notFoundComments.Length}");
                notFoundCounter += notFoundComments.Length;
                foreach (var notFoundComment in notFoundComments)
                {
                    Logger.Trace(notFoundComment.Comment.Location);
                }
            }

            Logger.Trace($"total not found: {notFoundCounter}");

            Logger.Info($"finished parsing comments");
        }
コード例 #2
0
        private static void CreateModels([NotNull] NamespaceSymbol root, [NotNull] ModelContainer container)
        {
            foreach (var symbol in root.MemberTable.AllSymbols)
            {
                switch (symbol)
                {
                case ArraySymbol array:
                    break;

                case BarrierSymbol barrier:
                    container.Add(
                        new BarrierModel(barrier));
                    break;

                case Deployment.SetSymbol deployment:
                    container.Add(
                        new DeploymentSetModel(deployment));
                    break;

                case Deployment.ScriptSymbol deployment:
                    container.Add(
                        new DeploymentScriptModel(deployment));
                    break;

                case Deployment.CurryingSymbol deployment:
                    container.Add(
                        new DeploymentCurryingModel(deployment));
                    break;

                case DeploymentRebootSymbol deployment:
                    container.Add(
                        new DeploymentRebootModel(deployment));
                    break;

                case Deployment.SelectSymbol deployment:
                    container.Add(
                        new DeploymentSelectModel(deployment));
                    break;

                case ExternalSymbol external:
                    container.Add(external.GetExternalFields(container));
                    break;

                case TypeAliasSymbol type:
                    break;

                case NamespaceSymbol nameSpace:
                    break;

                case Platform.DefSymbol platform:
                    container.Add(new PlatformModel(platform));
                    break;

                case Platform.SetSymbol platform:
                    container.Add(new PlatformsSetModel(platform));
                    break;

                case Product.DefSymbol product:
                    container.Add(new ProductModel(product));
                    break;

                case Product.SetSymbol product:
                    container.Add(new ProductSetModel(product));
                    break;

                case ProductTypeSymbol productType:
                    container.Add(new ProductTypeModel(productType));
                    break;

                case Scenario.DefSymbol scenario:
                    container.Add(new ScenarioModel(scenario));
                    break;

                case Scenario.SetSymbol scenario:
                    container.Add(new ScenarioSetModel(scenario));
                    break;

                case SuiteTypeSymbol suiteTypeSymbol:
                    container.Add(new SuiteTypeModel(suiteTypeSymbol));
                    break;

                case Suite.DefSymbol suite:
                    container.Add(new SuiteDefModel(suite));
                    break;

                case ModuleSymbol module:
                    container.Add(new ModuleModel(module));
                    break;

                case TypeSymbol type:
                    break;

                default:
                    Logger.Warn(
                        $"Unknown symbol {symbol.Name}{Constants.TabulationSymbol}{symbol.Kind}{Constants.TabulationSymbol}{symbol.GetType()}");
                    break;
                }
            }
        }