@@ -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 = {
0 commit comments