void FixClosingBrace(BraceStyle braceStyle, AstNode rbrace) { if (rbrace.IsNull) { return; } switch (braceStyle) { case BraceStyle.DoNotChange: return; case BraceStyle.NextLineShifted: case BraceStyle.BannerStyle: curIndent.Push(IndentType.Block); CorrectClosingBrace(rbrace); curIndent.Pop(); break; case BraceStyle.EndOfLineWithoutSpace: case BraceStyle.EndOfLine: case BraceStyle.NextLine: CorrectClosingBrace(rbrace); break; case BraceStyle.NextLineShifted2: curIndent.Push(IndentType.Block); CorrectClosingBrace(rbrace); curIndent.Pop(); break; } }
public void CloseBrace(BraceStyle style) { switch (style) { case BraceStyle.DoNotChange: case BraceStyle.EndOfLine: case BraceStyle.EndOfLineWithoutSpace: case BraceStyle.NextLine: Unindent(); WriteIndentation(); textWriter.Write('}'); break; case BraceStyle.NextLineShifted: WriteIndentation(); textWriter.Write('}'); Unindent(); break; case BraceStyle.NextLineShifted2: Unindent(); WriteIndentation(); textWriter.Write('}'); Unindent(); break; default: throw new ArgumentOutOfRangeException (); } }
public void CloseBrace(BraceStyle style) { Unindent(); WriteIndentation(); Write("}"); }
public void CloseBrace(BraceStyle style) { switch (style) { case BraceStyle.DoNotChange: case BraceStyle.EndOfLine: case BraceStyle.EndOfLineWithoutSpace: case BraceStyle.NextLine: Unindent(); WriteIndentation(); textWriter.Write('}'); isAtStartOfLine = false; break; case BraceStyle.BannerStyle: case BraceStyle.NextLineShifted: WriteIndentation(); textWriter.Write('}'); isAtStartOfLine = false; Unindent(); break; case BraceStyle.NextLineShifted2: Unindent(); WriteIndentation(); textWriter.Write('}'); isAtStartOfLine = false; Unindent(); break; default: throw new ArgumentOutOfRangeException(); } }
public virtual void OpenBrace(BraceStyle style) { if (!_startOfLine) { switch (style) { case BraceStyle.EndOfLineNoSpacing: break; case BraceStyle.EndOfLine: WriteSpace(); break; case BraceStyle.NextLine: WriteLine(); break; case BraceStyle.NextLineIndented: WriteLine(); Indent(); break; } } Output.Write('{'); Indent(); WriteLine(); }
void AppendBraceEnd(StringBuilder result, BraceStyle braceStyle) { switch (braceStyle) { case BraceStyle.EndOfLineWithoutSpace: case BraceStyle.NextLine: case BraceStyle.EndOfLine: IndentLevel--; AppendIndent(result); result.Append("}"); break; case BraceStyle.NextLineShifted: AppendIndent(result); result.Append("}"); IndentLevel--; break; case BraceStyle.NextLineShifted2: IndentLevel--; AppendIndent(result); result.Append("}"); IndentLevel--; break; default: goto case BraceStyle.NextLine; } }
public void EndBrace() { BraceStyle style = (BraceStyle)braceStack.Pop(); switch (style) { case BraceStyle.EndOfLine: case BraceStyle.NextLine: --IndentationLevel; Indent(); PrintToken(Tokens.CloseCurlyBrace); NewLine(); break; case BraceStyle.NextLineShifted: Indent(); PrintToken(Tokens.CloseCurlyBrace); NewLine(); --IndentationLevel; break; case BraceStyle.NextLineShifted2: --IndentationLevel; Indent(); PrintToken(Tokens.CloseCurlyBrace); NewLine(); --IndentationLevel; break; } }
internal string GenerateBody(AstNode node, BraceStyle braceStyle, bool addClosingBracket, ref int newOffset) { StringBuilder result = new StringBuilder(); if (addClosingBracket) { result.Append(")"); } var nodeIndent = GetIndent(node.Parent); switch (braceStyle) { case BraceStyle.DoNotChange: case BraceStyle.BannerStyle: case BraceStyle.EndOfLine: result.Append(" "); result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); break; case BraceStyle.EndOfLineWithoutSpace: result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); break; case BraceStyle.NextLine: result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent); result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); break; case BraceStyle.NextLineShifted: result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); break; case BraceStyle.NextLineShifted2: result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t" + "\t"); break; } newOffset += result.Length; result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent); result.Append("}"); return(result.ToString()); }
public void OpenBrace(BraceStyle style) { WriteIndentation(); sb.Append(' '); sb.Append('{'); Indent(); NewLine(); }
public ConcreteSyntaxTree NewBlock(string header = "", string footer = "", BraceStyle open = BraceStyle.Space, BraceStyle close = BraceStyle.Newline) { Contract.Requires(header != null); Append(ConcreteSyntaxTreeUtils.Block(out ConcreteSyntaxTree result, header, footer, open, close)); return(result); }
public void OpenBrace(BraceStyle style) { WriteIndentation(); textWriter.Write(' '); textWriter.Write('{'); Indent(); NewLine(); }
public void CloseBrace(BraceStyle style) { output.Unindent(); output.Write('}'); if (nodeStack.OfType<BlockStatement>().Count() <= 1) output.MarkFoldEnd(); if (braceLevelWithinType >= 0) braceLevelWithinType--; }
public void CloseBrace(BraceStyle style, out TextPosition?start, out TextPosition?end) { output.Unindent(); start = output.Location; output.WriteRightBrace(); end = output.Location; if (braceLevelWithinType >= 0) { braceLevelWithinType--; } }
public void OpenBrace(BraceStyle style) { if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration) braceLevelWithinType++; if (nodeStack.OfType<BlockStatement>().Count() <= 1) { output.MarkFoldStart(defaultCollapsed: braceLevelWithinType == 1); } output.WriteLine(); output.WriteLine("{"); output.Indent(); }
public void CloseBrace(BraceStyle style, out TextLocation? start, out TextLocation? end) { output.Unindent(); start = output.Location; output.WriteRightBrace(); end = output.Location; if (nodeStack.OfType<BlockStatement>().Count() <= 1) output.MarkFoldEnd(); if (braceLevelWithinType >= 0) braceLevelWithinType--; }
public void CloseBrace(BraceStyle style) { output.Unindent(); output.Write('}'); if (nodeStack.OfType <BlockStatement>().Count() <= 1 || FoldBraces) { output.MarkFoldEnd(); } if (braceLevelWithinType >= 0) { braceLevelWithinType--; } }
public void OpenBrace(BraceStyle style, out TextPosition?start, out TextPosition?end) { if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration) { braceLevelWithinType++; } output.WriteLine(); start = output.Location; output.WriteLeftBrace(); end = output.Location; output.WriteLine(); output.Indent(); }
/// <summary> /// Opens the brace. /// </summary> /// <param name="style">The style.</param> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public void OpenBrace(BraceStyle style) { switch (style) { case BraceStyle.DoNotChange: case BraceStyle.EndOfLine: case BraceStyle.BannerStyle: WriteIndentation(); if (!isAtStartOfLine) { textWriter.Write(' '); } textWriter.Write('{'); break; case BraceStyle.EndOfLineWithoutSpace: WriteIndentation(); textWriter.Write('{'); break; case BraceStyle.NextLine: if (!isAtStartOfLine) { NewLine(); } WriteIndentation(); textWriter.Write('{'); break; case BraceStyle.NextLineShifted: NewLine(); Indent(); WriteIndentation(); textWriter.Write('{'); NewLine(); return; case BraceStyle.NextLineShifted2: NewLine(); Indent(); WriteIndentation(); textWriter.Write('{'); break; default: throw new ArgumentOutOfRangeException(); } Indent(); NewLine(); }
public void OpenBrace(BraceStyle style) { if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration) { braceLevelWithinType++; } if (nodeStack.OfType <BlockStatement>().Count() <= 1 || FoldBraces) { output.MarkFoldStart(defaultCollapsed: braceLevelWithinType == 1); } output.WriteLine(); output.WriteLine("{"); output.Indent(); }
public void OpenBrace(BraceStyle style) { if (!_firstBrace) NewLine(); else _firstBrace = false; WriteIndentation(); Write("{"); Indent(); NewLine(); }
public void EndBrace(bool indent, bool emitNewLine) { BraceStyle style = (BraceStyle)braceStack.Pop(); switch (style) { case BraceStyle.EndOfLine: case BraceStyle.EndOfLineWithoutSpace: case BraceStyle.NextLine: if (indent) { --IndentationLevel; } Indent(); PrintToken(Tokens.CloseCurlyBrace); if (emitNewLine) { NewLine(); } break; case BraceStyle.NextLineShifted: Indent(); PrintToken(Tokens.CloseCurlyBrace); if (emitNewLine) { NewLine(); } if (indent) { --IndentationLevel; } break; case BraceStyle.NextLineShifted2: if (indent) { --IndentationLevel; } Indent(); PrintToken(Tokens.CloseCurlyBrace); if (emitNewLine) { NewLine(); } --IndentationLevel; break; } }
public void CloseBrace(BraceStyle style, out TextLocation?start, out TextLocation?end) { output.Unindent(); start = output.Location; output.WriteRightBrace(); end = output.Location; if (nodeStack.OfType <BlockStatement>().Count() <= 1) { output.MarkFoldEnd(); } if (braceLevelWithinType >= 0) { braceLevelWithinType--; } }
public void OpenBrace(BraceStyle style, out TextLocation?start, out TextLocation?end) { if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration) { braceLevelWithinType++; } if (nodeStack.OfType <BlockStatement>().Count() <= 1) { output.MarkFoldStart(defaultCollapsed: braceLevelWithinType == 1); } output.WriteLine(); start = output.Location; output.WriteLeftBrace(); end = output.Location; output.WriteLine(); output.Indent(); }
public void BeginBrace(BraceStyle style, bool indent) { switch (style) { case BraceStyle.EndOfLine: if (!LastCharacterIsWhiteSpace) { Space(); } PrintToken(Tokens.OpenCurlyBrace); NewLine(); if (indent) ++IndentationLevel; break; case BraceStyle.EndOfLineWithoutSpace: PrintToken(Tokens.OpenCurlyBrace); NewLine(); if (indent) ++IndentationLevel; break; case BraceStyle.NextLine: NewLine(); Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); if (indent) ++IndentationLevel; break; case BraceStyle.NextLineShifted: NewLine(); if (indent) ++IndentationLevel; Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); break; case BraceStyle.NextLineShifted2: NewLine(); if (indent) ++IndentationLevel; Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); ++IndentationLevel; break; } braceStack.Push(style); }
void AddIndentation(BraceStyle braceStyle) { switch (braceStyle) { case BraceStyle.DoNotChange: case BraceStyle.EndOfLine: case BraceStyle.EndOfLineWithoutSpace: case BraceStyle.NextLine: case BraceStyle.NextLineShifted: case BraceStyle.BannerStyle: indentDelta.Push(IndentType.Block); break; case BraceStyle.NextLineShifted2: indentDelta.Push(IndentType.DoubleBlock); break; } }
void AppendBraceStart(StringBuilder result, BraceStyle braceStyle) { switch (braceStyle) { case BraceStyle.BannerStyle: case BraceStyle.EndOfLine: result.Append(" {"); AppendLine(result); break; case BraceStyle.EndOfLineWithoutSpace: result.Append("{"); AppendLine(result); break; case BraceStyle.NextLine: AppendLine(result); AppendIndent(result); result.Append("{"); AppendLine(result); break; case BraceStyle.NextLineShifted: AppendLine(result); result.Append(GetIndent(IndentLevel + 1)); result.Append("{"); AppendLine(result); break; case BraceStyle.NextLineShifted2: AppendLine(result); result.Append(GetIndent(IndentLevel + 1)); result.Append("{"); AppendLine(result); IndentLevel++; break; default: goto case BraceStyle.NextLine; } IndentLevel++; }
public void OpenBrace(BraceStyle style) { switch (style) { case BraceStyle.DoNotChange: case BraceStyle.EndOfLine: case BraceStyle.BannerStyle: WriteIndentation(); if (!isAtStartOfLine) textWriter.Write(' '); textWriter.Write('{'); break; case BraceStyle.EndOfLineWithoutSpace: WriteIndentation(); textWriter.Write('{'); break; case BraceStyle.NextLine: if (!isAtStartOfLine) NewLine(); WriteIndentation(); textWriter.Write('{'); break; case BraceStyle.NextLineShifted: NewLine (); Indent(); WriteIndentation(); textWriter.Write('{'); NewLine(); return; case BraceStyle.NextLineShifted2: NewLine (); Indent(); WriteIndentation(); textWriter.Write('{'); break; default: throw new ArgumentOutOfRangeException (); } Indent(); NewLine(); }
public void BeginBrace(BraceStyle style) { switch (style) { case BraceStyle.EndOfLine: if (!LastCharacterIsWhiteSpace) { Space(); } PrintToken(Tokens.OpenCurlyBrace); NewLine(); ++IndentationLevel; break; case BraceStyle.NextLine: NewLine(); Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); ++IndentationLevel; break; case BraceStyle.NextLineShifted: NewLine(); ++IndentationLevel; Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); break; case BraceStyle.NextLineShifted2: NewLine(); ++IndentationLevel; Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); ++IndentationLevel; break; } _braceStack.Push(style); }
public virtual void CloseBrace(BraceStyle style) { Unindent(); if (!_startOfLine) { switch (style) { case BraceStyle.EndOfLine: WriteSpace(); break; case BraceStyle.NextLine: WriteLine(); break; } } Output.Write('}'); _startOfLine = false; }
public ConcreteSyntaxTree NewBlock(string header, string /*?*/ footer = null, BraceStyle open = BraceStyle.Space, BraceStyle close = BraceStyle.Newline) { Contract.Requires(header != null); Write(header); switch (open) { case BraceStyle.Space: Write(" "); break; case BraceStyle.Newline: WriteLine(); break; } WriteLine("{"); var result = Fork(1); Write("}"); if (footer != null) { Write(footer); } switch (close) { case BraceStyle.Space: Write(" "); break; case BraceStyle.Newline: WriteLine(); break; } return(result); }
public static ConcreteSyntaxTree Block(out ConcreteSyntaxTree body, string header = "", string footer = "", BraceStyle open = BraceStyle.Space, BraceStyle close = BraceStyle.Newline) { var outer = new ConcreteSyntaxTree(); outer.Write(header); switch (open) { case BraceStyle.Space: outer.Write(" "); break; case BraceStyle.Newline: outer.WriteLine(); break; } outer.WriteLine("{"); body = outer.Fork(1); outer.Write("}"); if (footer != "") { outer.Write(footer); } switch (close) { case BraceStyle.Space: outer.Write(" "); break; case BraceStyle.Newline: outer.WriteLine(); break; } return(outer); }
void FixEmbeddedStatment(BraceStyle braceStyle, BraceForcement braceForcement, CSharpTokenNode token, bool allowInLine, AstNode node, bool statementAlreadyIndented = false) { if (node == null) { return; } bool isBlock = node is BlockStatement; TextReplaceAction beginBraceAction = null; TextReplaceAction endBraceAction = null; switch (braceForcement) { case BraceForcement.DoNotChange: //nothing break; case BraceForcement.AddBraces: if (!isBlock) { AstNode n = node.Parent.GetCSharpNodeBefore(node); int start = document.GetOffset(n.EndLocation); string startBrace = ""; switch (braceStyle) { case BraceStyle.EndOfLineWithoutSpace: startBrace = "{"; break; case BraceStyle.BannerStyle: case BraceStyle.EndOfLine: startBrace = " {"; break; case BraceStyle.NextLine: startBrace = this.options.EolMarker + curIndent.IndentString + "{"; break; case BraceStyle.NextLineShifted2: case BraceStyle.NextLineShifted: curIndent.Push(IndentType.Block); startBrace = this.options.EolMarker + curIndent.IndentString + "{"; curIndent.Pop(); break; } beginBraceAction = AddChange(start, 0, startBrace); } break; case BraceForcement.RemoveBraces: if (isBlock) { BlockStatement block = node as BlockStatement; if (block.Statements.Count() == 1) { int offset1 = document.GetOffset(node.StartLocation); int start = SearchWhitespaceStart(offset1); int offset2 = document.GetOffset(node.EndLocation); int end = SearchWhitespaceStart(offset2 - 1); beginBraceAction = AddChange(start, offset1 - start + 1, null); endBraceAction = AddChange(end + 1, offset2 - end, null); node = block.FirstChild; isBlock = false; } } break; } 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) { EnforceBraceStyle(braceStyle, block.LBraceToken, block.RBraceToken); } } if (braceStyle == BraceStyle.NextLineShifted2) { curIndent.Push(IndentType.Block); } } else { if (allowInLine && token.StartLocation.Line == node.EndLocation.Line) { nextStatementIndent = " "; } } 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); } if (isBlock) { VisitBlockWithoutFixingBraces((BlockStatement)node, false); } else { if (!statementAlreadyIndented) { FixStatementIndentation(node.StartLocation); } node.AcceptVisitor(this); } if (policy.IndentBlocks && !(policy.AlignEmbeddedIfStatements && node is IfElseStatement && node.Parent is IfElseStatement || policy.AlignEmbeddedUsingStatements && node is UsingStatement && node.Parent is UsingStatement)) { curIndent.Pop(); } switch (braceForcement) { case BraceForcement.DoNotChange: break; case BraceForcement.AddBraces: if (!isBlock) { int offset = document.GetOffset(node.EndLocation); if (!char.IsWhiteSpace(document.GetCharAt(offset))) { offset++; } string startBrace = ""; switch (braceStyle) { case BraceStyle.DoNotChange: startBrace = null; break; case BraceStyle.EndOfLineWithoutSpace: startBrace = this.options.EolMarker + curIndent.IndentString + "}"; break; case BraceStyle.EndOfLine: startBrace = this.options.EolMarker + curIndent.IndentString + "}"; break; case BraceStyle.NextLine: startBrace = this.options.EolMarker + curIndent.IndentString + "}"; break; case BraceStyle.BannerStyle: case BraceStyle.NextLineShifted2: case BraceStyle.NextLineShifted: curIndent.Push(IndentType.Block); startBrace = this.options.EolMarker + curIndent.IndentString + "}"; curIndent.Pop (); break; } if (startBrace != null) { endBraceAction = AddChange(offset, 0, startBrace); } } break; } if (beginBraceAction != null && endBraceAction != null) { beginBraceAction.DependsOn = endBraceAction; endBraceAction.DependsOn = beginBraceAction; } }
void AppendBraceEnd (StringBuilder result, BraceStyle braceStyle) { switch (braceStyle) { case BraceStyle.EndOfLineWithoutSpace: case BraceStyle.NextLine: case BraceStyle.EndOfLine: IndentLevel --; AppendIndent (result); result.Append ("}"); break; case BraceStyle.BannerStyle: case BraceStyle.NextLineShifted: AppendIndent (result); result.Append ("}"); IndentLevel--; break; case BraceStyle.NextLineShifted2: IndentLevel--; AppendIndent (result); result.Append ("}"); IndentLevel--; break; default: goto case BraceStyle.NextLine; } }
void CloseBrace(BraceStyle style) { WriteSpecialsUpToRole(Roles.RBrace); formatter.CloseBrace(style); lastWritten = LastWritten.Other; }
public void BeginBrace(BraceStyle style, bool indent) { switch (style) { case BraceStyle.EndOfLine: if (!LastCharacterIsWhiteSpace) { Space(); } PrintToken(Tokens.OpenCurlyBrace); NewLine(); if (indent) { ++IndentationLevel; } break; case BraceStyle.EndOfLineWithoutSpace: PrintToken(Tokens.OpenCurlyBrace); NewLine(); if (indent) { ++IndentationLevel; } break; case BraceStyle.NextLine: if (!OnlyWhitespacesOrTabsAfterLastNewLine) { NewLine(); Indent(); } PrintToken(Tokens.OpenCurlyBrace); NewLine(); if (indent) { ++IndentationLevel; } break; case BraceStyle.NextLineShifted: NewLine(); if (indent) { ++IndentationLevel; } Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); break; case BraceStyle.NextLineShifted2: NewLine(); if (indent) { ++IndentationLevel; } Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); ++IndentationLevel; break; } braceStack.Push(style); }
void FixOpenBrace(BraceStyle braceStyle, AstNode lbrace) { if (lbrace.IsNull) { return; } switch (braceStyle) { case BraceStyle.DoNotChange: return; case BraceStyle.BannerStyle: case BraceStyle.EndOfLine: var prev = lbrace.GetPrevNode(); while (prev is NewLineNode) { prev = prev.GetPrevNode(); } if (prev is PreProcessorDirective) { return; } int prevOffset = document.GetOffset(prev.EndLocation); if (prev is Comment || prev is PreProcessorDirective) { int next = document.GetOffset(lbrace.GetNextNode().StartLocation); AddChange(prevOffset, next - prevOffset, ""); while (prev is Comment || prev is PreProcessorDirective) { prev = prev.GetPrevNode(); } prevOffset = document.GetOffset(prev.EndLocation); AddChange(prevOffset, 0, " {"); } else { int braceOffset2 = document.GetOffset(lbrace.StartLocation); AddChange(prevOffset, braceOffset2 - prevOffset, " "); } break; case BraceStyle.EndOfLineWithoutSpace: prev = lbrace.GetPrevNode(); while (prev is NewLineNode) { prev = prev.GetPrevNode(); } if (prev is PreProcessorDirective) { return; } prevOffset = document.GetOffset(prev.EndLocation); int braceOffset = document.GetOffset(lbrace.StartLocation); AddChange(prevOffset, braceOffset - prevOffset, ""); break; case BraceStyle.NextLine: prev = lbrace.GetPrevNode(); while (prev is NewLineNode) { prev = prev.GetPrevNode(); } if (prev is PreProcessorDirective) { return; } prevOffset = document.GetOffset(prev.EndLocation); braceOffset = document.GetOffset(lbrace.StartLocation); AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString); break; case BraceStyle.NextLineShifted: prev = lbrace.GetPrevNode(); while (prev is NewLineNode) { prev = prev.GetPrevNode(); } if (prev is PreProcessorDirective) { return; } prevOffset = document.GetOffset(prev.EndLocation); braceOffset = document.GetOffset(lbrace.StartLocation); curIndent.Push(IndentType.Block); AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString); curIndent.Pop(); break; case BraceStyle.NextLineShifted2: prev = lbrace.GetPrevNode(); while (prev is NewLineNode) { prev = prev.GetPrevNode(); } if (prev is PreProcessorDirective) { return; } prevOffset = document.GetOffset(prev.EndLocation); braceOffset = document.GetOffset(lbrace.StartLocation); curIndent.Push(IndentType.Block); AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString); curIndent.Pop(); break; } }
void FixClosingBrace(BraceStyle braceStyle, AstNode rbrace) { if (rbrace.IsNull) return; switch (braceStyle) { case BraceStyle.DoNotChange: return; case BraceStyle.NextLineShifted: case BraceStyle.BannerStyle: curIndent.Push(IndentType.Block); CorrectClosingBrace (rbrace); curIndent.Pop (); break; case BraceStyle.EndOfLineWithoutSpace: case BraceStyle.EndOfLine: case BraceStyle.NextLine: CorrectClosingBrace (rbrace); break; case BraceStyle.NextLineShifted2: curIndent.Push(IndentType.Block); CorrectClosingBrace (rbrace); curIndent.Pop (); break; } }
/// <summary> /// Writes a block statement. /// Similar to VisitBlockStatement() except that: /// 1) it allows customizing the BraceStyle /// 2) it does not write a trailing newline after the '}' (this job is left to the caller) /// </summary> protected virtual void WriteBlock(BlockStatement blockStatement, BraceStyle style) { StartNode(blockStatement); OpenBrace(style); foreach (var node in blockStatement.Statements) { node.AcceptVisitor(this); } EndNode(blockStatement); CloseBrace(style); }
void CloseBrace(BraceStyle style) { braceCounter--; lastIsNewLine = false; WriteLine(); switch (style) { case BraceStyle.Array: Write(']'); break; case BraceStyle.Object: Write('}'); break; default: throw new Exception("Unknowed Brace Syyle"); } }
void OpenBrace(BraceStyle style) { WriteLine(); switch (style) { case BraceStyle.Array: Write('['); break; case BraceStyle.Object: Write('{'); break; default: throw new Exception("Unknowed Brace Syyle"); } braceCounter++; lastIsNewLine = false; WriteLine(); }
void FormatAccessor(Accessor accessor, BraceStyle braceStyle, PropertyFormatting blockFormatting, bool oneLine) { if (accessor.IsNull) return; if (!oneLine) { if (!IsLineIsEmptyUpToEol(accessor.StartLocation)) { int offset = this.document.GetOffset(accessor.StartLocation); int start = SearchWhitespaceStart(offset); string indentString = this.curIndent.IndentString; AddChange(start, offset - start, this.options.EolMarker + indentString); } else { FixIndentation(accessor); } } else { blockFormatting = PropertyFormatting.ForceOneLine; if (!accessor.Body.IsNull) { ForceSpacesBeforeRemoveNewLines(accessor.Body.LBraceToken, true); ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true); } } if (!accessor.IsNull) { if (!accessor.Body.IsNull) { if (IsSimpleAccessor (accessor)) { switch (blockFormatting) { case PropertyFormatting.AllowOneLine: if (accessor.Body.LBraceToken.StartLocation.Line != accessor.Body.RBraceToken.StartLocation.Line) goto case PropertyFormatting.ForceNewLine; nextStatementIndent = " "; VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks); if (!oneLine) ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true); break; case PropertyFormatting.ForceOneLine: FixOpenBrace(BraceStyle.EndOfLine, accessor.Body.LBraceToken); var statement = accessor.Body.Statements.First(); ForceSpacesBeforeRemoveNewLines(statement, true); statement.AcceptVisitor(this); if (!oneLine) ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true); break; case PropertyFormatting.ForceNewLine: FixOpenBrace(braceStyle, accessor.Body.LBraceToken); VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks); if (!oneLine) FixClosingBrace(braceStyle, accessor.Body.RBraceToken); break; } } else { FixOpenBrace(braceStyle, accessor.Body.LBraceToken); VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks); FixClosingBrace(braceStyle, accessor.Body.RBraceToken); } } } }
protected virtual void WriteMethodBody(BlockStatement body, BraceStyle style) { if (body.IsNull) { Semicolon(); } else { WriteBlock(body, style); NewLine(); } }
void OpenBrace(BraceStyle style) { switch (style) { case BraceStyle.DoNotChange: case BraceStyle.EndOfLine: case BraceStyle.BannerStyle: if (!isAtStartOfLine) writer.Space(); writer.WriteToken(Roles.LBrace, "{"); break; case BraceStyle.EndOfLineWithoutSpace: writer.WriteToken(Roles.LBrace, "{"); break; case BraceStyle.NextLine: if (!isAtStartOfLine) NewLine(); writer.WriteToken(Roles.LBrace, "{"); break; case BraceStyle.NextLineShifted: NewLine(); writer.Indent(); writer.WriteToken(Roles.LBrace, "{"); NewLine(); return; case BraceStyle.NextLineShifted2: NewLine(); writer.Indent(); writer.WriteToken(Roles.LBrace, "{"); break; default: throw new ArgumentOutOfRangeException (); } writer.Indent(); NewLine(); }
void CloseBrace(BraceStyle style) { switch (style) { case BraceStyle.DoNotChange: case BraceStyle.EndOfLine: case BraceStyle.EndOfLineWithoutSpace: case BraceStyle.NextLine: writer.Unindent(); writer.WriteToken(Roles.RBrace, "}"); isAtStartOfLine = false; break; case BraceStyle.BannerStyle: case BraceStyle.NextLineShifted: writer.WriteToken(Roles.RBrace, "}"); isAtStartOfLine = false; writer.Unindent(); break; case BraceStyle.NextLineShifted2: writer.Unindent(); writer.WriteToken(Roles.RBrace, "}"); isAtStartOfLine = false; writer.Unindent(); break; default: throw new ArgumentOutOfRangeException(); } }
internal string GenerateBody(AstNode node, BraceStyle braceStyle, bool addClosingBracket, ref int newOffset) { StringBuilder result = new StringBuilder(); if (addClosingBracket) result.Append(")"); var nodeIndent = GetIndent(node.Parent); switch (braceStyle) { case BraceStyle.DoNotChange: case BraceStyle.BannerStyle: case BraceStyle.EndOfLine: result.Append(" "); result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); break; case BraceStyle.EndOfLineWithoutSpace: result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); break; case BraceStyle.NextLine: result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent); result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); break; case BraceStyle.NextLineShifted: result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); break; case BraceStyle.NextLineShifted2: result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t"); result.Append("{"); result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent + "\t" + "\t"); break; } newOffset += result.Length; result.Append(textEditorOptions.EolMarker); result.Append(nodeIndent); result.Append("}"); return result.ToString(); }
void FixOpenBrace(BraceStyle braceStyle, AstNode lbrace) { if (lbrace.IsNull) return; switch (braceStyle) { case BraceStyle.DoNotChange: return; case BraceStyle.BannerStyle: case BraceStyle.EndOfLine: var prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; int prevOffset = document.GetOffset(prev.EndLocation); if (prev is Comment || prev is PreProcessorDirective) { int next = document.GetOffset(lbrace.GetNextNode ().StartLocation); AddChange(prevOffset, next - prevOffset, ""); while (prev is Comment || prev is PreProcessorDirective) prev = prev.GetPrevNode(); prevOffset = document.GetOffset(prev.EndLocation); AddChange(prevOffset, 0, " {"); } else { int braceOffset2 = document.GetOffset(lbrace.StartLocation); AddChange(prevOffset, braceOffset2 - prevOffset, " "); } break; case BraceStyle.EndOfLineWithoutSpace: prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; prevOffset = document.GetOffset(prev.EndLocation); int braceOffset = document.GetOffset(lbrace.StartLocation); AddChange(prevOffset, braceOffset - prevOffset, ""); break; case BraceStyle.NextLine: prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; prevOffset = document.GetOffset(prev.EndLocation); braceOffset = document.GetOffset(lbrace.StartLocation); AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString); break; case BraceStyle.NextLineShifted: prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; prevOffset = document.GetOffset(prev.EndLocation); braceOffset = document.GetOffset(lbrace.StartLocation); curIndent.Push(IndentType.Block); AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString); curIndent.Pop(); break; case BraceStyle.NextLineShifted2: prev = lbrace.GetPrevNode (NoWhitespacePredicate); if (prev is PreProcessorDirective) return; prevOffset = document.GetOffset(prev.EndLocation); braceOffset = document.GetOffset(lbrace.StartLocation); curIndent.Push(IndentType.Block); AddChange(prevOffset, braceOffset - prevOffset, options.EolMarker + curIndent.IndentString); curIndent.Pop(); break; } }
void EnforceBraceStyle(BraceStyle braceStyle, CodeLocation lBrace, int rBraceLine, int rBraceColumn) { if (lBrace.IsEmpty) { return; } int lbraceOffset = document.ToOffset(lBrace); int rbraceOffset = document.ToOffset(rBraceLine, rBraceColumn); int whitespaceStart = SearchWhitespaceStart(lbraceOffset); int whitespaceEnd = SearchWhitespaceLineStart(rbraceOffset); string startIndent = ""; string endIndent = ""; switch (braceStyle) { case BraceStyle.DoNotChange: startIndent = endIndent = null; break; case BraceStyle.EndOfLineWithoutSpace: startIndent = ""; endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString; break; case BraceStyle.EndOfLine: int lastNonWs; var lastComments = GetCommentsBefore(lBrace, out lastNonWs); if (lastComments.Count != 0) { // delete old bracket AddChange(whitespaceStart, lbraceOffset - whitespaceStart + 1, ""); lbraceOffset = whitespaceStart = lastNonWs + 1; startIndent = " {"; } else { startIndent = " "; } endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString; break; case BraceStyle.NextLine: startIndent = this.options.EolMarker + curIndent.IndentString; endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString; break; case BraceStyle.NextLineShifted2: case BraceStyle.NextLineShifted: curIndent.Push(IndentType.Block); startIndent = this.options.EolMarker + curIndent.IndentString; endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString; curIndent.Pop(); break; } if (lbraceOffset > 0 && startIndent != null) { AddChange(whitespaceStart, lbraceOffset - whitespaceStart, startIndent); } if (rbraceOffset > 0 && endIndent != null) { AddChange(whitespaceEnd, rbraceOffset - whitespaceEnd, endIndent); } }
public void CloseBrace(BraceStyle style) { Unindent(); WriteIndentation(); sb.Append('}'); }
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); } }
private void FixEmbeddedStatment(BraceStyle braceStyle, AstNode node) { FixEmbeddedStatment(braceStyle, null, false, node); }
public void BeginBrace(BraceStyle style) { switch (style) { case BraceStyle.EndOfLine: text.Append(" "); PrintToken(Tokens.OpenCurlyBrace); NewLine(); ++IndentationLevel; break; case BraceStyle.NextLine: NewLine(); Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); ++IndentationLevel; break; case BraceStyle.NextLineShifted: NewLine(); ++IndentationLevel; Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); break; case BraceStyle.NextLineShifted2: NewLine(); ++IndentationLevel; Indent(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); ++IndentationLevel; break; } braceStack.Push(style); }
void OpenBrace(BraceStyle style) { WriteSpecialsUpToRole(Roles.LBrace); formatter.OpenBrace(style); lastWritten = LastWritten.Other; }
public void CloseBrace(BraceStyle style) { Unindent(); WriteIndentation(); textWriter.Write('}'); }
void AppendBraceStart (StringBuilder result, BraceStyle braceStyle) { switch (braceStyle) { case BraceStyle.BannerStyle: case BraceStyle.EndOfLine: result.Append (" {"); AppendLine (result); break; case BraceStyle.EndOfLineWithoutSpace: result.Append ("{"); AppendLine (result); break; case BraceStyle.NextLine: AppendLine (result); AppendIndent (result); result.Append ("{"); AppendLine (result); break; case BraceStyle.NextLineShifted: AppendLine (result); result.Append (GetIndent (IndentLevel + 1)); result.Append ("{"); AppendLine (result); break; case BraceStyle.NextLineShifted2: AppendLine (result); result.Append (GetIndent (IndentLevel + 1)); result.Append ("{"); AppendLine (result); IndentLevel++; break; default: goto case BraceStyle.NextLine; } IndentLevel++; }
void FormatAccessor(Accessor accessor, BraceStyle braceStyle, PropertyFormatting blockFormatting, bool oneLine) { if (accessor.IsNull) { return; } if (!oneLine) { if (!IsLineIsEmptyUpToEol(accessor.StartLocation)) { int offset = this.document.GetOffset(accessor.StartLocation); int start = SearchWhitespaceStart(offset); string indentString = this.curIndent.IndentString; AddChange(start, offset - start, this.options.EolMarker + indentString); } else { FixIndentation(accessor); } } else { blockFormatting = PropertyFormatting.ForceOneLine; if (!accessor.Body.IsNull) { ForceSpacesBeforeRemoveNewLines(accessor.Body.LBraceToken, true); ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true); } } if (!accessor.IsNull) { if (!accessor.Body.IsNull) { if (IsSimpleAccessor(accessor)) { switch (blockFormatting) { case PropertyFormatting.AllowOneLine: if (accessor.Body.LBraceToken.StartLocation.Line != accessor.Body.RBraceToken.StartLocation.Line) { goto case PropertyFormatting.ForceNewLine; } nextStatementIndent = " "; VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks); if (!oneLine) { ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true); } break; case PropertyFormatting.ForceOneLine: FixOpenBrace(BraceStyle.EndOfLine, accessor.Body.LBraceToken); var statement = accessor.Body.Statements.FirstOrDefault(); if (statement != null) { ForceSpacesBeforeRemoveNewLines(statement, true); statement.AcceptVisitor(this); } if (!oneLine) { ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true); } break; case PropertyFormatting.ForceNewLine: FixOpenBrace(braceStyle, accessor.Body.LBraceToken); VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks); if (!oneLine) { FixClosingBrace(braceStyle, accessor.Body.RBraceToken); } break; } } else { FixOpenBrace(braceStyle, accessor.Body.LBraceToken); VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks); FixClosingBrace(braceStyle, accessor.Body.RBraceToken); } } } }
void EnforceBraceStyle(BraceStyle braceStyle, AstNode lbrace, AstNode rbrace) { if (lbrace.IsNull || rbrace.IsNull) { return; } // LineSegment lbraceLineSegment = data.Document.GetLine (lbrace.StartLocation.Line); int lbraceOffset = document.GetOffset(lbrace.StartLocation); // LineSegment rbraceLineSegment = data.Document.GetLine (rbrace.StartLocation.Line); int rbraceOffset = document.GetOffset(rbrace.StartLocation); int whitespaceStart = SearchWhitespaceStart(lbraceOffset); int whitespaceEnd = SearchWhitespaceLineStart(rbraceOffset); string startIndent = ""; string endIndent = ""; switch (braceStyle) { case BraceStyle.DoNotChange: startIndent = endIndent = null; break; case BraceStyle.EndOfLineWithoutSpace: startIndent = ""; endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString; break; case BraceStyle.BannerStyle: var prevNode = lbrace.GetPrevNode(); if (prevNode is Comment) { // delete old bracket AddChange(whitespaceStart, lbraceOffset - whitespaceStart + 1, ""); while (prevNode is Comment) { prevNode = prevNode.GetPrevNode(); } whitespaceStart = document.GetOffset(prevNode.EndLocation); lbraceOffset = whitespaceStart; startIndent = " {"; } else { startIndent = " "; } curIndent.Push(IndentType.Block); endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString; curIndent.Pop(); break; case BraceStyle.EndOfLine: prevNode = lbrace.GetPrevNode(); if (prevNode is Comment) { // delete old bracket AddChange(whitespaceStart, lbraceOffset - whitespaceStart + 1, ""); while (prevNode is Comment) { prevNode = prevNode.GetPrevNode(); } whitespaceStart = document.GetOffset(prevNode.EndLocation); lbraceOffset = whitespaceStart; startIndent = " {"; } else { startIndent = " "; } endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString; break; case BraceStyle.NextLine: startIndent = this.options.EolMarker + curIndent.IndentString; endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString; break; case BraceStyle.NextLineShifted2: case BraceStyle.NextLineShifted: curIndent.Push(IndentType.Block); startIndent = this.options.EolMarker + curIndent.IndentString; endIndent = IsLineIsEmptyUpToEol(rbraceOffset) ? curIndent.IndentString : this.options.EolMarker + curIndent.IndentString; curIndent.Pop (); break; } if (lbraceOffset > 0 && startIndent != null) { AddChange(whitespaceStart, lbraceOffset - whitespaceStart, startIndent); } if (rbraceOffset > 0 && endIndent != null) { AddChange(whitespaceEnd, rbraceOffset - whitespaceEnd, endIndent); } }
void FixEmbeddedStatment(BraceStyle braceStyle, BraceForcement braceForcement, AstNode node) { FixEmbeddedStatment(braceStyle, braceForcement, null, false, node); }