示例#1
0
        public override int Transform([NotNull] GlobalContext globalContext, Ignore Ignore,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            DependencyPattern idempotentPattern     = transformOptions.MarkerToAdd == null ? null : new DependencyPattern("'" + transformOptions.MarkerToAdd, globalContext.IgnoreCase);
            Dictionary <FromTo, Dependency> fromTos = transformOptions.Idempotent ? FromTo.AggregateAllDependencies(globalContext.CurrentGraph, dependencies) : null;

            int added   = 0;
            int removed = 0;

            foreach (var d in dependencies)
            {
                if (!transformOptions.RemoveOriginal)
                {
                    transformedDependencies.Add(d);
                }
                else
                {
                    removed++;
                }
                if (d.IsMarkerMatch(transformOptions.Matches, transformOptions.Excludes))
                {
                    if (fromTos == null ||
                        !FromTo.ContainsMatchingDependency(fromTos, d.UsedItem, d.UsingItem, idempotentPattern))
                    {
                        var newDependency = globalContext.CurrentGraph.CreateDependency(d.UsedItem, d.UsingItem, d.Source, d.MarkerSet, d.Ct,
                                                                                        d.QuestionableCt, d.BadCt, d.NotOkReason, d.ExampleInfo);
                        if (transformOptions.MarkerToAdd != null)
                        {
                            newDependency.IncrementMarker(transformOptions.MarkerToAdd);
                        }
                        transformedDependencies.Add(newDependency);
                        added++;
                    }
                }
            }
            Log.WriteInfo($"... added {added}{(removed > 0 ? " removed " + removed : "")} dependencies");
            return(Program.OK_RESULT);
        }