Exemplo n.º 1
0
Arquivo: Span.cs Projeto: 316729240/M5
        private void UpdateContent(TextChange change)
        {
            // Update the span's content
            Content = change.ApplyChange(this);

            ClearCachedStartPoints(Next);
        }
Exemplo n.º 2
0
        private bool IsAcceptableIdentifierReplacement(Span target, TextChange change)
        {
            if (!change.IsReplace)
            {
                return(false);
            }

            foreach (ISymbol isymbol in target.Symbols)
            {
                CSharpSymbol symbol = isymbol as CSharpSymbol;

                if (symbol == null)
                {
                    break;
                }

                int symbolStartIndex = target.Start.AbsoluteIndex + symbol.Start.AbsoluteIndex;
                int symbolEndIndex   = symbolStartIndex + symbol.Content.Length;

                // We're looking for the first symbol that contains the TextChange.
                if (symbolEndIndex > change.OldPosition)
                {
                    if (
                        symbolEndIndex >= change.OldPosition + change.OldLength &&
                        symbol.Type == CSharpSymbolType.Identifier
                        )
                    {
                        // The symbol we're changing happens to be an identifier. Need to check if its transformed state is also one.
                        // We do this transformation logic to capture the case that the new text change happens to not be an identifier;
                        // i.e. "5". Alone, it's numeric, within an identifier it's classified as identifier.
                        string transformedContent = change.ApplyChange(
                            symbol.Content,
                            symbolStartIndex
                            );
                        IEnumerable <ISymbol> newSymbols = Tokenizer(transformedContent);

                        if (newSymbols.Count() != 1)
                        {
                            // The transformed content resulted in more than one symbol; we can only replace a single identifier with
                            // another single identifier.
                            break;
                        }

                        CSharpSymbol newSymbol = (CSharpSymbol)newSymbols.First();
                        if (newSymbol.Type == CSharpSymbolType.Identifier)
                        {
                            return(true);
                        }
                    }
                    // Change is touching a non-identifier symbol or spans multiple symbols.

                    break;
                }
            }

            return(false);
        }
        private PartialParseResult TryAcceptChange(Span target, TextChange change, PartialParseResult acceptResult = PartialParseResult.Accepted)
        {
            string content = change.ApplyChange(target);

            if (StartsWithKeyword(content))
            {
                return(PartialParseResult.Rejected | PartialParseResult.SpanContextChanged);
            }

            return(acceptResult);
        }
        public void ApplyChangeWithReplacedTextReturnsNewContentWithChangeApplied()
        {
            // Arrange
            var newBuffer  = new StringTextBuffer("abcdefg");
            var oldBuffer  = new StringTextBuffer("");
            var textChange = new TextChange(1, 1, oldBuffer, 2, newBuffer);

            // Act
            string text = textChange.ApplyChange("abcdefg", 1);

            // Assert
            Assert.Equal("bcbcdefg", text);
        }
        public void ApplyChangeWithInsertedTextReturnsNewContentWithChangeApplied()
        {
            // Arrange
            var newBuffer  = new StringTextBuffer("test");
            var oldBuffer  = new StringTextBuffer("");
            var textChange = new TextChange(0, 0, oldBuffer, 3, newBuffer);

            // Act
            string text = textChange.ApplyChange("abcd", 0);

            // Assert
            Assert.Equal("tesabcd", text);
        }
Exemplo n.º 6
0
 protected virtual SpanBuilder UpdateSpan(Span target, TextChange normalizedChange)
 {
     var newContent = normalizedChange.ApplyChange(target);
     var newSpan = new SpanBuilder(target);
     newSpan.ClearSymbols();
     foreach (ISymbol sym in Tokenizer(newContent))
     {
         sym.OffsetStart(target.Start);
         newSpan.Accept(sym);
     }
     if (target.Next != null)
     {
         var newEnd = SourceLocationTracker.CalculateNewLocation(target.Start, newContent);
         target.Next.ChangeStart(newEnd);
     }
     return newSpan;
 }
Exemplo n.º 7
0
        protected virtual SpanBuilder UpdateSpan(Span target, TextChange normalizedChange)
        {
            var newContent = normalizedChange.ApplyChange(target);
            var newSpan    = new SpanBuilder(target);

            newSpan.ClearSymbols();
            foreach (ISymbol sym in Tokenizer(newContent))
            {
                sym.OffsetStart(target.Start);
                newSpan.Accept(sym);
            }
            if (target.Next != null)
            {
                var newEnd = SourceLocationTracker.CalculateNewLocation(target.Start, newContent);
                target.Next.ChangeStart(newEnd);
            }
            return(newSpan);
        }
Exemplo n.º 8
0
        private PartialParseResult TryAcceptChange(Span target, TextChange change, PartialParseResult acceptResult = PartialParseResult.Accepted)
        {
            var content = change.ApplyChange(target);
            if (StartsWithKeyword(content))
            {
                return PartialParseResult.Rejected | PartialParseResult.SpanContextChanged;
            }

            return acceptResult;
        }
Exemplo n.º 9
0
        public void ApplyChangeWithReplacedTextReturnsNewContentWithChangeApplied()
        {
            // Arrange
            var newBuffer = new StringTextBuffer("abcdefg");
            var oldBuffer = new StringTextBuffer("");
            var textChange = new TextChange(1, 1, oldBuffer, 2, newBuffer);

            // Act
            var text = textChange.ApplyChange("abcdefg", 1);

            // Assert
            Assert.Equal("bcbcdefg", text);
        }
Exemplo n.º 10
0
        public void ApplyChangeWithInsertedTextReturnsNewContentWithChangeApplied()
        {
            // Arrange
            var newBuffer = new StringTextBuffer("test");
            var oldBuffer = new StringTextBuffer("");
            var textChange = new TextChange(0, 0, oldBuffer, 3, newBuffer);

            // Act
            var text = textChange.ApplyChange("abcd", 0);

            // Assert
            Assert.Equal("tesabcd", text);
        }