コード例 #1
0
        /// <summary>
        ///     Returns a <see cref="ITraverserAction" /> action that ensures instances of type
        ///     <typeparamref name="T" /> have ancestors within the type list <paramref name="validAncestorTypes" />.
        /// </summary>
        /// <typeparam name="T">The type to check.</typeparam>
        /// <param name="validAncestorTypes">An array of the types that may be ancestors of that object.</param>
        /// <returns>An <see cref="ITraverserAction{T}" />.</returns>
        public static ITraverserAction CheckAncestors <T>(params Type[][] validAncestorTypes)
            where T : IContained
        {
            return(new TraverserAction <T>(
                       (obj, errLis) =>
            {
                IContained current = obj;
                foreach (var parentTypes in validAncestorTypes)
                {
                    CheckInstanceParent(parentTypes, current, errLis);
                    current = current.Parent as IContained;

                    if (current != null)
                    {
                        continue;
                    }

                    var parentsText = parentTypes.Select(t => $"'{Names.OfType(t).ToLower()}s'").DelimiteredConcat(", ", " or ");
                    var message = $"A '{obj.ObjectName.ToLower()}' does not have a parent. " +
                                  $"'{obj.ObjectName.ToUpperFirstLowerRest()}s' are expected to have {parentsText} as parents.";
                    errLis.Error(new TraverserException(obj, message));
                    break;
                }
            }));
        }
コード例 #2
0
        public void InvalidNotUnique()
        {
            var none       = new IContained[] { };
            var empty      = new List <FileLine>();
            var sourceList = new List <ISourceFile>
            {
                new SourceFile(string.Empty, "project/src/File1", none, string.Empty, empty),
                new SourceFile(string.Empty, "project/src/File1", none, string.Empty, empty)
            };

            var project = new Project(sourceList);

            ITraverserAction action = TraverserActions.UniqueSourceNames as ITraverserAction <Project>;

            action.Act(project, new StandardErrorListener <TraverserException>());
        }
コード例 #3
0
        private static void CheckInstanceParent(IEnumerable <Type> validParentTypes, IContained obj, IErrorListener <TraverserException> errLis)
        {
            var valid = false;

            obj.Parent.GetType().ForTypeBaseTypesAndInterfaces(t => valid |= validParentTypes.Contains(t));

            if (valid)
            {
                return;
            }

            var parentsText = validParentTypes.Select(t => $"'{Names.OfType(t).ToLower()}s'").DelimiteredConcat(", ", " or ");
            var message     = $"A '{obj.ObjectName.ToLower()}' has a '{obj.Parent.ObjectName.ToLower()}' for a parent. " +
                              $"'{obj.ObjectName.ToUpperFirstLowerRest()}s' are expected to have {parentsText} as parents.";

            errLis.Error(new TraverserException(obj, message));
        }
コード例 #4
0
ファイル: Traversal.cs プロジェクト: CPardi/Doctran
        /// <summary>
        /// Search the ancestors of an instance of <see cref="IContained"/> for an instance of type <typeparamref name="T"/>.
        /// </summary>
        /// <typeparam name="T">The type to search for.</typeparam>
        /// <param name="contained">The instances whose ancestors are to be searched.</param>
        /// <returns>The ancestor of type <typeparamref name="T"/>.</returns>
        public static T AncestorOfType <T>(IContained contained)
            where T : class, IFortranObject
        {
            if (contained == null)
            {
                return(null);
            }

            IFortranObject current  = contained;
            var            currentT = contained as T;

            while (current != null && currentT == null)
            {
                current  = (current as IContained)?.Parent;
                currentT = current as T;
            }

            return(currentT);
        }
コード例 #5
0
        public void ValidNotUnique()
        {
            var none       = new IContained[] { };
            var empty      = new List <FileLine>();
            var sourceList = new List <ISourceFile>
            {
                new SourceFile(string.Empty, "project/src/File1", none, string.Empty, empty),
                new SourceFile(string.Empty, "project/examples/File1", none, string.Empty, empty)
            };

            var project = new Project(sourceList);

            ITraverserAction action = TraverserActions.UniqueSourceNames as ITraverserAction <Project>;

            action.Act(project, new StandardErrorListener <TraverserException>());
            Assert.AreEqual(1, project.SourceNameUniquenessLevel);
            Assert.AreEqual("src/File1", sourceList[0].Name);
            Assert.AreEqual("examples/File1", sourceList[1].Name);
        }
コード例 #6
0
 public void RemoveSubObject(IContained containedItem) => CollectionUtils.RemoveSubObject(_subObjects, this, containedItem);
コード例 #7
0
 public void InsertSubObject(int index, IContained containedItem) => CollectionUtils.InsertSubObject(_subObjects, this, index, containedItem);
コード例 #8
0
 public void AddSubObject(IContained containedItem) => CollectionUtils.AddSubObject(_subObjects, this, containedItem);
コード例 #9
0
ファイル: CollectionUtils.cs プロジェクト: CPardi/Doctran
 public static void RemoveSubObject(List <IContained> subObjects, IContainer container, IContained contained)
 {
     subObjects.Remove(contained);
 }
コード例 #10
0
ファイル: CollectionUtils.cs プロジェクト: CPardi/Doctran
 public static void InsertSubObject(List <IContained> subObjects, IContainer container, int index, IContained contained)
 {
     contained.Parent = container;
     subObjects.Insert(index, contained);
 }
コード例 #11
0
ファイル: CollectionUtils.cs プロジェクト: CPardi/Doctran
 public static void AddSubObject(List <IContained> subObjects, IContainer container, IContained contained)
 {
     contained.Parent = container;
     subObjects.Add(contained);
 }