Skip to content

Commit 77c7cf5

Browse files
committed
Fixed code grid so that outer statements do not override inner statements.
1 parent 7361e62 commit 77c7cf5

File tree

3 files changed

+22
-115
lines changed

3 files changed

+22
-115
lines changed

scalac-scoverage-plugin/src/main/scala/scoverage/report/CodeGrid.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@ class CodeGrid(mfile: MeasuredFile) {
1111

1212
private val lineBreak = System.getProperty("line.separator")
1313

14+
// Array of lines, each line is an array of cells, where a cell is a character + coverage info for that position
15+
// All cells defaul to NoData until the highlighted information is applied
1416
// note: we must reinclude the line sep to keep source positions correct.
1517
private val lines = source(mfile).split(lineBreak).map(line => (line.toCharArray ++ lineBreak).map(Cell(_, NoData)))
1618

1719
// useful to have a single array to write into the cells
1820
private val cells = lines.flatten
1921

20-
// for all statements in the source file we build highlighted data
21-
mfile.statements.foreach(highlight)
22+
// apply the instrumentation data to the cells updating their coverage info
23+
mfile.statements.foreach(stmt => {
24+
for ( k <- stmt.start until stmt.end ) {
25+
if (k < cells.size) {
26+
// if the cell is set to NotInvoked, then it cannot be changed further, even if an outer statement
27+
// is green. This is because, for example, a block may be entered, but not all contained statements
28+
// in that block were executed
29+
if (cells(k).status != NotInvoked) {
30+
if (stmt.isInvoked) cells(k).status = Invoked
31+
}
32+
}
33+
}
34+
})
2235

2336
val highlighted: String = {
2437
var lineNumber = 1
@@ -45,19 +58,6 @@ class CodeGrid(mfile: MeasuredFile) {
4558

4659
private def source(mfile: MeasuredFile): String = Source.fromFile(mfile.source).mkString
4760

48-
private def highlight(stmt: Statement) {
49-
50-
for ( k <- stmt.start until stmt.end ) {
51-
if (k < cells.size) {
52-
if (stmt.isInvoked) {
53-
cells(k).status = Invoked
54-
} else if (cells(k).status == NoData) {
55-
cells(k).status = NotInvoked
56-
}
57-
}
58-
}
59-
}
60-
6161
private def spanStart(status: StatementStatus): String = s"<span style='${cellStyle(status)}'>"
6262

6363
private def cellStyle(status: StatementStatus): String = {

scalac-scoverage-plugin/src/main/scala/scoverage/report/SourceHighlighter.scala

Lines changed: 0 additions & 98 deletions
This file was deleted.

scalac-scoverage-plugin/src/main/scala/scoverage/report/StatementWriter.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ class StatementWriter(mfile: MeasuredFile) {
2121
<tr>
2222
<th>Line Number</th>
2323
<th>Statement Id</th>
24+
<th>Pos</th>
2425
<th>Tree Type</th>
2526
<th>Symbol</th>
2627
<th>Code</th>
27-
</tr>
28-
{mfile.statements.toSeq.sortBy(_.line).map(stmt => {
28+
</tr>{mfile.statements.toSeq.sortBy(_.line).map(stmt => {
2929
<tr>
3030
<td>
3131
{stmt.line}
3232
</td>
3333
<td>
3434
{stmt.id}
3535
</td>
36+
<td>
37+
{stmt.start.toString}
38+
-
39+
{stmt.end.toString}
40+
</td>
3641
<td>
3742
{stmt.treeName}
3843
</td>

0 commit comments

Comments
 (0)