Exemplo n.º 1
0
        S IAstVisitor <T, S> .VisitCSharpTokenNode(CSharpTokenNode token, T data)
        {
            var handler = CSharpTokenNodeVisited;

            if (handler != null)
            {
                handler(token, data);
            }
            return(VisitChildren(token, data));
        }
Exemplo n.º 2
0
        static bool ShouldBreakLine(NewLinePlacement placement, CSharpTokenNode token)
        {
            if (placement == NewLinePlacement.NewLine)
            {
                return(true);
            }
            if (placement == NewLinePlacement.SameLine)
            {
                return(false);
            }
            var prevMeaningfulNode = token.GetPrevNode(n => n.Role != Roles.NewLine && n.Role != Roles.Whitespace && n.Role != Roles.Comment);

            return(prevMeaningfulNode.EndLocation.Line != token.StartLocation.Line);
        }
Exemplo n.º 3
0
        public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
        {
            FixAttributes(destructorDeclaration);

            CSharpTokenNode lParen = destructorDeclaration.LParToken;

            ForceSpaceBefore(lParen, policy.SpaceBeforeConstructorDeclarationParentheses);

            if (!destructorDeclaration.Body.IsNull)
            {
                FixOpenBrace(policy.DestructorBraceStyle, destructorDeclaration.Body.LBraceToken);
                VisitBlockWithoutFixingBraces(destructorDeclaration.Body, policy.IndentMethodBody);
                FixClosingBrace(policy.DestructorBraceStyle, destructorDeclaration.Body.RBraceToken);
            }
        }
Exemplo n.º 4
0
        public void FixSemicolon(CSharpTokenNode semicolon)
        {
            if (semicolon.IsNull)
            {
                return;
            }
            int endOffset = document.GetOffset(semicolon.StartLocation);
            int offset    = endOffset;

            while (offset - 1 > 0 && char.IsWhiteSpace(document.GetCharAt(offset - 1)))
            {
                offset--;
            }
            if (offset < endOffset)
            {
                AddChange(offset, endOffset - offset, null);
            }
        }
        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
        {
            CSharpTokenNode o = other as CSharpTokenNode;

            return(o != null && !o.IsNull && !(o is CSharpModifierToken));
        }
Exemplo n.º 6
0
 void IAstVisitor.VisitCSharpTokenNode(CSharpTokenNode token)
 {
     Visit(EnterCSharpTokenNode, LeaveCSharpTokenNode, token);
 }
        void FixEmbeddedStatment(BraceStyle braceStyle, CSharpTokenNode token, bool allowInLine, AstNode node, bool statementAlreadyIndented = false)
        {
            if (node == null)
            {
                return;
            }
            bool isBlock = node is BlockStatement;

            FormattingChanges.TextReplaceAction beginBraceAction = null;
            FormattingChanges.TextReplaceAction endBraceAction   = null;
            BlockStatement closeBlockToBeFixed = null;

            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
                {
                    if (!statementAlreadyIndented)
                    {
                        FixOpenBrace(braceStyle, block.LBraceToken);
                    }
                    closeBlockToBeFixed = block;
                }

                if (braceStyle == BraceStyle.NextLineShifted2)
                {
                    curIndent.Push(IndentType.Block);
                }
            }
            else
            {
                if (allowInLine && token.StartLocation.Line == node.EndLocation.Line)
                {
                    nextStatementIndent = " ";
                }
            }
            bool pushed = false;

            if (policy.IndentBlocks && !(policy.AlignEmbeddedIfStatements && node is IfElseStatement && node.Parent is IfElseStatement || policy.AlignEmbeddedUsingStatements && node is UsingStatement && node.Parent is UsingStatement))
            {
                curIndent.Push(IndentType.Block);
                pushed = true;
            }
            if (isBlock)
            {
                VisitBlockWithoutFixingBraces((BlockStatement)node, false);
            }
            else
            {
                if (!statementAlreadyIndented)
                {
                    FixStatementIndentation(node.StartLocation);
                }
                node.AcceptVisitor(this);
            }
            if (pushed)
            {
                curIndent.Pop();
            }
            if (beginBraceAction != null && endBraceAction != null)
            {
                beginBraceAction.DependsOn = endBraceAction;
                endBraceAction.DependsOn   = beginBraceAction;
            }

            if (isBlock && braceStyle == BraceStyle.NextLineShifted2)
            {
                curIndent.Pop();
            }
            if (closeBlockToBeFixed != null)
            {
                FixClosingBrace(braceStyle, closeBlockToBeFixed.RBraceToken);
            }
        }