Exemplo n.º 1
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 (policy.SpaceBeforeSemicolon)
            {
                AddChange(offset, endOffset - offset, " ");
            }
            else
            {
                if (offset < endOffset)
                {
                    AddChange(offset, endOffset - offset, null);
                }
            }
        }
        public override void WriteKeyword(Role role, string keyword)
        {
            TextLocation    start = locationProvider.Location;
            CSharpTokenNode t     = null;

            if (role is TokenRole)
            {
                t = new CSharpTokenNode(start, (TokenRole)role);
            }
            else if (role == EntityDeclaration.ModifierRole)
            {
                t = new CSharpModifierToken(start, CSharpModifierToken.GetModifierValue(keyword));
            }
            else if (keyword == "this")
            {
                ThisReferenceExpression node = nodes.Peek().LastOrDefault() as ThisReferenceExpression;
                if (node != null)
                {
                    node.Location = start;
                }
            }
            else if (keyword == "base")
            {
                BaseReferenceExpression node = nodes.Peek().LastOrDefault() as BaseReferenceExpression;
                if (node != null)
                {
                    node.Location = start;
                }
            }
            if (t != null)
            {
                currentList.Add(t);
            }
            base.WriteKeyword(role, keyword);
        }
Exemplo n.º 3
0
        public override void WriteToken(Role role, string token)
        {
            CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role);

            t.Role = role;
            if (!(nodes.Peek().LastOrDefault() is EmptyStatement node))
            {
                currentList.Add(t);
            }
Exemplo n.º 4
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.º 5
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);
        }
        public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
        {
            FixAttributesAndDocComment(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.º 7
0
        public override void WriteToken(Role role, string token)
        {
            CSharpTokenNode t    = new CSharpTokenNode(locationProvider.Location, (TokenRole)role);
            EmptyStatement  node = nodes.Peek().LastOrDefault() as EmptyStatement;

            if (node == null)
            {
                currentList.Add(t);
            }
            else
            {
                node.Location = locationProvider.Location;
            }
            base.WriteToken(role, token);
        }
Exemplo n.º 8
0
 void IAstVisitor.VisitCSharpTokenNode(CSharpTokenNode token)
 {
     Visit(EnterCSharpTokenNode, LeaveCSharpTokenNode, token);
 }
Exemplo n.º 9
0
 public virtual S VisitCSharpTokenNode(CSharpTokenNode token, T data)
 {
     return(VisitChildren(token, data));
 }
Exemplo n.º 10
0
        private 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.AlignEmbeddedStatements && node is IfElseStatement && node.Parent is IfElseStatement ||
                    policy.AlignEmbeddedStatements && node is UsingStatement && node.Parent is UsingStatement ||
                    policy.AlignEmbeddedStatements && node is LockStatement && node.Parent is LockStatement))
            {
                curIndent.Push(IndentType.Block);
                pushed = true;
            }
            if (isBlock)
            {
                VisitBlockWithoutFixingBraces((BlockStatement)node, false);
            }
            else
            {
                if (!statementAlreadyIndented)
                {
                    PlaceOnNewLine(policy.EmbeddedStatementPlacement, node);
                    nextStatementIndent = null;
                }
                node.AcceptVisitor(this);
            }
            nextStatementIndent = null;
            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);
            }
        }
Exemplo n.º 11
0
        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
        {
            CSharpTokenNode o = other as CSharpTokenNode;

            return(o != null && !o.IsNull && !(o is CSharpModifierToken));
        }
 public virtual S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, T data)
 {
     throw new NotImplementedException();
 }