author | Claus Gittinger <cg@exept.de> |
Wed, 09 May 2018 09:58:25 +0200 | |
changeset 1046 | 2c62588b53ed |
parent 1044 | af7f15850437 |
permissions | -rw-r--r-- |
48 | 1 |
"{ Package: 'stx:goodies/monticello' }" |
2 |
||
968 | 3 |
"{ NameSpace: Smalltalk }" |
4 |
||
48 | 5 |
MCDefinition subclass:#MCClassDefinition |
214 | 6 |
instanceVariableNames:'name superclassName variables category type comment commentStamp |
894
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
7 |
traitComposition classTraitComposition' |
48 | 8 |
classVariableNames:'' |
9 |
poolDictionaries:'' |
|
610 | 10 |
category:'SCM-Monticello-Modeling' |
48 | 11 |
! |
12 |
||
13 |
||
14 |
!MCClassDefinition class methodsFor:'instance creation'! |
|
15 |
||
16 |
name: nameString |
|
17 |
superclassName: superclassString |
|
18 |
category: categoryString |
|
19 |
instVarNames: ivarArray |
|
20 |
classVarNames: cvarArray |
|
21 |
poolDictionaryNames: poolArray |
|
22 |
classInstVarNames: civarArray |
|
23 |
type: typeSymbol |
|
24 |
comment: commentString |
|
25 |
commentStamp: stampString |
|
26 |
^ self instanceLike: |
|
27 |
(self new initializeWithName: nameString |
|
28 |
superclassName: superclassString |
|
214 | 29 |
traitComposition: '{}' |
30 |
classTraitComposition: '{}' |
|
31 |
category: categoryString |
|
32 |
instVarNames: ivarArray |
|
33 |
classVarNames: cvarArray |
|
34 |
poolDictionaryNames: poolArray |
|
35 |
classInstVarNames: civarArray |
|
36 |
type: typeSymbol |
|
37 |
comment: commentString |
|
38 |
commentStamp: stampString) |
|
39 |
! |
|
40 |
||
41 |
name: nameString |
|
42 |
superclassName: superclassString |
|
43 |
traitComposition: traitCompositionString |
|
44 |
classTraitComposition: classTraitCompositionString |
|
45 |
category: categoryString |
|
46 |
instVarNames: ivarArray |
|
47 |
classVarNames: cvarArray |
|
48 |
poolDictionaryNames: poolArray |
|
49 |
classInstVarNames: civarArray |
|
50 |
type: typeSymbol |
|
51 |
comment: commentString |
|
52 |
commentStamp: stampString |
|
53 |
||
54 |
^ self instanceLike: |
|
55 |
(self new initializeWithName: nameString |
|
56 |
superclassName: superclassString |
|
57 |
traitComposition: traitCompositionString |
|
58 |
classTraitComposition: classTraitCompositionString |
|
48 | 59 |
category: categoryString |
60 |
instVarNames: ivarArray |
|
61 |
classVarNames: cvarArray |
|
62 |
poolDictionaryNames: poolArray |
|
63 |
classInstVarNames: civarArray |
|
64 |
type: typeSymbol |
|
65 |
comment: commentString |
|
66 |
commentStamp: stampString) |
|
67 |
! ! |
|
68 |
||
69 |
!MCClassDefinition class methodsFor:'obsolete'! |
|
70 |
||
71 |
name: nameString |
|
72 |
superclassName: superclassString |
|
73 |
category: categoryString |
|
74 |
instVarNames: ivarArray |
|
75 |
classVarNames: cvarArray |
|
76 |
poolDictionaryNames: poolArray |
|
77 |
classInstVarNames: civarArray |
|
78 |
comment: commentString |
|
79 |
^ self name: nameString |
|
80 |
superclassName: superclassString |
|
81 |
category: categoryString |
|
82 |
instVarNames: ivarArray |
|
83 |
classVarNames: cvarArray |
|
84 |
poolDictionaryNames: poolArray |
|
85 |
classInstVarNames: civarArray |
|
86 |
type: #normal |
|
87 |
comment: commentString |
|
214 | 88 |
|
48 | 89 |
! |
90 |
||
91 |
name: nameString |
|
92 |
superclassName: superclassString |
|
93 |
category: categoryString |
|
94 |
instVarNames: ivarArray |
|
95 |
classVarNames: cvarArray |
|
96 |
poolDictionaryNames: poolArray |
|
97 |
classInstVarNames: civarArray |
|
98 |
type: typeSymbol |
|
99 |
comment: commentString |
|
100 |
^ self |
|
101 |
name: nameString |
|
102 |
superclassName: superclassString |
|
103 |
category: categoryString |
|
104 |
instVarNames: ivarArray |
|
105 |
classVarNames: cvarArray |
|
106 |
poolDictionaryNames: poolArray |
|
107 |
classInstVarNames: civarArray |
|
108 |
type: typeSymbol |
|
109 |
comment: commentString |
|
110 |
commentStamp: nil |
|
111 |
! |
|
112 |
||
113 |
name: nameString |
|
114 |
superclassName: superclassString |
|
115 |
category: categoryString |
|
116 |
instVarNames: ivarArray |
|
117 |
comment: commentString |
|
118 |
^ self name: nameString |
|
119 |
superclassName: superclassString |
|
120 |
category: categoryString |
|
121 |
instVarNames: ivarArray |
|
122 |
classVarNames: #() |
|
123 |
poolDictionaryNames: #() |
|
124 |
classInstVarNames: #() |
|
125 |
comment: commentString |
|
214 | 126 |
|
48 | 127 |
! ! |
128 |
||
129 |
!MCClassDefinition methodsFor:'accessing'! |
|
130 |
||
131 |
actualClass |
|
132 |
^Smalltalk classNamed: self className |
|
133 |
! |
|
134 |
||
135 |
category |
|
136 |
^ category |
|
137 |
! |
|
138 |
||
848
b86a6f467667
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
766
diff
changeset
|
139 |
category:something |
b86a6f467667
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
766
diff
changeset
|
140 |
category := something. |
b86a6f467667
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
766
diff
changeset
|
141 |
! |
b86a6f467667
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
766
diff
changeset
|
142 |
|
48 | 143 |
classInstVarNames |
144 |
^ self selectVariables: #isClassInstanceVariable |
|
145 |
! |
|
146 |
||
521 | 147 |
classInstVarNames:civarArray |
148 |
self addVariables: civarArray ofType: MCClassInstanceVariableDefinition. |
|
149 |
||
150 |
"Created: / 25-11-2011 / 17:42:34 / cg" |
|
151 |
! |
|
152 |
||
48 | 153 |
className |
154 |
^ name |
|
155 |
! |
|
156 |
||
876 | 157 |
className: aString |
158 |
name := aString |
|
159 |
||
160 |
"Created: / 31-05-2013 / 10:33:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
161 |
! |
|
162 |
||
214 | 163 |
classTraitComposition |
164 |
^classTraitComposition |
|
165 |
! |
|
166 |
||
167 |
classTraitCompositionString |
|
168 |
^self classTraitComposition ifNil: ['{}']. |
|
169 |
! |
|
170 |
||
48 | 171 |
classVarNames |
172 |
^ self selectVariables: #isClassVariable |
|
173 |
! |
|
174 |
||
175 |
comment |
|
214 | 176 |
^ comment ? '' |
177 |
||
178 |
"Modified: / 12-09-2010 / 17:07:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
48 | 179 |
! |
180 |
||
181 |
commentStamp |
|
182 |
^ commentStamp |
|
183 |
! |
|
184 |
||
185 |
description |
|
186 |
^ Array with: name |
|
214 | 187 |
|
48 | 188 |
! |
189 |
||
190 |
instVarNames |
|
191 |
^ self selectVariables: #isInstanceVariable |
|
192 |
! |
|
193 |
||
470 | 194 |
installedClass |
195 |
^Smalltalk classNamed: self installedClassName |
|
196 |
||
197 |
"Created: / 07-09-2011 / 13:33:10 / cg" |
|
198 |
! |
|
199 |
||
200 |
installedClassName |
|
894
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
201 |
| installedClassName | |
470 | 202 |
|
894
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
203 |
installedClassName := self objectAttributeAt: #installedClassName. |
470 | 204 |
^ installedClassName ? name |
205 |
||
894
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
206 |
"Created: / 07-09-2011 / 13:36:37 / cg" |
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
207 |
"Modified: / 12-08-2013 / 01:49:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
208 |
! |
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
209 |
|
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
210 |
installedClassName:aString |
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
211 |
self objectAttributeAt: #installedClassName put: aString. |
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
212 |
|
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
213 |
"Modified: / 12-08-2013 / 01:37:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
470 | 214 |
! |
215 |
||
48 | 216 |
poolDictionaries |
217 |
^ self selectVariables: #isPoolImport |
|
218 |
! |
|
219 |
||
220 |
selectVariables: aSelector |
|
713 | 221 |
variables isNil ifTrue:[^#()]. |
222 |
^ variables select: [:v | v perform: aSelector] thenCollect: [:v | v name] |
|
48 | 223 |
! |
224 |
||
225 |
sortKey |
|
226 |
^ self className |
|
227 |
! |
|
228 |
||
229 |
superclassName |
|
230 |
^ superclassName |
|
231 |
! |
|
232 |
||
897
76481ea7aaba
Bugfix: MCClassDefinition.superclassName must be a symbol.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
894
diff
changeset
|
233 |
superclassName:aStringOrSymbol |
76481ea7aaba
Bugfix: MCClassDefinition.superclassName must be a symbol.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
894
diff
changeset
|
234 |
superclassName := aStringOrSymbol asSymbol. |
76481ea7aaba
Bugfix: MCClassDefinition.superclassName must be a symbol.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
894
diff
changeset
|
235 |
|
76481ea7aaba
Bugfix: MCClassDefinition.superclassName must be a symbol.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
894
diff
changeset
|
236 |
"Modified: / 20-09-2013 / 00:13:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
848
b86a6f467667
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
766
diff
changeset
|
237 |
! |
b86a6f467667
More support Squeak/Pharo interoperability - part 1:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
766
diff
changeset
|
238 |
|
214 | 239 |
traitComposition |
240 |
^traitComposition |
|
241 |
! |
|
242 |
||
243 |
traitCompositionString |
|
244 |
^self traitComposition ifNil: ['{}']. |
|
245 |
! |
|
246 |
||
48 | 247 |
type |
248 |
^ type |
|
249 |
! |
|
250 |
||
251 |
variables |
|
252 |
^ variables |
|
253 |
! ! |
|
254 |
||
255 |
!MCClassDefinition methodsFor:'annotations'! |
|
256 |
||
257 |
printAnnotations: requests on: aStream |
|
258 |
"Add a string for an annotation pane, trying to fulfill the annotation requests. |
|
259 |
These might include anything that |
|
260 |
Preferences defaultAnnotationRequests |
|
261 |
might return. Which includes anything in |
|
262 |
Preferences annotationInfo |
|
263 |
To edit these, use:" |
|
264 |
"Preferences editAnnotations" |
|
265 |
||
266 |
requests do: [ :aRequest | |
|
267 |
aRequest == #requirements ifTrue: [ |
|
268 |
self requirements do: [ :req | aStream nextPutAll: req ] separatedBy: [ aStream space ]] |
|
269 |
] separatedBy: [ aStream space ]. |
|
270 |
! ! |
|
271 |
||
272 |
!MCClassDefinition methodsFor:'comparing'! |
|
273 |
||
274 |
hash |
|
275 |
| hash | |
|
214 | 276 |
hash := String stringHash: name initialHash: 0. |
277 |
hash := String stringHash: superclassName initialHash: hash. |
|
278 |
hash := String stringHash: self traitCompositionString initialHash: hash. |
|
279 |
hash := String stringHash: self classTraitComposition asString initialHash: hash. |
|
280 |
hash := String stringHash: (category ifNil: ['']) initialHash: hash. |
|
281 |
hash := String stringHash: type initialHash: hash. |
|
48 | 282 |
variables do: [ |
283 |
:v | |
|
214 | 284 |
hash := String stringHash: v name initialHash: hash. |
48 | 285 |
]. |
286 |
^ hash |
|
287 |
! |
|
288 |
||
289 |
provisions |
|
290 |
^ Array with: name |
|
291 |
! |
|
292 |
||
293 |
requirements |
|
294 |
^ (Array with: superclassName), self poolDictionaries |
|
295 |
! ! |
|
296 |
||
214 | 297 |
!MCClassDefinition methodsFor:'converting'! |
298 |
||
1036 | 299 |
addChangesTo:aChangeSet |
300 |
aChangeSet add:(self asChange). |
|
301 |
comment notEmptyOrNil ifTrue:[ |
|
302 |
aChangeSet add:(ClassCommentChange new className:name comment:comment). |
|
303 |
]. |
|
304 |
! |
|
305 |
||
214 | 306 |
asChange |
565 | 307 |
|instVarNamesString classVarNamesString classInstVarNamesString poolDictionariesString |
308 |
definitionSelector| |
|
214 | 309 |
|
565 | 310 |
instVarNamesString := self instVarNames asStringWith:' '. |
311 |
classVarNamesString := self classVarNames asStringWith:' '. |
|
312 |
classInstVarNamesString := self classInstVarNames asStringWith:' '. |
|
313 |
poolDictionariesString := self poolDictionaries asStringWith:' '. |
|
314 |
||
315 |
definitionSelector := #'subclass:instanceVariableNames:classVariableNames:poolDictionaries:category:'. |
|
713 | 316 |
(type notNil and:[type ~~ #normal]) ifTrue:[ |
565 | 317 |
type == #variable ifTrue:[ |
318 |
definitionSelector := #'variableSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:'. |
|
319 |
] ifFalse:[ |
|
320 |
type == #bytes ifTrue:[ |
|
321 |
definitionSelector := #'variableByteSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:'. |
|
322 |
] ifFalse:[ |
|
323 |
type == #words ifTrue:[ |
|
324 |
"for Squeak compatibility: that is long-words !!!!!!!!" |
|
325 |
definitionSelector := #'variableLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:'. |
|
326 |
] ifFalse:[ |
|
327 |
type == #compiledMethod ifTrue:[ |
|
328 |
definitionSelector := #'subclass:instanceVariableNames:classVariableNames:poolDictionaries:category:'. |
|
329 |
] ifFalse:[ |
|
1044 | 330 |
type == #weak ifTrue:[ |
331 |
definitionSelector := #'variableWeakSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:'. |
|
332 |
] ifFalse:[ |
|
565 | 333 |
self halt:'unhandled class-type'. |
1044 | 334 |
] |
565 | 335 |
] |
336 |
] |
|
337 |
] |
|
338 |
] |
|
339 |
]. |
|
976 | 340 |
|
341 |
"/ does not work yet |
|
342 |
"/ classInstVarNamesString notEmptyOrNil ifTrue:[ |
|
343 |
"/ definitionSelector := (definitionSelector , 'classInstanceVariableNames:') asSymbol |
|
344 |
"/ ]. |
|
345 |
||
214 | 346 |
^ClassDefinitionChange new |
347 |
mcDefinition: self; |
|
565 | 348 |
definitionSelector: definitionSelector; |
214 | 349 |
className: name; |
350 |
superClassName: superclassName; |
|
968 | 351 |
instanceVariableString: instVarNamesString ; |
352 |
classVariableString: classVarNamesString ; |
|
969 | 353 |
classInstanceVariableString: classInstVarNamesString ; |
565 | 354 |
poolDictionaries: poolDictionariesString ; |
214 | 355 |
category: category; |
356 |
yourself |
|
357 |
||
358 |
"Created: / 13-10-2010 / 17:11:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
359 |
"Modified: / 08-11-2010 / 17:56:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
565 | 360 |
"Modified: / 13-06-2012 / 12:57:38 / cg" |
214 | 361 |
! ! |
362 |
||
48 | 363 |
!MCClassDefinition methodsFor:'initializing'! |
364 |
||
365 |
addVariables: aCollection ofType: aClass |
|
366 |
variables addAll: (aCollection collect: [:var | aClass name: var asString]). |
|
367 |
! |
|
368 |
||
369 |
defaultCommentStamp |
|
370 |
^ String new |
|
371 |
||
372 |
"The version below avoids stomping on stamps already in the image |
|
373 |
||
374 |
^ (Smalltalk at: name ifPresent: [:c | c organization commentStamp]) |
|
375 |
ifNil: [''] |
|
376 |
" |
|
214 | 377 |
|
48 | 378 |
! ! |
379 |
||
380 |
!MCClassDefinition methodsFor:'installing'! |
|
381 |
||
382 |
createClass |
|
470 | 383 |
"cg: changed to honor any nameSpace query override" |
384 |
||
385 |
| env superClass class installedSuperclassName| |
|
386 |
||
387 |
env := MCStXNamespaceQuery query ? Smalltalk. |
|
388 |
superClass := env at: superclassName. |
|
389 |
(superClass isNil and:[env ~~ Smalltalk]) ifTrue:[ |
|
390 |
superClass := Smalltalk at: superclassName. |
|
391 |
]. |
|
392 |
||
214 | 393 |
"Create class if not exists" |
470 | 394 |
superClass isNil ifTrue:[ |
395 |
installedSuperclassName := (env == Smalltalk) |
|
396 |
ifTrue:[ superclassName ] |
|
397 |
ifFalse:[ env name ,'::',superclassName]. |
|
398 |
superClass := Class undeclared: installedSuperclassName |
|
399 |
]. |
|
934
6a56a913c6b0
Fixed MCClassDefinition>>#createClass: load superclass before creating class.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
897
diff
changeset
|
400 |
superClass isLoaded ifFalse:[ superClass autoload ]. |
470 | 401 |
|
402 |
"/ env := superClass environment. |
|
214 | 403 |
|
404 |
class := (ClassBuilder new) |
|
156 | 405 |
name: name |
470 | 406 |
inEnvironment: env |
156 | 407 |
subclassOf: superClass |
408 |
type: type |
|
409 |
instanceVariableNames: self instanceVariablesString |
|
410 |
classVariableNames: self classVariablesString |
|
411 |
poolDictionaries: self sharedPoolsString |
|
412 |
category: category. |
|
470 | 413 |
|
894
0c981690a584
Removed instvar installedClassName and make it an object attribute.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
876
diff
changeset
|
414 |
self installedClassName:class name. |
470 | 415 |
|
214 | 416 |
self traitComposition ifNotNil: [ |
417 |
class setTraitComposition: (Compiler |
|
418 |
evaluate: self traitComposition) asTraitComposition ]. |
|
419 |
self classTraitComposition ifNotNil: [ |
|
420 |
class class setTraitComposition: (Compiler |
|
421 |
evaluate: self classTraitComposition) asTraitComposition ]. |
|
422 |
^class. |
|
156 | 423 |
|
470 | 424 |
"Modified (comment): / 07-09-2011 / 13:32:38 / cg" |
934
6a56a913c6b0
Fixed MCClassDefinition>>#createClass: load superclass before creating class.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
897
diff
changeset
|
425 |
"Modified: / 07-10-2014 / 00:20:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
48 | 426 |
! |
427 |
||
428 |
load |
|
214 | 429 |
| class | |
430 |
||
470 | 431 |
(class := self createClass) notNil ifTrue:[ |
432 |
class class instanceVariableNames: self classInstanceVariablesString. |
|
433 |
self hasComment ifTrue: [class classComment: comment stamp: commentStamp] |
|
434 |
]. |
|
214 | 435 |
class package: MCStXPackageQuery query. |
436 |
||
437 |
"Modified: / 14-09-2010 / 22:10:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
470 | 438 |
"Modified: / 07-09-2011 / 13:01:53 / cg" |
214 | 439 |
! |
440 |
||
441 |
stringForSortedVariablesOfType: aSymbol |
|
442 |
^ String streamContents: |
|
443 |
[:stream | |
|
444 |
(self selectVariables: aSymbol) asSortedCollection |
|
445 |
do: [:ea | stream nextPutAll: ea] |
|
446 |
separatedBy: [stream space]] |
|
48 | 447 |
! |
448 |
||
449 |
stringForVariablesOfType: aSymbol |
|
450 |
^ String streamContents: |
|
451 |
[:stream | |
|
452 |
(self selectVariables: aSymbol) |
|
453 |
do: [:ea | stream nextPutAll: ea] |
|
454 |
separatedBy: [stream space]] |
|
455 |
! |
|
456 |
||
457 |
unload |
|
458 |
Smalltalk removeClassNamed: name |
|
459 |
! ! |
|
460 |
||
461 |
!MCClassDefinition methodsFor:'printing'! |
|
462 |
||
463 |
classInstanceVariablesString |
|
464 |
^ self stringForVariablesOfType: #isClassInstanceVariable |
|
465 |
! |
|
466 |
||
467 |
classVariablesString |
|
214 | 468 |
^ self stringForSortedVariablesOfType: #isClassVariable |
48 | 469 |
! |
470 |
||
471 |
definitionString |
|
472 |
^ String streamContents: [:stream | self printDefinitionOn: stream] |
|
473 |
! |
|
474 |
||
475 |
instanceVariablesString |
|
476 |
^ self stringForVariablesOfType: #isInstanceVariable |
|
477 |
! |
|
478 |
||
479 |
kindOfSubclass |
|
214 | 480 |
type = #normal ifTrue: [^ ' subclass:']. |
481 |
type = #words ifTrue: [^ ' variableWordSubclass:']. |
|
482 |
type = #variable ifTrue: [^ ' variableSubclass:']. |
|
483 |
type = #bytes ifTrue: [^ ' variableByteSubclass:']. |
|
484 |
type = #weak ifTrue: [^ ' weakSubclass:' ]. |
|
485 |
type = #compiledMethod ifTrue: [^ ' variableByteSubclass:' ]. |
|
486 |
self error: 'Unrecognized class type' |
|
487 |
||
488 |
"Modified: / 11-09-2010 / 18:13:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
48 | 489 |
! |
490 |
||
491 |
printDefinitionOn: stream |
|
766 | 492 |
|clsName| |
493 |
||
214 | 494 |
stream |
495 |
nextPutAll: self superclassName; |
|
766 | 496 |
nextPutAll: self kindOfSubclass. |
497 |
((clsName := self className) includes:$_) ifTrue:[ |
|
498 |
stream |
|
499 |
nextPutAll: '#''' ; |
|
214 | 500 |
nextPutAll: self className; |
766 | 501 |
nextPutAll: '''' . |
502 |
] ifFalse:[ |
|
503 |
stream |
|
504 |
nextPut: $#; |
|
505 |
nextPutAll: self className. |
|
506 |
]. |
|
507 |
stream |
|
214 | 508 |
cr; tab. |
509 |
self hasTraitComposition ifTrue: [ |
|
510 |
stream |
|
511 |
nextPutAll: 'uses: '; |
|
512 |
nextPutAll: self traitCompositionString; |
|
513 |
cr; tab ]. |
|
514 |
stream |
|
515 |
nextPutAll: 'instanceVariableNames:'; |
|
516 |
store: self instanceVariablesString; |
|
517 |
cr; tab; |
|
518 |
nextPutAll: 'classVariableNames:'; |
|
519 |
store: self classVariablesString; |
|
520 |
cr; tab; |
|
521 |
nextPutAll: 'poolDictionaries:'; |
|
522 |
store: self sharedPoolsString; |
|
523 |
cr; tab; |
|
524 |
nextPutAll: 'category:'; |
|
525 |
store: self category asString |
|
526 |
||
527 |
"Modified: / 11-09-2010 / 18:11:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
48 | 528 |
! |
529 |
||
530 |
sharedPoolsString |
|
214 | 531 |
^ self stringForSortedVariablesOfType: #isPoolImport |
48 | 532 |
! |
533 |
||
534 |
source |
|
535 |
^ self definitionString |
|
536 |
! |
|
537 |
||
538 |
summary |
|
539 |
^ name |
|
540 |
! ! |
|
541 |
||
542 |
!MCClassDefinition methodsFor:'serializing'! |
|
543 |
||
544 |
initializeWithName: nameString |
|
545 |
superclassName: superclassString |
|
546 |
category: categoryString |
|
547 |
instVarNames: ivarArray |
|
548 |
classVarNames: cvarArray |
|
549 |
poolDictionaryNames: poolArray |
|
550 |
classInstVarNames: civarArray |
|
551 |
type: typeSymbol |
|
552 |
comment: commentString |
|
553 |
commentStamp: stampStringOrNil |
|
214 | 554 |
name := nameString asSymbol. |
555 |
superclassName := superclassString ifNil: ['nil'] ifNotNil: [superclassString asSymbol]. |
|
556 |
category := categoryString. |
|
557 |
name = #CompiledMethod ifTrue: [type := #compiledMethod] ifFalse: [type := typeSymbol]. |
|
558 |
comment := (commentString ? '') asStringWithSqueakLineEndings. |
|
559 |
commentStamp := stampStringOrNil ifNil: [self defaultCommentStamp]. |
|
560 |
variables := OrderedCollection new. |
|
156 | 561 |
self addVariables: ivarArray ofType: MCInstanceVariableDefinition. |
562 |
self addVariables: cvarArray ofType: MCClassVariableDefinition. |
|
563 |
self addVariables: poolArray ofType: MCPoolImportDefinition. |
|
564 |
self addVariables: civarArray ofType: MCClassInstanceVariableDefinition. |
|
214 | 565 |
|
566 |
"Modified: / 12-09-2010 / 17:09:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
567 |
! |
|
568 |
||
569 |
storeDataOn: aDataStream |
|
570 |
| instVarSize | |
|
571 |
instVarSize := (self hasTraitComposition or: [ self hasClassTraitComposition ]) |
|
572 |
ifTrue: [ self class instSize ] |
|
573 |
ifFalse: [ self class instSize - 2 ]. |
|
574 |
aDataStream |
|
575 |
beginInstance: self class |
|
576 |
size: instVarSize. |
|
577 |
1 to: instVarSize do: [ :index | |
|
578 |
aDataStream nextPut: (self instVarAt: index) ]. |
|
48 | 579 |
! ! |
580 |
||
581 |
!MCClassDefinition methodsFor:'testing'! |
|
582 |
||
583 |
hasClassInstanceVariables |
|
584 |
^ (self selectVariables: #isClassInstanceVariable) isEmpty not |
|
585 |
! |
|
586 |
||
214 | 587 |
hasClassTraitComposition |
588 |
^self classTraitCompositionString ~= '{}' |
|
589 |
! |
|
590 |
||
48 | 591 |
hasComment |
214 | 592 |
^ comment isEmptyOrNil not |
593 |
! |
|
594 |
||
595 |
hasTraitComposition |
|
596 |
^self traitCompositionString ~= '{}' |
|
48 | 597 |
! |
598 |
||
599 |
isClassDefinition |
|
600 |
^ true |
|
601 |
! |
|
602 |
||
603 |
isCodeDefinition |
|
604 |
^ true |
|
605 |
! ! |
|
606 |
||
607 |
!MCClassDefinition methodsFor:'visiting'! |
|
608 |
||
214 | 609 |
= aDefinition |
610 |
^super = aDefinition |
|
611 |
and: [superclassName = aDefinition superclassName |
|
612 |
and: [self traitCompositionString = aDefinition traitCompositionString |
|
613 |
and: [self classTraitCompositionString = aDefinition classTraitCompositionString |
|
614 |
and: [category = aDefinition category |
|
615 |
and: [type = aDefinition type |
|
616 |
and: [variables = aDefinition variables |
|
617 |
and: [comment = aDefinition comment]]]]]]] |
|
618 |
||
619 |
"Modified: / 18-08-2009 / 10:19:27 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
620 |
! |
|
621 |
||
48 | 622 |
accept: aVisitor |
214 | 623 |
aVisitor visitClassDefinition: self. |
624 |
(self hasClassInstanceVariables or: [self hasClassTraitComposition]) |
|
625 |
ifTrue: [aVisitor visitMetaclassDefinition: self]. |
|
626 |
||
627 |
! |
|
628 |
||
629 |
initializeWithName: nameString |
|
630 |
superclassName: superclassString |
|
631 |
traitComposition: traitCompositionString |
|
632 |
classTraitComposition: classTraitCompositionString |
|
633 |
category: categoryString |
|
634 |
instVarNames: ivarArray |
|
635 |
classVarNames: cvarArray |
|
636 |
poolDictionaryNames: poolArray |
|
637 |
classInstVarNames: civarArray |
|
638 |
type: typeSymbol |
|
639 |
comment: commentString |
|
640 |
commentStamp: stampStringOrNil |
|
641 |
name := nameString asSymbol. |
|
642 |
superclassName := superclassString ifNil: ['nil'] ifNotNil: [superclassString asSymbol]. |
|
643 |
traitComposition := traitCompositionString. |
|
644 |
classTraitComposition := classTraitCompositionString. |
|
645 |
category := categoryString. |
|
646 |
name = #CompiledMethod ifTrue: [type := #compiledMethod] ifFalse: [type := typeSymbol]. |
|
521 | 647 |
comment := commentString isNil ifTrue:[ nil] ifFalse:[ commentString asStringWithSqueakLineEndings]. |
214 | 648 |
commentStamp := stampStringOrNil ifNil: [self defaultCommentStamp]. |
649 |
variables := OrderedCollection new. |
|
650 |
self addVariables: ivarArray ofType: MCInstanceVariableDefinition. |
|
651 |
self addVariables: cvarArray ofType: MCClassVariableDefinition. |
|
652 |
self addVariables: poolArray ofType: MCPoolImportDefinition. |
|
653 |
self addVariables: civarArray ofType: MCClassInstanceVariableDefinition. |
|
654 |
||
655 |
"Modified: / 12-09-2010 / 16:05:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
521 | 656 |
"Modified: / 25-11-2011 / 17:30:38 / cg" |
48 | 657 |
! ! |
658 |
||
659 |
!MCClassDefinition class methodsFor:'documentation'! |
|
660 |
||
661 |
version |
|
1036 | 662 |
^ '$Header$' |
156 | 663 |
! |
664 |
||
665 |
version_CVS |
|
1036 | 666 |
^ '$Header$' |
214 | 667 |
! |
668 |
||
669 |
version_SVN |
|
1036 | 670 |
^ '$Id$' |
48 | 671 |
! ! |
713 | 672 |