public override void WriteKeyword(Role role, string keyword) { TextLocation start = locationProvider.Location; AlTokenNode t = null; if (role is TokenRole) { t = new AlTokenNode(start, (TokenRole)role); } else if (role == EntityDeclaration.ModifierRole) { t = new AlModifierToken(start, AlModifierToken.GetModifierValue(keyword)); } else if (keyword == "self") { ThisReferenceExpression node = nodes.Peek().LastOrDefault() as ThisReferenceExpression; if (node != null) { node.Location = start; } } else if (keyword == "me") { BaseReferenceExpression node = nodes.Peek().LastOrDefault() as BaseReferenceExpression; if (node != null) { node.Location = start; } } if (t != null) { currentList.Add(t); } base.WriteKeyword(role, keyword); }
public void FixSemicolon(AlTokenNode 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 VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration) { FixAttributesAndDocComment(destructorDeclaration); AlTokenNode 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); } }
public override void WriteToken(Role role, string token) { AlTokenNode t = new AlTokenNode(locationProvider.Location, (TokenRole)role); t.Role = role; EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement; if (node == null) { currentList.Add(t); } else { node.Location = locationProvider.Location; } base.WriteToken(role, token); }
static bool ShouldBreakLine(NewLinePlacement placement, AlTokenNode token) { if (placement == NewLinePlacement.NewLine) { return(true); } if (placement == NewLinePlacement.SameLine) { return(false); } if (token.IsNull) { 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); }
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) { AlTokenNode o = other as AlTokenNode; return(o != null && !o.IsNull && !(o is AlModifierToken)); }
void IAstVisitor.VisitAlTokenNode(AlTokenNode token) { Visit(EnterAlTokenNode, LeaveAlTokenNode, token); }
void FixEmbeddedStatment(BraceStyle braceStyle, AlTokenNode 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); } }