Ejemplo n.º 1
0
        public override bool TryFix(ConstructFixer fixer, SyntaxTree syntaxTree, IDocument document, TextLocation location, ref int newOffset)
        {
            var methodDeclaration = syntaxTree.GetNodeAt <MethodDeclaration>(location);

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

                    var insertionOffset = document.GetOffset(lastNode.EndLocation);
                    document.Insert(insertionOffset, ")\n\t{\t\t\n\t}");
                    newOffset += ")\n\t{\t\t".Length;
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }