コード例 #1
0
ファイル: TagsParser.cs プロジェクト: TAHK518/clean-code
        private static IEnumerable <TagsPair> GetAllInvalidTagsPair(TagsPair currentPair, IReadOnlyCollection <TagsPair> previousPairs,
                                                                    IReadOnlyCollection <TagSpecification> currentSpecifications)
        {
            var specificationForCurrentPairType = currentSpecifications.First(t => t.TagType == currentPair.PairType);

            return(previousPairs.Where(pair => pair.EndPosition > currentPair.StartPosition).Where(tagPair => specificationForCurrentPairType.IgnoreTags.Contains(tagPair.PairType)).ToList());
        }
コード例 #2
0
ファイル: TagsParser.cs プロジェクト: TAHK518/clean-code
        private static List <TagsPair> GetTagsPair(Queue <Tag> characterSequences, IReadOnlyCollection <TagSpecification> currentSpecifications, IReadOnlyCollection <TagType> tagsByLine)
        {
            var previousPairs             = new List <TagsPair>();
            var openingTags               = new List <Tag>();
            var tagsPairAfterBlockingTags = new List <TagsPair>();

            while (characterSequences.Count > 0)
            {
                var currentTag = characterSequences.Dequeue();
                if (currentTag.TagType == TagType.EndLine && TryGetLastLineOpenTag(openingTags, tagsByLine, currentTag, out var newTag))
                {
                    currentTag = newTag;
                }
                var startTag = openingTags.FindLast(t => t.TagType == currentTag.TagType);
                if (CurrentTagCannotCreatePair(startTag, currentTag))
                {
                    if (currentTag.PositionType != PositionType.ClosingTag)
                    {
                        openingTags.Add(new Tag(currentTag.TagType, currentTag.PositionInText, PositionType.OpeningTag, currentTag.Value));
                    }
                    continue;
                }
                var currentPair = new TagsPair(currentTag.TagType, startTag, currentTag);
                openingTags.Remove(startTag);
                foreach (var invalidOpeningTags in GetAllInvalidOpeningTag(currentPair, openingTags, currentSpecifications))
                {
                    openingTags.Remove(invalidOpeningTags);
                }
                foreach (var invalidTagsPair in GetAllInvalidTagsPair(currentPair, tagsPairAfterBlockingTags, currentSpecifications))
                {
                    tagsPairAfterBlockingTags.Remove(invalidTagsPair);
                    if (invalidTagsPair.StartPosition > currentPair.StartPosition)
                    {
                        continue;
                    }
                    InsertOpeningTags(openingTags, invalidTagsPair.StartTag);
                }
                if (CanRemoveCurrentPairInTheFuture(openingTags, currentSpecifications, currentPair.PairType))
                {
                    tagsPairAfterBlockingTags.Add(currentPair);
                }
                else
                {
                    previousPairs.Add(currentPair);
                }
            }
            previousPairs.AddRange(tagsPairAfterBlockingTags);
            return(previousPairs);
        }
コード例 #3
0
ファイル: TagsParser.cs プロジェクト: TAHK518/clean-code
        private static IEnumerable <Tag> GetAllInvalidOpeningTag(TagsPair currentPair, IReadOnlyCollection <Tag> previousOpeningTags, IReadOnlyCollection <TagSpecification> currentSpecifications)
        {
            var specificationForCurrentPairType = currentSpecifications.First(t => t.TagType == currentPair.PairType);

            return(previousOpeningTags.Where(tag => tag.PositionInText > currentPair.StartPosition).Where(tag => specificationForCurrentPairType.IgnoreTags.Contains(tag.TagType)).ToList());
        }