blob: eb8880e43713557e49e4414372823c64cda41dd8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package scala.tools.nsc.scratchpad
import java.io.Writer
import reflect.internal.Chars._
class CommentWriter(underlying: SourceInserter, startCol: Int = 40, endCol: Int = 152) extends Writer {
private def rightCol(marker: String) = {
while (underlying.column < startCol) underlying.write(' ')
underlying.write(marker)
}
private var lastWasNL = false
private def writeChar(ch: Char) = {
if (underlying.column >= endCol) {
underlying.write('\n'); rightCol("//| ")
}
if (underlying.column < startCol) rightCol("//> ")
underlying.write(ch)
lastWasNL = isLineBreakChar(ch)
}
override def write(chs: Array[Char], off: Int, len: Int) = {
for (i <- off until off + len) writeChar(chs(i))
flush()
}
def skip(len: Int) {
if (lastWasNL) {
underlying.backspace()
lastWasNL = false
}
underlying.skip(len)
if (underlying.column >= startCol) underlying.write('\n')
}
override def close() = underlying.close()
override def flush() = underlying.flush()
}
|