public async Task VerifyRefactoringAsync(
            string theory,
            string fromData,
            string toData,
            string equivalenceKey               = null,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            (TextSpan span, string source, string expected) = SpanParser.ReplaceEmptySpan(theory, fromData, toData);

            TextSpanParserResult result = SpanParser.GetSpans(source, reverse: true);

            if (result.Spans.Any())
            {
                await VerifyRefactoringAsync(
                    source : result.Text,
                    expected : expected,
                    spans : result.Spans.Select(f => f.Span),
                    equivalenceKey : equivalenceKey,
                    options : options,
                    cancellationToken : cancellationToken).ConfigureAwait(false);
            }
            else
            {
                await VerifyRefactoringAsync(
                    source : source,
                    expected : expected,
                    span : span,
                    equivalenceKey : equivalenceKey,
                    options : options,
                    cancellationToken : cancellationToken).ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
 public CSharpChunkParser(SpanParser spanParser, Mono.TextEditor.Document doc, Style style, SyntaxMode mode, LineSegment line) : base(spanParser, doc, style, mode, line)
 {
     foreach (var tag in ProjectDomService.SpecialCommentTags)
     {
         tags.Add(tag.Tag);
     }
 }
Ejemplo n.º 3
0
            public CSharpChunkParser(SpanParser spanParser, Mono.TextEditor.Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) : base(spanParser, doc, style, mode, line)
            {
                document = IdeApp.Workbench.GetDocument(doc.FileName);

                foreach (var tag in ProjectDomService.SpecialCommentTags)
                {
                    tags.Add(tag.Tag);
                }
//				ICSharpCode.OldNRefactory.Ast.CompilationUnit unit = null;
//				if (document != null && document.ParsedDocument != null && MonoDevelop.Core.PropertyService.Get ("EnableSemanticHighlighting", false)) {
//					resolver = document.GetResolver ();
//					if (!document.ParsedDocument.TryGetTag (out unit)) {
//						try {
//							using (ICSharpCode.OldNRefactory.IParser parser = ICSharpCode.OldNRefactory.ParserFactory.CreateParser (ICSharpCode.OldNRefactory.SupportedLanguage.CSharp, document.Editor.Document.OpenTextReader ())) {
//								parser.Parse ();
//								unit = parser.CompilationUnit;
//								document.ParsedDocument.SetTag (unit);
//							}
//						} catch (Exception) {
//							resolver = null;
//							return;
//						}
//					}
//					resolver.SetupParsedCompilationUnit (unit);
//				}
            }
Ejemplo n.º 4
0
            public override void Analyze(TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
            {
                // Check line start
                int  o = line.Offset;
                char c = '\0';

                for (; o < line.EndOffset && char.IsWhiteSpace(c = doc.GetCharAt(o)); o++)
                {
                    ;
                }

                if (c != '-' && c != '#')
                {
                    return;
                }

                DSyntax.Document = doc;
                var spanParser = new SpanParser(DSyntax, new CloneableStack <Span>());
                var chunkP     = new ChunkParser(DSyntax, spanParser, Ide.IdeApp.Workbench.ActiveDocument.Editor.ColorStyle, line);

                var n = chunkP.GetChunks(startOffset, endOffset - startOffset);

                startChunk.Next   = n;
                startChunk.Length = n.Offset - startChunk.Offset;
            }
Ejemplo n.º 5
0
 public CSharpChunkParser(CSharpSyntaxMode csharpSyntaxMode, SpanParser spanParser, ColorScheme style, DocumentLine line) : base(csharpSyntaxMode, spanParser, style, line)
 {
     this.csharpSyntaxMode = csharpSyntaxMode;
     foreach (var tag in CommentTag.SpecialCommentTags)
     {
         tags.Add(tag.Tag);
     }
 }
Ejemplo n.º 6
0
        public virtual IEnumerable <Chunk> GetChunks(ColorScheme style, DocumentLine line, int offset, int length)
        {
            SpanParser  spanParser  = CreateSpanParser(line, null);
            ChunkParser chunkParser = CreateChunkParser(spanParser, style, line);
            Chunk       result      = chunkParser.GetChunks(chunkParser.lineOffset, line.Length);

            if (SemanticRules != null)
            {
                foreach (SemanticRule sematicRule in SemanticRules)
                {
                    sematicRule.Analyze(doc, line, result, offset, offset + length);
                }
            }
            var minOffset = offset;

            if (result != null)
            {
                // crop to begin
                if (result.Offset < offset)
                {
                    while (result != null && result.EndOffset < offset)
                    {
                        result = result.Next;
                    }
                    if (result != null)
                    {
                        int endOffset = result.EndOffset;
                        result.Offset = offset;
                        result.Length = endOffset - offset;
                        minOffset     = result.Offset;
                    }
                }
            }
            while (result != null)
            {
                // crop to end
                if (result.EndOffset >= offset + length)
                {
                    result.Length = offset + length - result.Offset;
                    result.Next   = null;
                    if (result.Length < 0)
                    {
                        result.Length = 0;
                        yield break;
                    }
                }
                while (result.Next != null && result.Offset < minOffset)
                {
                    result = result.Next;
                }
                minOffset = result.Offset + result.Length;
                yield return(result);

                result = result.Next;
            }
        }
Ejemplo n.º 7
0
        public virtual IEnumerable <Chunk> GetChunks(ColorScheme style, DocumentLine line, int offset, int length)
        {
            SpanParser  spanParser  = CreateSpanParser(line, null);
            ChunkParser chunkParser = CreateChunkParser(spanParser, style, line);
            Chunk       result      = chunkParser.GetChunks(chunkParser.lineOffset, line.Length);

            if (SemanticRules != null)
            {
                foreach (SemanticRule sematicRule in SemanticRules)
                {
                    sematicRule.Analyze(doc, line, result, offset, offset + length);
                }
            }
            if (result != null)
            {
                // crop to begin
                if (result.Offset != offset)
                {
                    while (result != null && result.EndOffset < offset)
                    {
                        result = result.Next;
                    }
                    if (result != null)
                    {
                        int endOffset = result.EndOffset;
                        result.Offset = offset;
                        result.Length = endOffset - offset;
                    }
                }

                if (result != null && offset + length != chunkParser.lineOffset + line.Length)
                {
                    // crop to end
                    Chunk cur = result;
                    while (cur != null && cur.EndOffset < offset + length)
                    {
                        cur = cur.Next;
                    }
                    if (cur != null)
                    {
                        cur.Length = offset + length - cur.Offset;
                        cur.Next   = null;
                    }
                }
            }
            while (result != null)
            {
                yield return(result);

                result = result.Next;
            }
        }
Ejemplo n.º 8
0
        public async Task VerifyNoDiagnosticAsync(
            string theory,
            string fromData,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            (TextSpan span, string text) = SpanParser.ReplaceSpan(theory, fromData);

            await VerifyNoDiagnosticAsync(
                source : text,
                additionalSources : null,
                options : options,
                cancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 9
0
        public async Task VerifyDiagnosticAsync(
            string source,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            SpanParserResult result = SpanParser.GetSpans(source);

            await VerifyDiagnosticAsync(
                result.Text,
                result.Spans.Select(f => CreateDiagnostic(f.Span, f.LineSpan)),
                additionalSources : null,
                options : options,
                cancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 10
0
 public ChunkParser(SpanParser spanParser, Document doc, Style style, SyntaxMode mode, LineSegment line)
 {
     this.mode                  = mode;
     this.doc                   = doc;
     this.line                  = line;
     this.spanParser            = spanParser;
     spanParser.FoundSpanBegin += FoundSpanBegin;
     spanParser.FoundSpanEnd   += FoundSpanEnd;
     spanParser.FoundSpanExit  += FoundSpanExit;
     spanParser.ParseChar      += ParseChar;
     if (line == null)
     {
         throw new ArgumentNullException("line");
     }
 }
        public async Task VerifyNoRefactoringAsync(
            string source,
            string equivalenceKey               = null,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            TextSpanParserResult result = SpanParser.GetSpans(source, reverse: true);

            await VerifyNoRefactoringAsync(
                source : result.Text,
                spans : result.Spans.Select(f => f.Span),
                equivalenceKey : equivalenceKey,
                options : options,
                cancellationToken : cancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 12
0
        public override ChunkParser CreateChunkParser(SpanParser spanParser, ColorScheme style, DocumentLine line)
        {
            switch ((SemanticHighlightingEnabled ? 2 : 0) + (DiffbasedHighlighting.Enabled ? 1 : 0))
            {
            case 1:
            case 3:
                return(new DiffbasedChunkParser(this, spanParser, style, line));

            case 2:
                return(new DChunkParser(this, spanParser, style, line));

            default:
                return(base.CreateChunkParser(spanParser, style, line));
            }
        }
Ejemplo n.º 13
0
        public virtual Chunk GetChunks(Document doc, Style style, LineSegment line, int offset, int length)
        {
            SpanParser  spanParser  = CreateSpanParser(doc, this, line, null);
            ChunkParser chunkParser = CreateChunkParser(spanParser, doc, style, this, line);
            Chunk       result      = chunkParser.GetChunks(chunkParser.lineOffset, line.EditableLength);

            if (SemanticRules != null)
            {
                foreach (SemanticRule sematicRule in SemanticRules)
                {
                    sematicRule.Analyze(doc, line, result, offset, offset + length);
                }
            }
            if (result != null)
            {
                // crop to begin
                if (result.Offset != offset)
                {
                    while (result != null && result.EndOffset < offset)
                    {
                        result = result.Next;
                    }
                    if (result != null)
                    {
                        int endOffset = result.EndOffset;
                        result.Offset = offset;
                        result.Length = endOffset - offset;
                    }
                }

                if (result != null && offset + length != chunkParser.lineOffset + line.EditableLength)
                {
                    // crop to end
                    Chunk cur = result;
                    while (cur != null && cur.EndOffset < offset + length)
                    {
                        cur = cur.Next;
                    }
                    if (cur != null)
                    {
                        cur.Length = offset + length - cur.Offset;
                        cur.Next   = null;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 14
0
 public ChunkParser(SyntaxMode mode, SpanParser spanParser, ColorScheme style, DocumentLine line)
 {
     this.mode                 = mode;
     this.doc                  = mode.Document;
     this.line                 = line;
     this.lineOffset           = line.Offset;
     this.spanParser           = spanParser;
     spanParser.FoundSpanBegin = FoundSpanBegin;
     spanParser.FoundSpanEnd   = FoundSpanEnd;
     spanParser.FoundSpanExit  = FoundSpanExit;
     spanParser.ParseChar     += ParseChar;
     if (line == null)
     {
         throw new ArgumentNullException("line");
     }
 }
Ejemplo n.º 15
0
        public async Task VerifyFixAsync(
            string theory,
            string fromData,
            string toData,
            string equivalenceKey               = null,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            (TextSpan span, string source, string expected) = SpanParser.ReplaceSpan(theory, fromData, toData);

            await VerifyFixAsync(
                source : source,
                expected : expected,
                equivalenceKey : equivalenceKey,
                options : options,
                cancellationToken : cancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 16
0
        public async Task VerifyDiagnosticAsync(
            string theory,
            string fromData,
            CodeVerificationOptions options     = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            (TextSpan span, string text) = SpanParser.ReplaceSpan(theory, fromData);

            SpanParserResult result = SpanParser.GetSpans(text);

            if (result.Spans.Any())
            {
                await VerifyDiagnosticAsync(result.Text, result.Spans.Select(f => f.Span), options, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                await VerifyDiagnosticAsync(text, span, options, cancellationToken).ConfigureAwait(false);
            }
        }
Ejemplo n.º 17
0
			public override void Analyze(TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
			{
				// Check line start
				int o = line.Offset;
				char c = '\0';
				for (; o < line.EndOffset && char.IsWhiteSpace(c = doc.GetCharAt(o)); o++) ;

				if (c != '-' && c != '#')
					return;

				DSyntax.Document = doc;
				var spanParser = new SpanParser(DSyntax, new CloneableStack<Span>());
				var chunkP = new ChunkParser(DSyntax, spanParser, Ide.IdeApp.Workbench.ActiveDocument.Editor.ColorStyle, line);

				var n = chunkP.GetChunks(startOffset, endOffset - startOffset);
				if (n == null)
					return;
				startChunk.Next = n;
				startChunk.Length = n.Offset - startChunk.Offset;
			}
Ejemplo n.º 18
0
 public override ChunkParser CreateChunkParser(SpanParser spanParser, ColorScheme style, DocumentLine line)
 {
     switch ((SemanticHighlightingEnabled ? 2 : 0) + (DiffbasedHighlighting.Enabled ? 1 : 0))
     {
         case 1:
         case 3:
             return new DiffbasedChunkParser(this, spanParser, style, line);
         case 2:
             return new DChunkParser(this, spanParser, style, line);
         default:
             return base.CreateChunkParser(spanParser, style, line);
     }
 }
Ejemplo n.º 19
0
			public ChunkParser (SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line)
			{
				this.mode = mode;
				this.doc = doc;
				this.line = line;
				this.lineOffset = line.Offset;
				this.spanParser = spanParser;
				spanParser.FoundSpanBegin = FoundSpanBegin;
				spanParser.FoundSpanEnd = FoundSpanEnd;
				spanParser.FoundSpanExit = FoundSpanExit;
				spanParser.ParseChar += ParseChar;
				if (line == null)
					throw new ArgumentNullException ("line");
			}
Ejemplo n.º 20
0
		public virtual ChunkParser CreateChunkParser (SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line)
		{
			return new ChunkParser (spanParser, doc, style, mode, line);
		}
Ejemplo n.º 21
0
 public override ChunkParser CreateChunkParser(SpanParser spanParser, ColorScheme style, DocumentLine line)
 {
     return(new CSharpChunkParser(this, spanParser, style, line));
 }
Ejemplo n.º 22
0
			public CSharpChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) : base (spanParser, doc, style, mode, line)
			{
				document = IdeApp.Workbench.GetDocument (doc.FileName);
				
				foreach (var tag in ProjectDomService.SpecialCommentTags) {
					tags.Add (tag.Tag);
				}
				
				ICSharpCode.OldNRefactory.Ast.CompilationUnit unit = null;
				if (document != null && document.ParsedDocument != null && MonoDevelop.Core.PropertyService.Get ("EnableSemanticHighlighting", false)) {
					resolver = document.GetResolver ();
					if (!document.ParsedDocument.TryGetTag (out unit)) {
						try {
							using (ICSharpCode.OldNRefactory.IParser parser = ICSharpCode.OldNRefactory.ParserFactory.CreateParser (ICSharpCode.OldNRefactory.SupportedLanguage.CSharp, document.Editor.Document.OpenTextReader ())) {
								parser.Parse ();
								unit = parser.CompilationUnit;
								document.ParsedDocument.SetTag (unit);
							}
						} catch (Exception) {
							resolver = null;
							return;
						}
					}
					resolver.SetupParsedCompilationUnit (unit);
				}
			}
Ejemplo n.º 23
0
		public override ChunkParser CreateChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, ColorSheme style, SyntaxMode mode, LineSegment line)
		{
			return new CSharpChunkParser (spanParser, doc, style, mode, line);
		}
 public override ChunkParser CreateChunkParser(SpanParser spanParser, Mono.TextEditor.Highlighting.ColorScheme style, DocumentLine line)
 {
     return(new CSharpChunkParser(this, spanParser, style, line));
 }
Ejemplo n.º 25
0
		public virtual ChunkParser CreateChunkParser (SpanParser spanParser, ColorScheme style, DocumentLine line)
		{
			return new ChunkParser (this, spanParser, style, line);
		}
Ejemplo n.º 26
0
			public CSharpChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, Style style, SyntaxMode mode, LineSegment line) : base (spanParser, doc, style, mode, line)
			{
				foreach (var tag in ProjectDomService.SpecialCommentTags) {
					tags.Add (tag.Tag);
				}
			}
Ejemplo n.º 27
0
 public DiffbasedChunkParser(DSyntaxMode syn, SpanParser s, ColorScheme st, DocumentLine ln)
     : base(syn, s, st, ln)
 {
 }
Ejemplo n.º 28
0
 public virtual ChunkParser CreateChunkParser(SpanParser spanParser, ColorScheme style, DocumentLine line)
 {
     return(new ChunkParser(this, spanParser, style, line));
 }
Ejemplo n.º 29
0
 public virtual ChunkParser CreateChunkParser(SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line)
 {
     return(new ChunkParser(spanParser, doc, style, mode, line));
 }
Ejemplo n.º 30
0
 public override ChunkParser CreateChunkParser(SpanParser spanParser, Mono.TextEditor.Document doc, Style style, SyntaxMode mode, LineSegment line)
 {
     return(new CSharpChunkParser(spanParser, doc, style, mode, line));
 }
Ejemplo n.º 31
0
			public ChunkParser (SyntaxMode mode, SpanParser spanParser, ColorScheme style, DocumentLine line)
			{
				this.mode = mode;
				this.doc = mode.Document;
				this.line = line;
				this.lineOffset = line.Offset;
				this.spanParser = spanParser;
				spanParser.FoundSpanBegin = FoundSpanBegin;
				spanParser.FoundSpanEnd = FoundSpanEnd;
				spanParser.FoundSpanExit = FoundSpanExit;
				spanParser.ParseChar += ParseChar;
				spanParser.IsAtWordStart = () => wordbuilder.Length == 0;
				if (line == null)
					throw new ArgumentNullException ("line");
			}
 public CSharpChunkParser(SemanticHighlightingSyntaxMode semanticMode, SpanParser spanParser, Mono.TextEditor.Highlighting.ColorScheme style, DocumentLine line) : base(semanticMode, spanParser, style, line)
 {
     this.semanticMode = semanticMode;
 }
Ejemplo n.º 33
0
 public DiffbasedChunkParser(DSyntaxMode syn, SpanParser s, ColorScheme st, DocumentLine ln)
     : base(syn, s, st, ln)
 {
 }