Fixes in Builder::CoverageReportFormat
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 27 Jun 2013 14:44:49 +0200
changeset 183 4e6fc1b6c282
parent 182 556ad4c2c381
child 184 5f75ffc9642b
Fixes in Builder::CoverageReportFormat
reports/Builder__CoverageReportFormat.st
--- a/reports/Builder__CoverageReportFormat.st	Wed Jun 26 23:47:46 2013 +0200
+++ b/reports/Builder__CoverageReportFormat.st	Thu Jun 27 14:44:49 2013 +0200
@@ -10,7 +10,8 @@
 !
 
 CoverageReportFormat subclass:#Cobertura
-	instanceVariableNames:'currentPackage currentClass currentMethod infos'
+	instanceVariableNames:'currentPackage currentClass currentClassLinesBuffer currentMethod
+		infos'
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:CoverageReportFormat
@@ -80,10 +81,10 @@
     packageMap := Dictionary new.
     infos := Dictionary new.
     instrumentedMethods do:[:method|
-        | classMap methodMap |
+        | classMap methodSet |
         classMap := packageMap at: method package ifAbsentPut: [ Dictionary new ].
-        methodMap := classMap at: method mclass ifAbsentPut: [ Dictionary new ].
-        methodMap at: method selector put: method.
+        methodSet := classMap at: method mclass ifAbsentPut: [ Set new ].
+        methodSet add: method.
     ].
 
     packageMap keys asSortedCollection do:[:package|
@@ -91,12 +92,13 @@
 
         self writePackage: package with:[            
             ((classMap := packageMap at: package) keys asSortedCollection:[:a :b| a name < b name ]) do:[:class|
-                | methodMap |
+                | methodSet |
                 self writeClass: class with:[
-                    (methodMap := classMap at: class) keys asSortedCollection do:[:selector|
-                        | method |
+                    | methodSetOrdered info |
 
-                        method := methodMap at: selector.
+                    info := infos at: class ifAbsentPut:[ReportSourceInfo for: class].
+                    methodSetOrdered := (classMap at: class) asSortedCollection:[:a :b | (info offsetOfMethod: a) < (info offsetOfMethod: b)].
+                    methodSetOrdered do:[:method|
                         self writeMethod: method.
                     ]                    
                 ]
@@ -105,6 +107,7 @@
     ]
 
     "Created: / 25-06-2013 / 13:17:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 27-06-2013 / 11:56:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 writeClass: class with: content
@@ -124,13 +127,18 @@
     stream nextPutAll:'        <class name="'; nextPutAll: className; nextPutAll: '" filename="'; nextPutAll: classPathName; nextPutLine:'" line-rate="1.0" branch-rate="1.0" complexity="1.0">'.
     stream nextPutLine:'          <methods>'.
     currentClass := class.
+    currentClassLinesBuffer := String new writeStream.
     content value.               
     currentClass := nil.
     stream nextPutLine:'          </methods>'.
+    stream nextPutLine:'          <lines>'.
+    stream nextPutAll: currentClassLinesBuffer contents.
+    stream nextPutLine:'          </lines>'.
+    currentClassLinesBuffer := nil.
     stream nextPutLine:'        </class>'
 
     "Created: / 25-06-2013 / 12:29:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 26-06-2013 / 17:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 27-06-2013 / 00:05:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 writeFooter
@@ -159,19 +167,18 @@
     "Modified: / 26-06-2013 / 17:50:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-writeLine: lineNr hits: nhits
+writeLine: lineNr hits: nhits on: s
 
-    stream nextPut:'            <line number="'; nextPutAll: lineNr printString; nextPutAll:'" hits="'; nextPutAll: nhits printString; nextPutLine:'" branch="false" />'.
+    s nextPutAll:'            <line number="'; nextPutAll: lineNr printString; nextPutAll:'" hits="'; nextPutAll: nhits printString; nextPutLine:'" branch="false" />'.
 
-    "Created: / 25-06-2013 / 13:04:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 25-06-2013 / 14:23:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 27-06-2013 / 00:03:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 writeMethod: method
 
     | info firstCharOffset firstLineNr lastLineNr lines  |
 
-    stream nextPutAll:'        <method name="'; nextPutAll: method selector; nextPutLine: '" signature="()" line-rate="1.0" branch-rate="1.0" complexity="1.0">'.
+    stream nextPutAll:'        <method name="'; nextPutAll: method selector; nextPutLine: '" signature="" line-rate="1.0" branch-rate="1.0" complexity="1.0">'.
     stream nextPutLine:'          <lines>'.
     currentMethod := method.
 
@@ -194,7 +201,8 @@
     ].
 
     1 to: lines size do:[:i|
-        self writeLine: (i + firstLineNr - 1) hits: (lines at: i)
+        self writeLine: (i + firstLineNr - 1) hits: (lines at: i) on: stream.
+        self writeLine: (i + firstLineNr - 1) hits: (lines at: i) on: currentClassLinesBuffer.
     ].
 
     currentMethod := nil.
@@ -202,7 +210,7 @@
     stream nextPutLine:'        </method>'
 
     "Created: / 25-06-2013 / 13:17:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 25-06-2013 / 14:51:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 27-06-2013 / 00:04:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 writeMethod: method with: content