Print line numbers and at most 40 lines of source per method in stacktrace jv
authorJan Vrany <jan.vrany@labware.com>
Tue, 02 Jun 2020 11:56:19 +0100
branchjv
changeset 566 030aa8306eda
parent 565 80afdfe990f9
child 567 8d386d0a4bfb
Print line numbers and at most 40 lines of source per method in stacktrace This reduces the size of reports, especially for Java code.
reports/Builder__TestReportFormat.st
--- a/reports/Builder__TestReportFormat.st	Tue Jun 02 11:46:28 2020 +0100
+++ b/reports/Builder__TestReportFormat.st	Tue Jun 02 11:56:19 2020 +0100
@@ -108,7 +108,7 @@
 
 writeContext: context on: s
 
-    |home mthd src rcvr vars args argAndVarNames |
+    |home mthd src rcvr vars args argAndVarNames srcFirstLineNr |
     [
     context printOn: s.
     s cr.
@@ -170,7 +170,17 @@
         ^ self.
     ].
     src := src asCollectionOfLines.
+    srcFirstLineNr := 1.
+    src size > 40 ifTrue:[ 
+        | last |
+
+        srcFirstLineNr := (context lineNumber - 15) max: 1.
+        last := (srcFirstLineNr + 29) min: src size.
+        src := src copyFrom: srcFirstLineNr to: last.
+    ].
     src keysAndValuesDo:[:lNr :line |
+        s nextPutAll:'  '. 
+        (lNr + srcFirstLineNr - 1) printOn: s leftPaddedTo:4.
         lNr == context lineNumber ifTrue:[
             s nextPutAll:'>> '.
         ] ifFalse:[
@@ -191,7 +201,7 @@
 
     "Created: / 03-08-2011 / 14:53:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 15-03-2016 / 14:34:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 02-06-2020 / 11:37:16 / Jan Vrany <jan.vrany@labware.com>"
+    "Modified: / 02-06-2020 / 11:55:00 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 writeContextArgs: context on: s
@@ -263,7 +273,7 @@
 
 writeVariable: name index: index value: value on: s
     s nextPutAll:'  '. 
-    index printOn: s leftPaddedTo:3 . s space. 
+    index printOn: s leftPaddedTo:4 . s space. 
     name printOn: s paddedTo:12. s nextPutAll:': '. 
     value isString ifTrue:[ 
         value storeOn: s