-
Notifications
You must be signed in to change notification settings - Fork 65
/
MethodReference.class.st
282 lines (223 loc) · 7.24 KB
/
MethodReference.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
"
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 by Tools.
Instance Variables
classIsMeta: Boolean class vs. instance
classSymbol: Symbol for method's class (without class keyword if meta)
methodSymbol: Symbol for method's selector
stringVersion: 'Class>>selector:' format
"
Class {
#name : #MethodReference,
#superclass : #Object,
#instVars : [
'classSymbol',
'classIsMeta',
'methodSymbol',
'stringVersion',
'category',
'environment'
],
#classVars : [
'InvalidReference'
],
#category : #VMMakerLoadingDependencies
}
{ #category : #'instance creation' }
MethodReference class >> class: aClass selector: aSelector [
^ self class: aClass selector: aSelector environment: aClass environment.
]
{ #category : #'instance creation' }
MethodReference class >> class: aClass selector: aSelector environment: anEnvironment [
^ self new setStandardClass: aClass methodSymbol: aSelector environment: anEnvironment.
]
{ #category : #'class initialization' }
MethodReference class >> cleanUp: aggressive [
aggressive ifTrue: [InvalidReference := nil].
]
{ #category : #'instance creation' }
MethodReference class >> invalid [
"Creates an invalid method reference to avoid the usage of nil."
^ InvalidReference ifNil: [
InvalidReference := self new
setClassSymbol: #NonExistentClass
classIsMeta: false
methodSymbol: #nonExistentSelector
stringVersion: '<The Invalid Method Reference>']
]
{ #category : #comparing }
MethodReference >> <= anotherMethodReference [
classSymbol < anotherMethodReference classSymbol ifTrue: [^true].
classSymbol > anotherMethodReference classSymbol ifTrue: [^false].
classIsMeta = anotherMethodReference classIsMeta ifFalse: [^classIsMeta not].
^methodSymbol <= anotherMethodReference methodSymbol
]
{ #category : #comparing }
MethodReference >> = anotherMethodReference [
"Answer whether the receiver and the argument represent the
same object."
^ self species == anotherMethodReference species
and: [self classSymbol = anotherMethodReference classSymbol
and: [self classIsMeta = anotherMethodReference classIsMeta
and: [self methodSymbol = anotherMethodReference methodSymbol
and: [self environment == anotherMethodReference environment]]]]
]
{ #category : #accessing }
MethodReference >> actualClass [
^self environment at: classSymbol ifPresent: [ :actualClass |
classIsMeta
ifTrue: [ actualClass classSide ]
ifFalse: [ actualClass ] ]
]
{ #category : #converting }
MethodReference >> asCodeReference [
^ self
]
{ #category : #converting }
MethodReference >> asString [
^(stringVersion ifNil: [ self stringVersionDefault ]) asString
]
{ #category : #converting }
MethodReference >> asStringOrText [
^stringVersion ifNil: [ self stringVersionDefault ]
]
{ #category : #converting }
MethodReference >> asValid [
"Sometimes persistent MethodReferences may become stale after a refactoring which moved some methods to a superclass. This method answers the new valid MethodReference if that happened."
^ self isValid
ifTrue: [ self ]
ifFalse:
[ | cm |
cm := self actualClass lookupSelector: self selector.
cm ifNotNil: [ cm methodReference ] ]
]
{ #category : #accessing }
MethodReference >> category [
"Answers the class category (cached for reuse via MC and other tools)"
^ category ifNil: [category := self actualClass organization categoryOfElement: methodSymbol]
]
{ #category : #'initialize-release' }
MethodReference >> category: aSymbol [
category := aSymbol
]
{ #category : #testing }
MethodReference >> classIsMeta [
^classIsMeta
]
{ #category : #accessing }
MethodReference >> classSymbol [
^classSymbol
]
{ #category : #accessing }
MethodReference >> compiledMethod [
^self actualClass compiledMethodAt: methodSymbol ifAbsent: nil
]
{ #category : #accessing }
MethodReference >> environment [
^ environment ifNil: [
"We will probably have MethodReferences already instantiated when this commit lands. We lazily move these over to the new, Environment aware, order of things."
environment := Smalltalk globals].
]
{ #category : #comparing }
MethodReference >> hash [
"Answer a SmallInteger whose value is related to the receiver's
identity."
^ (self species hash bitXor: self classSymbol hash)
bitXor: self methodSymbol hash
]
{ #category : #testing }
MethodReference >> isClassReference [
^ false
]
{ #category : #testing }
MethodReference >> isMethodReference [
^ true
]
{ #category : #testing }
MethodReference >> isValid [
"Answer whether the receiver represents a current selector or Comment"
| aClass |
methodSymbol isDoIt ifTrue: [^ false].
(aClass := self actualClass) ifNil: [^ false].
^ (aClass includesSelector: methodSymbol) or:
[methodSymbol == #Comment]
]
{ #category : #accessing }
MethodReference >> methodSymbol [
^methodSymbol
]
{ #category : #printing }
MethodReference >> printOn: aStream [
| actualClass |
"Print the receiver on a stream"
actualClass := classSymbol asString.
classIsMeta ifTrue: [actualClass := actualClass, ' class'].
super printOn: aStream.
aStream nextPutAll: ' ', actualClass, ' >> ', methodSymbol printString.
]
{ #category : #accessing }
MethodReference >> selector [
^methodSymbol
]
{ #category : #'initialize-release' }
MethodReference >> setClass: aClass methodSymbol: methodSym stringVersion: aString [
classSymbol := aClass theNonMetaClass name.
classIsMeta := aClass isMeta.
methodSymbol := methodSym.
environment := aClass environment.
stringVersion := aString.
]
{ #category : #'initialize-release' }
MethodReference >> setClassAndSelectorIn: csBlock [
^csBlock value: self actualClass value: methodSymbol
]
{ #category : #'initialize-release' }
MethodReference >> setClassSymbol: classSym classIsMeta: isMeta methodSymbol: methodSym stringVersion: aString [
classSymbol := classSym.
classIsMeta := isMeta.
methodSymbol := methodSym.
stringVersion := aString.
]
{ #category : #'initialize-release' }
MethodReference >> setStandardClass: aClass methodSymbol: methodSym [
classSymbol := aClass theNonMetaClass name.
environment := aClass environment.
classIsMeta := aClass isMeta.
methodSymbol := methodSym.
stringVersion := nil.
]
{ #category : #'initialize-release' }
MethodReference >> setStandardClass: aClass methodSymbol: aSelector environment: anEnvironment [
classSymbol := aClass instanceSide name.
classIsMeta := aClass isMeta.
methodSymbol := aSelector.
environment := anEnvironment.
stringVersion := nil
]
{ #category : #accessing }
MethodReference >> source [
^ (self actualClass sourceCodeAt: methodSymbol) asString withSqueakLineEndings
]
{ #category : #accessing }
MethodReference >> sourceCode [
^ self actualClass sourceCodeAt: self methodSymbol
]
{ #category : #accessing }
MethodReference >> sourceString [
^ self sourceCode asString
]
{ #category : #accessing }
MethodReference >> stringVersion [
^stringVersion ifNil: [self asStringOrText]
]
{ #category : #accessing }
MethodReference >> stringVersion: aString [
stringVersion := aString
]
{ #category : #accessing }
MethodReference >> stringVersionDefault [
^classSymbol, (classIsMeta ifTrue: [ ' class ' ] ifFalse: [' ']), methodSymbol
]
{ #category : #accessing }
MethodReference >> timeStamp [
^ self compiledMethod timeStamp
]