Esempio n. 1
0
		static void Test (string input, string expectedOutput)
		{
			input = input.Replace("\r\n", "\n");
			expectedOutput = expectedOutput.Replace("\r\n", "\n");
			int caretPositon = input.IndexOf('$');
			if (caretPositon > 0)
				input = input.Substring(0, caretPositon) + input.Substring(caretPositon + 1);

			var document1 = new StringBuilderDocument(input);

			int expectedCaretPosition = expectedOutput.IndexOf('$');
			if (expectedCaretPosition > 0)
				expectedOutput = expectedOutput.Substring(0, expectedCaretPosition) + expectedOutput.Substring(expectedCaretPosition + 1);

			var fixer = new ConstructFixer(FormattingOptionsFactory.CreateMono (), new TextEditorOptions { EolMarker = "\n" });
			int newCaretPosition;
			Assert.IsTrue(fixer.TryFix(document1, caretPositon, out newCaretPosition));   
			var isEqual = expectedOutput == document1.Text.Replace("\r\n", "\n");
			if (!isEqual) {
				System.Console.WriteLine("expected:");
				System.Console.WriteLine(expectedOutput);
				System.Console.WriteLine("was:");
				System.Console.WriteLine(document1.Text);
			}
			Assert.IsTrue(isEqual); 
			Assert.AreEqual(expectedCaretPosition, newCaretPosition); 
		}
Esempio n. 2
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var stmt = syntaxTree.GetNodeAt <BreakStatement>(location);

            if (stmt != null && stmt.SemicolonToken.IsNull)
            {
                // TODO !!!!
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var stmt = syntaxTree.GetNodeAt <UncheckedExpression>(location);

            if (stmt != null && stmt.Parent is ExpressionStatement)
            {
                var insertionOffset = document.GetOffset(stmt.EndLocation);
                document.Insert(insertionOffset, fixer.GenerateBody(stmt, fixer.Options.StatementBraceStyle, false, ref newOffset));
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var stmt = syntaxTree.GetNodeAt <ThrowStatement>(location);

            if (stmt != null && stmt.SemicolonToken.IsNull)
            {
                var insertionOffset = document.GetOffset(stmt.EndLocation);
                document.Insert(insertionOffset, ";");
                newOffset = insertionOffset + 1;
                return(true);
            }
            return(false);
        }
Esempio n. 5
0
		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var typeDeclaration = syntaxTree.GetNodeAt<DelegateDeclaration>(location); 
			if (typeDeclaration != null) {
				if (typeDeclaration.RParToken.IsNull) {
					var lastNode = GetLastNonErrorChild (typeDeclaration);
					if (lastNode == null)
						return false;
					var insertionOffset = document.GetOffset(lastNode.EndLocation);
					document.Insert(insertionOffset, ");\n");
					newOffset += ");\n".Length;
					return true;
				}
			}
			return false;
		}
Esempio n. 6
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var expressionStatement = syntaxTree.GetNodeAt <ExpressionStatement>(location);

            if (expressionStatement != null)
            {
                int offset = document.GetOffset(expressionStatement.Expression.EndLocation);
                if (expressionStatement.SemicolonToken.IsNull)
                {
                    document.Insert(offset, ";");
                    newOffset = offset + 1;
                }
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var typeDeclaration = syntaxTree.GetNodeAt<TypeDeclaration>(location); 
			if (typeDeclaration != null) {
				if (typeDeclaration.LBraceToken.IsNull && typeDeclaration.RBraceToken.IsNull) {
					if (typeDeclaration.Members.Any())
						return false;
					var lastNode = GetLastNonErrorChild (typeDeclaration);
					if (lastNode == null)
						return false;
					var insertionOffset = document.GetOffset(lastNode.EndLocation);
					document.Insert(insertionOffset, fixer.GenerateBody (typeDeclaration, fixer.Options.ClassBraceStyle, false, ref newOffset));
					return true;
				}
			}
			return false;
		}
Esempio n. 8
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var typeDeclaration = syntaxTree.GetNodeAt <DelegateDeclaration>(location);

            if (typeDeclaration != null)
            {
                if (typeDeclaration.RParToken.IsNull)
                {
                    var lastNode = GetLastNonErrorChild(typeDeclaration);
                    if (lastNode == null)
                    {
                        return(false);
                    }
                    var insertionOffset = document.GetOffset(lastNode.EndLocation);
                    document.Insert(insertionOffset, ");\n");
                    newOffset += ");\n".Length;
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 9
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var stmt = syntaxTree.GetNodeAt <LockStatement>(location);

            if (stmt != null)
            {
                if (!stmt.LParToken.IsNull && stmt.RParToken.IsNull)
                {
                    var lastNode = GetLastNonErrorChild(stmt);
                    if (lastNode == null)
                    {
                        return(false);
                    }

                    var insertionOffset = document.GetOffset(lastNode.EndLocation);
                    document.Insert(insertionOffset, fixer.GenerateBody(stmt, fixer.Options.StatementBraceStyle, true, ref newOffset));
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 10
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var stmt = syntaxTree.GetNodeAt <DoWhileStatement>(location);

            if (stmt != null)
            {
                if (!stmt.LParToken.IsNull && stmt.RParToken.IsNull)
                {
                    var lastNode = GetLastNonErrorChild(stmt);
                    if (lastNode == null)
                    {
                        return(false);
                    }

                    var insertionOffset = document.GetOffset(lastNode.EndLocation);
                    document.Insert(insertionOffset, ");");
                    newOffset = insertionOffset + 2;
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 11
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var invocationExpression = syntaxTree.GetNodeAt <InvocationExpression>(location);

            if (invocationExpression != null)
            {
                if (!invocationExpression.LParToken.IsNull && invocationExpression.RParToken.IsNull)
                {
                    var lastNode = GetLastNonErrorChild(invocationExpression);
                    if (lastNode == null)
                    {
                        return(false);
                    }

                    var insertionOffset = document.GetOffset(lastNode.EndLocation);

                    newOffset = insertionOffset;


                    var text = ")";
                    newOffset++;
                    var expressionStatement = invocationExpression.Parent as ExpressionStatement;
                    if (expressionStatement != null)
                    {
                        if (expressionStatement.SemicolonToken.IsNull)
                        {
                            text = ");";
                        }
                        newOffset++;
                    }
                    document.Insert(insertionOffset, text);


                    return(true);
                }
            }
            return(false);
        }
Esempio n. 12
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var typeDeclaration = syntaxTree.GetNodeAt <TypeDeclaration>(location);

            if (typeDeclaration != null)
            {
                if (typeDeclaration.LBraceToken.IsNull && typeDeclaration.RBraceToken.IsNull)
                {
                    if (typeDeclaration.Members.Any())
                    {
                        return(false);
                    }
                    var lastNode = GetLastNonErrorChild(typeDeclaration);
                    if (lastNode == null)
                    {
                        return(false);
                    }
                    var insertionOffset = document.GetOffset(lastNode.EndLocation);
                    document.Insert(insertionOffset, fixer.GenerateBody(typeDeclaration, fixer.Options.ClassBraceStyle, false, ref newOffset));
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 13
0
		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var stmt = syntaxTree.GetNodeAt<ThrowStatement>(location); 

			if (stmt != null && stmt.SemicolonToken.IsNull) {
				var insertionOffset = document.GetOffset(stmt.EndLocation);
				document.Insert(insertionOffset, ";");
				newOffset = insertionOffset + 1;
				return true;
			}
			return false;
		}
Esempio n. 14
0
		public abstract bool TryFix (ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset);
Esempio n. 15
0
		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var stmt = syntaxTree.GetNodeAt<LockStatement>(location); 
			if (stmt != null) {
				if (!stmt.LParToken.IsNull && stmt.RParToken.IsNull) {
					var lastNode = GetLastNonErrorChild (stmt);
					if (lastNode == null)
						return false;

					var insertionOffset = document.GetOffset(lastNode.EndLocation);
					document.Insert(insertionOffset, fixer.GenerateBody (stmt, fixer.Options.StatementBraceStyle, true, ref newOffset));
					return true;
				}
			}
			return false;
		}
Esempio n. 16
0
		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var expressionStatement = syntaxTree.GetNodeAt<ExpressionStatement>(location); 

			if (expressionStatement != null) {
				int offset = document.GetOffset(expressionStatement.Expression.EndLocation);
				if (expressionStatement.SemicolonToken.IsNull) {
					document.Insert(offset, ";");
					newOffset = offset + 1;
				}
				return true;
			}
			return false;
		}
Esempio n. 17
0
		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var stmt = syntaxTree.GetNodeAt<UncheckedExpression>(location); 

			if (stmt != null && stmt.Parent is ExpressionStatement) {
				var insertionOffset = document.GetOffset(stmt.EndLocation);
				document.Insert(insertionOffset, fixer.GenerateBody (stmt, fixer.Options.StatementBraceStyle, false, ref newOffset));
				return true;
			}
			return false;
		}
Esempio n. 18
0
		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var stmt = syntaxTree.GetNodeAt<BreakStatement>(location); 

			if (stmt != null && stmt.SemicolonToken.IsNull) {
				// TODO !!!!
				return true;
			}
			return false;
		}
Esempio n. 19
0
		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var invocationExpression = syntaxTree.GetNodeAt<InvocationExpression>(location); 

			if (invocationExpression != null) {
				if (!invocationExpression.LParToken.IsNull && invocationExpression.RParToken.IsNull) {
					var lastNode = GetLastNonErrorChild (invocationExpression);
					if (lastNode == null)
						return false;

					var insertionOffset = document.GetOffset(lastNode.EndLocation);

					newOffset = insertionOffset;


					var text = ")";
					newOffset++;
					var expressionStatement = invocationExpression.Parent as ExpressionStatement;
					if (expressionStatement != null) {
						if (expressionStatement.SemicolonToken.IsNull)
							text = ");";
						newOffset ++;
					}
					document.Insert(insertionOffset, text);


					return true;
				}

			}
			return false;
		}
Esempio n. 20
0
		public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
		{
			var stmt = syntaxTree.GetNodeAt<DoWhileStatement>(location); 
			if (stmt != null) {
				if (!stmt.LParToken.IsNull && stmt.RParToken.IsNull) {
					var lastNode = GetLastNonErrorChild (stmt);
					if (lastNode == null)
						return false;

					var insertionOffset = document.GetOffset(lastNode.EndLocation);
					document.Insert(insertionOffset, ");");
					newOffset = insertionOffset + 2;
					return true;
				}
			}
			return false;
		}
Esempio n. 21
0
 public abstract bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset);