168
|
1 |
"{ Package: 'stx:goodies/builder/reports' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Builder }"
|
|
4 |
|
|
5 |
Object subclass:#ReportSourceInfo
|
|
6 |
instanceVariableNames:'klass filename offsets lineEnds'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Builder-Reports-Utils'
|
|
10 |
!
|
|
11 |
|
|
12 |
Stream subclass:#LineCountingStream
|
|
13 |
instanceVariableNames:'position lineEnds'
|
|
14 |
classVariableNames:''
|
|
15 |
poolDictionaries:''
|
|
16 |
privateIn:ReportSourceInfo
|
|
17 |
!
|
|
18 |
|
|
19 |
!ReportSourceInfo class methodsFor:'documentation'!
|
|
20 |
|
|
21 |
documentation
|
|
22 |
"
|
|
23 |
Utility class to map line numbers in methods to global
|
|
24 |
line number in source file (in chunk-formatted .st file)
|
|
25 |
|
|
26 |
[author:]
|
|
27 |
Jan Vrany <jan.vrany@fit.cvut.cz>
|
|
28 |
|
|
29 |
[instance variables:]
|
|
30 |
|
|
31 |
[class variables:]
|
|
32 |
|
|
33 |
[see also:]
|
|
34 |
|
|
35 |
"
|
|
36 |
! !
|
|
37 |
|
|
38 |
!ReportSourceInfo class methodsFor:'instance creation'!
|
|
39 |
|
|
40 |
for: aClass
|
|
41 |
^self new setClass: aClass
|
|
42 |
|
|
43 |
"Created: / 01-03-2013 / 17:50:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
44 |
! !
|
|
45 |
|
|
46 |
!ReportSourceInfo methodsFor:'initialization'!
|
|
47 |
|
|
48 |
setClass: aClass
|
|
49 |
klass := aClass theNonMetaclass.
|
|
50 |
self setup.
|
|
51 |
|
|
52 |
"Created: / 01-03-2013 / 17:49:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
53 |
!
|
|
54 |
|
|
55 |
setup
|
|
56 |
"To be called after class is set"
|
|
57 |
|
|
58 |
| stream |
|
|
59 |
|
|
60 |
stream := LineCountingStream new.
|
|
61 |
offsets := Dictionary new.
|
|
62 |
|
|
63 |
[
|
|
64 |
self fileOutOn: stream.
|
|
65 |
] on: AbstractSourceFileWriter methodSourceRewriteQuery do:[:rewriteQuery |
|
|
66 |
| m |
|
|
67 |
|
|
68 |
m := rewriteQuery method.
|
|
69 |
offsets at: m put: stream position + 1.
|
|
70 |
rewriteQuery proceed.
|
|
71 |
].
|
|
72 |
lineEnds := stream lineEnds
|
|
73 |
|
|
74 |
"
|
|
75 |
SourceInfo for: Builder::ReportRunner
|
|
76 |
"
|
|
77 |
|
|
78 |
"Created: / 01-03-2013 / 17:30:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
79 |
"Modified: / 03-03-2013 / 11:09:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
80 |
! !
|
|
81 |
|
|
82 |
!ReportSourceInfo methodsFor:'queries'!
|
|
83 |
|
|
84 |
lineAndColumnOfOffset: offset
|
|
85 |
| low high middle element line col |
|
|
86 |
|
|
87 |
low := 1.
|
|
88 |
high := lineEnds size.
|
|
89 |
[low > high] whileFalse:[
|
|
90 |
middle := (low + high) // 2.
|
|
91 |
element := lineEnds at:middle.
|
|
92 |
element < offset ifTrue:[
|
|
93 |
"middleelement is smaller than object"
|
|
94 |
low := middle + 1
|
|
95 |
] ifFalse:[
|
|
96 |
high := middle - 1
|
|
97 |
]
|
|
98 |
].
|
|
99 |
|
|
100 |
line := low.
|
|
101 |
col := offset - (line > 1 ifTrue:[lineEnds at: line - 1] ifFalse:[0]).
|
|
102 |
^line @ col.
|
|
103 |
|
|
104 |
"Created: / 03-03-2013 / 10:50:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
105 |
!
|
|
106 |
|
|
107 |
offsetOfMethod: aMethod
|
|
108 |
^offsets at: aMethod
|
|
109 |
|
|
110 |
"Created: / 03-03-2013 / 10:49:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
111 |
! !
|
|
112 |
|
|
113 |
!ReportSourceInfo methodsFor:'utilities'!
|
|
114 |
|
|
115 |
fileOutOn:aStream
|
|
116 |
klass fileOutOn: aStream withTimeStamp:false
|
|
117 |
|
|
118 |
"Created: / 01-03-2013 / 17:51:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
119 |
! !
|
|
120 |
|
|
121 |
!ReportSourceInfo::LineCountingStream class methodsFor:'instance creation'!
|
|
122 |
|
|
123 |
new
|
|
124 |
"return an initialized instance"
|
|
125 |
|
|
126 |
^ self basicNew initialize.
|
|
127 |
! !
|
|
128 |
|
|
129 |
!ReportSourceInfo::LineCountingStream methodsFor:'accessing'!
|
|
130 |
|
|
131 |
contents
|
|
132 |
"return the entire contents of the stream.
|
|
133 |
For a readStream, that is the rest (i.e. upToEnd),
|
|
134 |
for a writeStream, that is the collected data. As we do not know here,
|
|
135 |
what we are, this is the responsibility of a subclass..."
|
|
136 |
|
|
137 |
^ self shouldNotImplement
|
|
138 |
|
|
139 |
"Modified: / 01-03-2013 / 17:36:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
140 |
!
|
|
141 |
|
|
142 |
lineEnds
|
|
143 |
^ lineEnds
|
|
144 |
!
|
|
145 |
|
|
146 |
position
|
|
147 |
^ position
|
|
148 |
! !
|
|
149 |
|
|
150 |
!ReportSourceInfo::LineCountingStream methodsFor:'initialization'!
|
|
151 |
|
|
152 |
initialize
|
|
153 |
"Invoked when a new instance is created."
|
|
154 |
|
|
155 |
"/ please change as required (and remove this comment)
|
|
156 |
position := 0.
|
|
157 |
lineEnds := OrderedCollection new.
|
|
158 |
|
|
159 |
"/ super initialize. -- commented since inherited method does nothing
|
|
160 |
|
|
161 |
"Modified: / 01-03-2013 / 17:39:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
162 |
! !
|
|
163 |
|
|
164 |
!ReportSourceInfo::LineCountingStream methodsFor:'queries'!
|
|
165 |
|
|
166 |
isReadable
|
|
167 |
"return true, if reading is supported by the recevier.
|
|
168 |
This has to be redefined in concrete subclasses."
|
|
169 |
|
|
170 |
^ false
|
|
171 |
|
|
172 |
"Modified: / 01-03-2013 / 17:36:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
173 |
!
|
|
174 |
|
|
175 |
isWritable
|
|
176 |
"return true, if writing is supported by the recevier.
|
|
177 |
This has to be redefined in concrete subclasses."
|
|
178 |
|
|
179 |
^ true
|
|
180 |
|
|
181 |
"Modified: / 01-03-2013 / 17:37:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
182 |
!
|
|
183 |
|
|
184 |
size
|
|
185 |
"return the number of elements in the streamed collection."
|
|
186 |
|
|
187 |
^ self shouldImplement
|
|
188 |
! !
|
|
189 |
|
|
190 |
!ReportSourceInfo::LineCountingStream methodsFor:'reading'!
|
|
191 |
|
|
192 |
next
|
|
193 |
"return the next element of the stream
|
|
194 |
- we do not know here how to do it, it must be redefined in subclass"
|
|
195 |
|
|
196 |
^ self shouldNotImplement
|
|
197 |
|
|
198 |
"Modified: / 01-03-2013 / 17:37:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
199 |
! !
|
|
200 |
|
|
201 |
!ReportSourceInfo::LineCountingStream methodsFor:'testing'!
|
|
202 |
|
|
203 |
atEnd
|
|
204 |
"return true if the end of the stream has been reached;
|
|
205 |
- we do not know here how to do it, it must be redefined in subclass"
|
|
206 |
|
|
207 |
^ false
|
|
208 |
|
|
209 |
"Modified: / 01-03-2013 / 17:37:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
210 |
!
|
|
211 |
|
|
212 |
isEmpty
|
|
213 |
"return true, if the contents of the stream is empty"
|
|
214 |
|
|
215 |
^ self shouldNotImplement
|
|
216 |
|
|
217 |
"Modified: / 01-03-2013 / 17:37:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
218 |
! !
|
|
219 |
|
|
220 |
!ReportSourceInfo::LineCountingStream methodsFor:'writing'!
|
|
221 |
|
|
222 |
nextPut:aCharacter
|
|
223 |
"put the argument, anObject onto the receiver
|
|
224 |
- we do not know here how to do it, it must be redefined in subclass"
|
|
225 |
|
|
226 |
position := position + 1.
|
|
227 |
aCharacter == Character cr ifTrue:[
|
|
228 |
lineEnds add: position
|
|
229 |
].
|
|
230 |
|
|
231 |
"Modified: / 01-03-2013 / 17:39:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
232 |
! !
|
|
233 |
|
|
234 |
!ReportSourceInfo class methodsFor:'documentation'!
|
|
235 |
|
|
236 |
version
|
|
237 |
^ '$Header$'
|
|
238 |
!
|
|
239 |
|
|
240 |
version_CVS
|
|
241 |
^ '$Header$'
|
|
242 |
! !
|
|
243 |
|