From e1de2a9a87c4cce5f785345771430d2ec30edc01 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Fri, 11 Aug 2023 08:50:13 +0300 Subject: [PATCH] FormatWriter: FormatLocations.iterate to foreach --- .../src/main/scala/org/scalafmt/internal/FormatWriter.scala | 6 +++--- .../src/test/scala/org/scalafmt/util/HasTests.scala | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala index 2ad8eb7679..5a96edab65 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala @@ -31,7 +31,7 @@ class FormatWriter(formatOps: FormatOps) { val locations = getFormatLocations(state) styleMap.init.runner.event(FormatEvent.Written(locations)) - locations.iterate.foreach { entry => + locations.foreach { entry => val location = entry.curr implicit val style: ScalafmtConfig = location.style val formatToken = location.formatToken @@ -424,9 +424,9 @@ class FormatWriter(formatOps: FormatOps) { val tokenAligns: Map[Int, Int] = alignmentTokens - def iterate: Iterator[Entry] = { + def foreach(f: Entry => Unit): Unit = { val iterator = Iterator.range(0, locations.length).map(new Entry(_)) - iterator.filter(_.curr.isNotRemoved) + iterator.filter(_.curr.isNotRemoved).foreach(f) } private def getAlign(tok: FormatToken, alignOffset: Int = 0): Int = diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/util/HasTests.scala b/scalafmt-tests/src/test/scala/org/scalafmt/util/HasTests.scala index d859d9c6f3..dcf148bebc 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/util/HasTests.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/util/HasTests.scala @@ -199,7 +199,7 @@ trait HasTests extends FormatAssertions { def getFormatOutput(debug: Debug): Array[FormatOutput] = { val builder = mutable.ArrayBuilder.make[FormatOutput] - debug.locations.iterate.foreach { entry => + debug.locations.foreach { entry => val token = entry.curr.formatToken builder += FormatOutput( token.left.syntax + entry.getWhitespace(0),