@@ -11,14 +11,27 @@ class CodeGrid(mfile: MeasuredFile) {
11
11
12
12
private val lineBreak = System .getProperty(" line.separator" )
13
13
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
14
16
// note: we must reinclude the line sep to keep source positions correct.
15
17
private val lines = source(mfile).split(lineBreak).map(line => (line.toCharArray ++ lineBreak).map(Cell (_, NoData )))
16
18
17
19
// useful to have a single array to write into the cells
18
20
private val cells = lines.flatten
19
21
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
+ })
22
35
23
36
val highlighted : String = {
24
37
var lineNumber = 1
@@ -45,19 +58,6 @@ class CodeGrid(mfile: MeasuredFile) {
45
58
46
59
private def source (mfile : MeasuredFile ): String = Source .fromFile(mfile.source).mkString
47
60
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
-
61
61
private def spanStart (status : StatementStatus ): String = s " <span style=' ${cellStyle(status)}'> "
62
62
63
63
private def cellStyle (status : StatementStatus ): String = {
0 commit comments