Report only lines which contains real code (ignoring comments, method signature and so on)
--- a/reports/Builder__CoverageReportFormat.st Mon Jul 29 01:40:21 2013 +0200
+++ b/reports/Builder__CoverageReportFormat.st Mon Jul 29 13:22:25 2013 +0200
@@ -17,6 +17,13 @@
privateIn:CoverageReportFormat
!
+Parser subclass:#MethodAnalyzer
+ instanceVariableNames:'intervals branches'
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:CoverageReportFormat::Cobertura
+!
+
!CoverageReportFormat class methodsFor:'testing'!
@@ -176,7 +183,7 @@
writeMethod: method
- | info firstCharOffset firstLineNr lastLineNr lines name |
+ | info firstCharOffset firstLineNr lastLineNr analyzer lines name |
name := method selector.
method mclass isMetaclass ifTrue:[
@@ -193,6 +200,17 @@
lastLineNr := (info lineAndColumnOfOffset: firstCharOffset + method source size) x.
lines := Array new: lastLineNr - firstLineNr + 1 withAll: nil.
+ analyzer := MethodAnalyzer new.
+ analyzer parseMethod: method source in: method mclass.
+ analyzer intervals do:[:interval|
+ | start stop |
+
+ start := info lineAndColumnOfOffset: interval first.
+ stop := info lineAndColumnOfOffset: interval last.
+ start x to: stop x do:[:lineNr|
+ lines at: lineNr put: -1.
+ ].
+ ].
(method statementInvocationInfo copy sort:[:a :b | a startPosition < b startPosition]) do:[:eachBlockInfo |
| startLine endLine |
@@ -200,7 +218,7 @@
startLine := (info lineAndColumnOfOffset: firstCharOffset + eachBlockInfo startPosition - 1) x.
endLine := (info lineAndColumnOfOffset: firstCharOffset + eachBlockInfo endPosition - 1) x.
startLine to: endLine do:[:lineNr|
- (lines at: (lineNr - firstLineNr + 1)) isNil ifTrue:[
+ (lines at: (lineNr - firstLineNr + 1)) == -1 ifTrue:[
lines at: (lineNr - firstLineNr + 1) put: (eachBlockInfo count)
] ifFalse:[
lines at: (lineNr - firstLineNr + 1) put: ((lines at: (lineNr - firstLineNr + 1)) min: eachBlockInfo count)
@@ -208,8 +226,13 @@
]
].
1 to: lines size do:[:i|
- self writeLine: (i + firstLineNr - 1) hits: ((lines at: i) ? 0) on: stream.
- self writeLine: (i + firstLineNr - 1) hits: ((lines at: i) ? 0) on: currentClassLinesBuffer.
+ (lines at: i) notNil ifTrue:[
+ (lines at: i) == -1 ifTrue:[
+ lines at: i put: 0.
+ ].
+ self writeLine: (i + firstLineNr - 1) hits: ((lines at: i)) on: stream.
+ self writeLine: (i + firstLineNr - 1) hits: ((lines at: i)) on: currentClassLinesBuffer.
+ ]
].
currentMethod := nil.
@@ -217,7 +240,7 @@
stream nextPutLine:' </method>'
"Created: / 25-06-2013 / 13:17:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 29-07-2013 / 00:35:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 29-07-2013 / 10:56:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
writePackage: packageName with: aBlock
@@ -234,6 +257,38 @@
"Modified: / 25-06-2013 / 13:24:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!CoverageReportFormat::Cobertura::MethodAnalyzer methodsFor:'accessing'!
+
+branches
+ ^ branches
+!
+
+intervals
+ ^ intervals
+! !
+
+!CoverageReportFormat::Cobertura::MethodAnalyzer methodsFor:'code generation hooks'!
+
+statementListRewriteHookFor:aStatementNode
+ "invoked whenever a statement list node has been generated;
+ gives subclasses a chance to rewrite (instrument) it"
+
+ | stmt |
+
+ intervals isNil ifTrue:[
+ intervals := OrderedCollection new.
+ ].
+ stmt := aStatementNode.
+ [ stmt notNil ] whileTrue:[
+ intervals add: (stmt startPosition to: stmt endPosition).
+ stmt := stmt nextStatement.
+ ].
+ ^ aStatementNode
+
+ "Created: / 29-07-2013 / 10:16:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 29-07-2013 / 11:25:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!CoverageReportFormat class methodsFor:'documentation'!
version