protected S VisitChildren(ICSharpNode node, T data)
        {
            ICSharpNode child = node.FirstChild as ICSharpNode;

            while (child != null)
            {
                child.AcceptVisitor(this, data);
                child = child.NextSibling as ICSharpNode;
            }
            return(default(S));
        }
Exemplo n.º 2
0
        object FixEmbeddedStatment(MonoDevelop.CSharp.Formatting.BraceStyle braceStyle, MonoDevelop.CSharp.Formatting.BraceForcement braceForcement, CSharpTokenNode token, bool allowInLine, ICSharpNode node)
        {
            if (node == null)
            {
                return(null);
            }
            bool isBlock = node is BlockStatement;

            switch (braceForcement)
            {
            case BraceForcement.DoNotChange:
                //nothing
                break;

            case BraceForcement.AddBraces:
                if (!isBlock)
                {
                    int    offset     = data.Document.LocationToOffset(node.StartLocation.Line, node.StartLocation.Column);
                    int    start      = SearchWhitespaceStart(offset);
                    string startBrace = "";
                    switch (braceStyle)
                    {
                    case BraceStyle.EndOfLineWithoutSpace:
                        startBrace = "{";
                        break;

                    case BraceStyle.EndOfLine:
                        startBrace = " {";
                        break;

                    case BraceStyle.NextLine:
                        startBrace = data.EolMarker + curIndent.IndentString + "{";
                        break;

                    case BraceStyle.NextLineShifted2:
                    case BraceStyle.NextLineShifted:
                        startBrace = data.EolMarker + curIndent.IndentString + curIndent.SingleIndent + "{";
                        break;
                    }
                    AddChange(start, offset - start, startBrace);
                }
                break;

            case BraceForcement.RemoveBraces:
                if (isBlock)
                {
                    BlockStatement block = node as BlockStatement;
                    if (block.Statements.Count() == 1)
                    {
                        int offset1 = data.Document.LocationToOffset(node.StartLocation.Line, node.StartLocation.Column);
                        int start   = SearchWhitespaceStart(offset1);

                        int offset2 = data.Document.LocationToOffset(node.EndLocation.Line, node.EndLocation.Column);
                        int end     = SearchWhitespaceStart(offset2 - 1);

                        AddChange(start, offset1 - start + 1, null);
                        AddChange(end + 1, offset2 - end, null);
                        node    = (ICSharpNode)block.FirstChild;
                        isBlock = false;
                    }
                }
                break;
            }
            int originalLevel = curIndent.Level;

            if (isBlock)
            {
                BlockStatement block = node as BlockStatement;
                if (allowInLine && block.StartLocation.Line == block.EndLocation.Line && block.Statements.Count() <= 1)
                {
                    if (block.Statements.Count() == 1)
                    {
                        nextStatementIndent = " ";
                    }
                }
                else
                {
                    EnforceBraceStyle(braceStyle, block.LBrace, block.RBrace);
                }
                if (braceStyle == BraceStyle.NextLineShifted2)
                {
                    curIndent.Level++;
                }
            }
            else
            {
                if (allowInLine && token.StartLocation.Line == node.EndLocation.Line)
                {
                    nextStatementIndent = " ";
                }
            }
            if (!(node is IfElseStatement && node.Parent is IfElseStatement || node is UsingStatement && node.Parent is UsingStatement))
            {
                curIndent.Level++;
            }
            object result = isBlock ? base.VisitBlockStatement((BlockStatement)node, null) : node.AcceptVisitor(this, null);

            curIndent.Level = originalLevel;
            switch (braceForcement)
            {
            case BraceForcement.DoNotChange:
                break;

            case BraceForcement.AddBraces:
                if (!isBlock)
                {
                    int    offset     = data.Document.LocationToOffset(node.EndLocation.Line, node.EndLocation.Column);
                    string startBrace = "";
                    switch (braceStyle)
                    {
                    case BraceStyle.DoNotChange:
                        startBrace = null;
                        break;

                    case BraceStyle.EndOfLineWithoutSpace:
                        startBrace = data.EolMarker + curIndent.IndentString + "}";
                        break;

                    case BraceStyle.EndOfLine:
                        startBrace = data.EolMarker + curIndent.IndentString + "}";
                        break;

                    case BraceStyle.NextLine:
                        startBrace = data.EolMarker + curIndent.IndentString + "}";
                        break;

                    case BraceStyle.NextLineShifted2:
                    case BraceStyle.NextLineShifted:
                        startBrace = data.EolMarker + curIndent.IndentString + curIndent.SingleIndent + "}";
                        break;
                    }
                    if (startBrace != null)
                    {
                        AddChange(offset, 0, startBrace);
                    }
                }
                break;
            }
            return(result);
        }