static bool ShouldBreakLine(NewLinePlacement placement, CSharpTokenNode 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); }
public CSharpSyntaxFormattingOptions( LineFormattingOptions lineFormatting, bool separateImportDirectiveGroups, SpacePlacement spacing, BinaryOperatorSpacingOptions spacingAroundBinaryOperator, NewLinePlacement newLines, LabelPositionOptions labelPositioning, IndentationPlacement indentation, bool wrappingKeepStatementsOnSingleLine, bool wrappingPreserveSingleLine) : base(lineFormatting, separateImportDirectiveGroups) { Spacing = spacing; SpacingAroundBinaryOperator = spacingAroundBinaryOperator; NewLines = newLines; LabelPositioning = labelPositioning; Indentation = indentation; WrappingKeepStatementsOnSingleLine = wrappingKeepStatementsOnSingleLine; WrappingPreserveSingleLine = wrappingPreserveSingleLine; }
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); }
public CSharpSyntaxFormattingOptions( LineFormattingOptions?lineFormatting = null, bool separateImportDirectiveGroups = false, SpacePlacement spacing = SpacingDefault, BinaryOperatorSpacingOptions spacingAroundBinaryOperator = BinaryOperatorSpacingOptions.Single, NewLinePlacement newLines = NewLinesDefault, LabelPositionOptions labelPositioning = LabelPositionOptions.OneLess, IndentationPlacement indentation = IndentationDefault, bool wrappingKeepStatementsOnSingleLine = true, bool wrappingPreserveSingleLine = true) : base(lineFormatting, separateImportDirectiveGroups) { Spacing = spacing; SpacingAroundBinaryOperator = spacingAroundBinaryOperator; NewLines = newLines; LabelPositioning = labelPositioning; Indentation = indentation; WrappingKeepStatementsOnSingleLine = wrappingKeepStatementsOnSingleLine; WrappingPreserveSingleLine = wrappingPreserveSingleLine; }
void PlaceOnNewLine(NewLinePlacement newLine, AstNode keywordNode) { if (keywordNode == null || newLine == NewLinePlacement.DoNotCare) { return; } var prev = keywordNode.GetPrevNode (NoWhitespacePredicate); 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); }
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; }
/// <summary> /// Writes an embedded statement. /// </summary> /// <param name="embeddedStatement">The statement to write.</param> /// <param name="nlp">Determines whether a trailing newline should be written following a block. /// Non-blocks always write a trailing newline.</param> /// <remarks> /// Blocks may or may not write a leading newline depending on StatementBraceStyle. /// Non-blocks always write a leading newline. /// </remarks> protected virtual void WriteEmbeddedStatement(Statement embeddedStatement, NewLinePlacement nlp = NewLinePlacement.NewLine) { if (embeddedStatement.IsNull) { NewLine(); return; } BlockStatement block = embeddedStatement as BlockStatement; if (block != null) { WriteBlock(block, policy.StatementBraceStyle); if (nlp == NewLinePlacement.SameLine) { Space(); // if not a trailing newline, then at least a trailing space } else { NewLine(); } } else { NewLine(); writer.Indent(); embeddedStatement.AcceptVisitor(this); writer.Unindent(); } }
void PlaceOnNewLine(NewLinePlacement newLine, AstNode keywordNode) { if (keywordNode == null || newLine == NewLinePlacement.DoNotCare) { return; } int offset = document.GetOffset(keywordNode.StartLocation); int whitespaceStart = SearchWhitespaceStart(offset); string indentString = newLine == NewLinePlacement.NewLine ? this.options.EolMarker + this.curIndent.IndentString : " "; AddChange(whitespaceStart, offset - whitespaceStart, indentString); }