-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split: keep 2 instances of FileLine, for debugging
- Loading branch information
Showing
5 changed files
with
72 additions
and
16 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FileLineStack.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.scalafmt.internal | ||
|
||
import org.scalameta.FileLine | ||
|
||
class FileLineStack private ( | ||
val fileLineHead: FileLine, | ||
val fileLineLast: FileLine, | ||
) extends Ordered[FileLineStack] { | ||
override def toString: String = s"$fileLineHead->$fileLineLast" | ||
|
||
def forThisLine(implicit | ||
file: sourcecode.File, | ||
line: sourcecode.Line, | ||
): FileLineStack = new FileLineStack( | ||
fileLineHead = fileLineHead, | ||
fileLineLast = FileLine.generate, | ||
) | ||
|
||
override def compare(that: FileLineStack): Int = { | ||
val cmpLast = Integer | ||
.compare(this.fileLineLast.line.value, that.fileLineLast.line.value) | ||
if (cmpLast != 0) cmpLast | ||
else Integer | ||
.compare(this.fileLineHead.line.value, that.fileLineHead.line.value) | ||
} | ||
} | ||
|
||
object FileLineStack { | ||
implicit def generate(implicit | ||
file: sourcecode.File, | ||
line: sourcecode.Line, | ||
fileLineHead: FileLine, | ||
): FileLineStack = new FileLineStack(fileLineHead, FileLine.generate) | ||
|
||
def nextLine(implicit fl: FileLine): FileLine = { | ||
val line = fl.line | ||
new FileLine(fl.file, line.copy(value = line.value + 1)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters