Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification: consistency, rename isNewline->isNL #4074

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ class FormatOps(
}
val nlMod = newStmtMod
.getOrElse(Space.orNL(ft.noBreak && ft.right.is[T.Comment]))
val delayedBreak = Policy ? nlMod.isNewline || breakAfterComment(ft)
val delayedBreak = Policy ? nlMod.isNL || breakAfterComment(ft)

val (singleLineExpire, singleLineIndent) = {
val skip = skipInfixIndent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ class FormatWriter(formatOps: FormatOps) {
}

implicit val floc: FormatLocation = processLine
val isBlankLine = floc.state.split.modExt.mod.newlines > 1
val isBlankLine = floc.state.split.modExt.mod.isBlankLine
if (alignContainer ne null) {
val candidates = columnCandidates.result()
val block = getOrCreateBlock(alignContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ case class ModExt(mod: Modification, indents: Seq[Indent] = Seq.empty) {
lazy val indentation = indents.mkString("[", ", ", "]")

@inline
def isNL: Boolean = mod.isNewline
def isNL: Boolean = mod.isNL

def withIndent(length: => Length, expire: => Token, when: ExpiresOn): ModExt =
length match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ sealed abstract class Modification {
val newlines: Int
val length: Int
@inline
final def isNewline: Boolean = newlines != 0
final def isNL: Boolean = newlines != 0
@inline
final def isBlankLine: Boolean = newlines > 1
}

case class Provided(ft: FormatToken) extends Modification {
override val newlines: Int = ft.newlinesBetween
override lazy val length: Int =
if (newlines == 0) betweenText.length else betweenText.indexOf('\n')
if (isNL) betweenText.indexOf('\n') else betweenText.length
lazy val betweenText: String = ft.between.map(_.syntax).mkString
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ class Router(formatOps: FormatOps) {
val mod =
if (style.newlines.keepBreak(newlines)) Newline
else Space(style.spaces.isSpaceAfterKeyword(right))
val slb = Split(mod.isNewline, 0)(mod)
val slb = Split(mod.isNL, 0)(mod)
.withSingleLine(expire, killOnFail = true)
val mlSplitBase = Split(mod, if (slb.isIgnored) 0 else 1)
.withPolicy(getBreakBeforeElsePolicy(owner))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ final case class State(
// Some tokens contain newline, like multiline strings/comments.
val startColumn = nextSplit.modExt.mod match {
case m: NewlineT => if (m.noIndent) 0 else nextIndent
case m => if (m.isNewline) nextIndent else column + m.length
case m => if (m.isNL) nextIndent else column + m.length
}
val (columnOnCurrentLine, nextStateColumn) = State
.getColumns(tok, nextIndent, startColumn)
Expand Down
Loading