Exemplo n.º 1
0
 /// <summary>
 /// Removes <see cref="Word"/>s which were overwritten or deleted.
 /// </summary>
 /// <param name="thisWord">The <see cref="Word"/> which has overwritten a <see cref="Word"/> in <see cref="MainClass.AllWordsInCode"/>.</param>
 private static void RemoveNonExistingWord(Word thisWord)
 {
     for (int i = 1; i < AllWordsInCode.Count + 1; i++)
     {
         if (thisWord.StartPosition.GetOffsetToPosition(AllWordsInCode[i - 1].StartPosition) == 0 ||
             thisWord.EndPosition.GetOffsetToPosition(AllWordsInCode[i - 1].EndPosition) == 0)
         {
             AllWordsInCode.Remove(AllWordsInCode[i - 1]);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Updates <see cref="WordType"/>s of the <see cref="Word"/>s in <see cref="MainClass.AllWordsInCode"/> according to the given <see cref="Word"/>.
        /// </summary>
        /// <param name="thisWord">
        /// The <see cref="Word"/> which possibly changes its successors.
        /// </param>
        /// <param name="programmingLanguage">
        /// A <see cref="ProgrammingLanguage"/> which holds important information for the <see cref="WordType"/>s.
        /// </param>
        /// <returns>
        /// A <see cref="List{Word}"/> containing all <see cref="Word"/>s which <see cref="WordType"/>s were changed.
        /// </returns>
        private static List <Word> UpdateWordTypes(Word thisWord, ProgrammingLanguage programmingLanguage)
        {
            var changedWords = new List <Word>();

            switch (thisWord.Type)
            {
            case WordType.LineCommentary:
                var tempLineEnd         = thisWord.StartPosition.GetLineStartPosition(1);
                var lineEnd             = (tempLineEnd ?? thisWord.StartPosition.DocumentEnd).GetInsertionPosition(LogicalDirection.Backward);
                var lineCommentaryRange = new TextRange(thisWord.EndPosition, lineEnd);
                var lineCommentaryWords = AllWordsInCode.Where(word => lineCommentaryRange.Contains(word.StartPosition)).ToList();
                foreach (var word in lineCommentaryWords)
                {
                    Word newWord;
                    ChangeWordType(word, out newWord);
                    changedWords.Add(newWord);
                }

                break;

            case WordType.BlockCommentary:
                var endPointer = thisWord.StartPosition.DocumentEnd;
                try
                {
                    var endWord = AllWordsInCode.First(
                        word =>
                        thisWord.StartPosition.CompareTo(word.StartPosition) > 0 &&
                        word.Content.EndsWith(programmingLanguage.EndTokens["BlockCommentary"]));
                    endPointer = endWord.EndPosition;
                }
                catch (InvalidOperationException) { }
                var blockCommentaryRange = new TextRange(thisWord.EndPosition, endPointer);
                var blockCommentaryWords = AllWordsInCode.Where(word => blockCommentaryRange.Contains(word.StartPosition)).ToList();
                foreach (var word in blockCommentaryWords)
                {
                    Word newWord;
                    ChangeWordType(word, out newWord);
                    changedWords.Add(newWord);
                }

                break;

            case WordType.Value:
                var endPosition = thisWord.StartPosition.DocumentEnd;
                try
                {
                    var lastWord = AllWordsInCode.First(
                        word =>
                        thisWord.StartPosition.CompareTo(word.StartPosition) > 0 &&
                        word.Content.EndsWith(programmingLanguage.EndTokens["String"]));
                    endPosition = lastWord.EndPosition;
                }
                catch (InvalidOperationException) { }
                var stringRange = new TextRange(thisWord.EndPosition, endPosition);
                var stringWords = AllWordsInCode.Where(word => stringRange.Contains(word.StartPosition)).ToList();
                foreach (var word in stringWords)
                {
                    Word newWord;
                    ChangeWordType(word, out newWord);
                    changedWords.Add(newWord);
                }

                break;
            }

            return(changedWords);
        }