void FixIndentationForceNewLine(AstNode node) { if (node.GetPrevNode() is NewLineNode) { FixIndentation(node); } else { int offset = document.GetOffset(node.StartLocation); AddChange(offset, 0, curIndent.IndentString); } }
void CorrectClosingBrace(AstNode rbrace) { int braceOffset = document.GetOffset(rbrace.StartLocation); var prevNode = rbrace.GetPrevNode(); int prevNodeOffset = prevNode != null?document.GetOffset(prevNode.EndLocation) : 0; if (prevNode is NewLineNode) { AddChange(prevNodeOffset, braceOffset - prevNodeOffset, curIndent.IndentString); } else { AddChange(prevNodeOffset, braceOffset - prevNodeOffset, options.EolMarker + curIndent.IndentString); } }
void PlaceOnNewLine(NewLinePlacement newLine, AstNode keywordNode) { if (keywordNode == null || newLine == NewLinePlacement.DoNotCare) { return; } var prev = keywordNode.GetPrevNode(); if (prev is Comment || prev is PreProcessorDirective) { return; } int offset = document.GetOffset(keywordNode.StartLocation); int whitespaceStart = SearchWhitespaceStart(offset); string indentString = newLine == NewLinePlacement.NewLine ? options.EolMarker + curIndent.IndentString : " "; AddChange(whitespaceStart, offset - whitespaceStart, indentString); }
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; } }