393
|
1 |
"{ Package: 'stx:goodies/monticello' }"
|
|
2 |
|
|
3 |
Object subclass:#MethodReference
|
|
4 |
instanceVariableNames:'classSymbol classIsMeta methodSymbol stringVersion category'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'System-Tools'
|
|
8 |
!
|
|
9 |
|
|
10 |
MethodReference comment:'A MethodReference is is a lightweight proxy for a CompiledMethod. Has methods for pointed to the CompileMethod''s source statements, byte codes. Is heavily used my Tools.
|
|
11 |
|
|
12 |
Instance Variables
|
|
13 |
classIsMeta: Boolean class vs. instance
|
|
14 |
classSymbol: Symbol for method''s class (without class keyword if meta)
|
|
15 |
methodSymbol: Symbol for method''s selector
|
|
16 |
stringVersion: ''Class>>selector:'' format
|
|
17 |
|
|
18 |
'
|
|
19 |
!
|
|
20 |
|
|
21 |
|
|
22 |
!MethodReference class methodsFor:'instance creation'!
|
|
23 |
|
|
24 |
class: aClass selector: aSelector
|
|
25 |
^ self new setStandardClass: aClass methodSymbol: aSelector
|
|
26 |
! !
|
|
27 |
|
|
28 |
!MethodReference methodsFor:'*Kernel-Traits'!
|
|
29 |
|
|
30 |
actualClass
|
|
31 |
|
|
32 |
| actualClass |
|
|
33 |
|
|
34 |
actualClass := Smalltalk at: classSymbol ifAbsent: [^nil].
|
|
35 |
classIsMeta ifTrue: [^actualClass classSide].
|
|
36 |
^actualClass
|
|
37 |
|
|
38 |
! !
|
|
39 |
|
|
40 |
!MethodReference methodsFor:'*OB-Standard'!
|
|
41 |
|
|
42 |
asNode
|
|
43 |
^ OBMethodNode on: self
|
|
44 |
! !
|
|
45 |
|
|
46 |
!MethodReference methodsFor:'*fixunderscores'!
|
|
47 |
|
|
48 |
fixLFInvisible
|
|
49 |
"Replace invisible with space. Answer true if fixed or no fix necessary, false if manual fix required"
|
|
50 |
|
|
51 |
| src ts |
|
|
52 |
"Check if we do need to do anything"
|
|
53 |
src := self actualClass sourceCodeAt: methodSymbol.
|
|
54 |
(src includes: Character lf) ifFalse: [^true].
|
|
55 |
|
|
56 |
"Chicken out if there is a literal underscore"
|
|
57 |
"cm := self actualClass compiledMethodAt: methodSymbol.
|
|
58 |
(cm hasLiteralSuchThat: [:lit |
|
|
59 |
lit = Character lf or: [lit isString and: [lit includes: Character lf]]]) ifTrue: [^false]."
|
|
60 |
|
|
61 |
"Otherwise, replace underscores with :="
|
|
62 |
src := src copyReplaceAll: Character lf asString with: Character space asString, Character cr asString.
|
|
63 |
ts := self timeStamp.
|
|
64 |
ts = '' ifTrue: [ts := nil].
|
|
65 |
self actualClass
|
|
66 |
compile: src
|
|
67 |
classified: ClassOrganizer default
|
|
68 |
withStamp: ts
|
|
69 |
notifying: nil.
|
|
70 |
|
|
71 |
^true
|
|
72 |
!
|
|
73 |
|
|
74 |
fixUnderscores
|
|
75 |
"Replace underscores with :=. Answer true if fixed or no fix necessary, false if manual fix required"
|
|
76 |
|
|
77 |
| src cm ts |
|
|
78 |
"Check if we do need to do anything"
|
|
79 |
src := self actualClass sourceCodeAt: methodSymbol.
|
|
80 |
(src includes: $_) ifFalse: [^true].
|
|
81 |
|
|
82 |
"Chicken out if there is a literal underscore"
|
|
83 |
cm := self actualClass compiledMethodAt: methodSymbol.
|
|
84 |
(cm hasLiteralSuchThat: [:lit |
|
|
85 |
lit = $_ or: [lit isString and: [lit includes: $_]]]) ifTrue: [^false].
|
|
86 |
|
|
87 |
"Otherwise, replace underscores with :="
|
|
88 |
src := src copyReplaceAll: '_' with: ':='.
|
|
89 |
ts := self timeStamp.
|
|
90 |
ts = '' ifTrue: [ts := nil].
|
|
91 |
self actualClass
|
|
92 |
compile: src
|
|
93 |
classified: ClassOrganizer default
|
|
94 |
withStamp: ts
|
|
95 |
notifying: nil.
|
|
96 |
|
|
97 |
^true
|
|
98 |
! !
|
|
99 |
|
|
100 |
!MethodReference methodsFor:'*monticello'!
|
|
101 |
|
|
102 |
asMethodDefinition
|
|
103 |
^ MCMethodDefinition forMethodReference: self
|
|
104 |
!
|
|
105 |
|
|
106 |
compiledMethod
|
|
107 |
^ self actualClass compiledMethodAt: methodSymbol
|
|
108 |
!
|
|
109 |
|
|
110 |
isLocalSelector
|
944
|
111 |
^self actualClass
|
|
112 |
"/ includesLocalSelector: self methodSymbol
|
|
113 |
implements: self methodSymbol
|
393
|
114 |
!
|
|
115 |
|
|
116 |
source
|
|
117 |
^ (self actualClass sourceCodeAt: methodSymbol) asString asStringWithSqueakLineEndings
|
|
118 |
|
|
119 |
"Modified: / 12-09-2010 / 16:06:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
120 |
!
|
|
121 |
|
|
122 |
timeStamp
|
|
123 |
^ self compiledMethod timeStamp
|
|
124 |
! !
|
|
125 |
|
|
126 |
!MethodReference methodsFor:'*packageinfo-base'!
|
|
127 |
|
|
128 |
sourceCode
|
|
129 |
^ self actualClass sourceCodeAt: methodSymbol
|
|
130 |
! !
|
|
131 |
|
|
132 |
!MethodReference methodsFor:'comparisons'!
|
|
133 |
|
|
134 |
<= anotherMethodReference
|
|
135 |
|
|
136 |
classSymbol < anotherMethodReference classSymbol ifTrue: [^true].
|
|
137 |
classSymbol > anotherMethodReference classSymbol ifTrue: [^false].
|
|
138 |
classIsMeta = anotherMethodReference classIsMeta ifFalse: [^classIsMeta not].
|
|
139 |
^methodSymbol <= anotherMethodReference methodSymbol
|
|
140 |
!
|
|
141 |
|
|
142 |
= anotherMethodReference
|
|
143 |
"Answer whether the receiver and the argument represent the
|
|
144 |
same object."
|
|
145 |
^ self species == anotherMethodReference species
|
|
146 |
and: [self classSymbol = anotherMethodReference classSymbol]
|
|
147 |
and: [self classIsMeta = anotherMethodReference classIsMeta]
|
|
148 |
and: [self methodSymbol = anotherMethodReference methodSymbol]
|
|
149 |
!
|
|
150 |
|
|
151 |
hash
|
|
152 |
"Answer a SmallInteger whose value is related to the receiver's
|
|
153 |
identity."
|
|
154 |
^ (self species hash bitXor: self classSymbol hash)
|
|
155 |
bitXor: self methodSymbol hash
|
|
156 |
! !
|
|
157 |
|
|
158 |
!MethodReference methodsFor:'queries'!
|
|
159 |
|
|
160 |
asStringOrText
|
|
161 |
|
|
162 |
^stringVersion
|
|
163 |
!
|
|
164 |
|
|
165 |
category
|
|
166 |
^ category ifNil: [category := self actualClass organization categoryOfElement: methodSymbol]
|
|
167 |
!
|
|
168 |
|
|
169 |
classIsMeta
|
|
170 |
|
|
171 |
^classIsMeta
|
|
172 |
!
|
|
173 |
|
|
174 |
classSymbol
|
|
175 |
|
|
176 |
^classSymbol
|
|
177 |
!
|
|
178 |
|
|
179 |
isValid
|
|
180 |
"Answer whether the receiver represents a current selector or Comment"
|
|
181 |
|
|
182 |
| aClass |
|
|
183 |
methodSymbol isDoIt ifTrue: [^ false].
|
|
184 |
(aClass := self actualClass) ifNil: [^ false].
|
|
185 |
^ (aClass includesSelector: methodSymbol) or:
|
|
186 |
[methodSymbol == #Comment]
|
|
187 |
!
|
|
188 |
|
|
189 |
methodSymbol
|
|
190 |
|
|
191 |
^methodSymbol
|
|
192 |
!
|
|
193 |
|
|
194 |
printOn: aStream
|
|
195 |
"Print the receiver on a stream"
|
|
196 |
|
|
197 |
"super printOn: aStream."
|
|
198 |
aStream nextPutAll: '"REF" ', self actualClass name, ' >> #', methodSymbol
|
|
199 |
|
|
200 |
"Modified: / 12-09-2010 / 19:03:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
201 |
!
|
|
202 |
|
|
203 |
sourceString
|
|
204 |
^ (self actualClass sourceCodeAt: self methodSymbol) asString
|
|
205 |
! !
|
|
206 |
|
|
207 |
!MethodReference methodsFor:'setting'!
|
|
208 |
|
|
209 |
setClass: aClass methodSymbol: methodSym stringVersion: aString
|
|
210 |
|
|
211 |
classSymbol := aClass theNonMetaClass name.
|
|
212 |
classIsMeta := aClass isMeta.
|
|
213 |
methodSymbol := methodSym.
|
|
214 |
stringVersion := aString.
|
|
215 |
!
|
|
216 |
|
|
217 |
setClassAndSelectorIn: csBlock
|
|
218 |
|
|
219 |
^csBlock value: self actualClass value: methodSymbol
|
|
220 |
!
|
|
221 |
|
|
222 |
setClassSymbol: classSym classIsMeta: isMeta methodSymbol: methodSym stringVersion: aString
|
|
223 |
|
|
224 |
classSymbol := classSym.
|
|
225 |
classIsMeta := isMeta.
|
|
226 |
methodSymbol := methodSym.
|
|
227 |
stringVersion := aString.
|
|
228 |
!
|
|
229 |
|
|
230 |
setStandardClass: aClass methodSymbol: methodSym
|
|
231 |
|
|
232 |
classSymbol := aClass theNonMetaClass name.
|
|
233 |
classIsMeta := aClass isMeta.
|
|
234 |
methodSymbol := methodSym.
|
|
235 |
stringVersion := aClass name , ' ' , methodSym.
|
|
236 |
! !
|
|
237 |
|
|
238 |
!MethodReference methodsFor:'string version'!
|
|
239 |
|
|
240 |
category: aString
|
|
241 |
|
|
242 |
category := aString
|
|
243 |
!
|
|
244 |
|
|
245 |
stringVersion
|
|
246 |
|
|
247 |
^stringVersion
|
|
248 |
!
|
|
249 |
|
|
250 |
stringVersion: aString
|
|
251 |
|
|
252 |
stringVersion := aString
|
|
253 |
! !
|
|
254 |
|
|
255 |
!MethodReference class methodsFor:'documentation'!
|
|
256 |
|
|
257 |
version
|
944
|
258 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MethodReference.st,v 1.2 2014-12-21 13:08:18 cg Exp $'
|
393
|
259 |
!
|
|
260 |
|
|
261 |
version_CVS
|
944
|
262 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MethodReference.st,v 1.2 2014-12-21 13:08:18 cg Exp $'
|
393
|
263 |
!
|
|
264 |
|
|
265 |
version_SVN
|
944
|
266 |
^ '$Id: MethodReference.st,v 1.2 2014-12-21 13:08:18 cg Exp $'
|
393
|
267 |
! !
|
944
|
268 |
|