48
|
1 |
"{ Package: 'stx:goodies/monticello' }"
|
|
2 |
|
|
3 |
MCDefinition subclass:#MCClassDefinition
|
|
4 |
instanceVariableNames:'name superclassName variables category type comment commentStamp'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Monticello-Modeling'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!MCClassDefinition class methodsFor:'instance creation'!
|
|
12 |
|
|
13 |
name: nameString
|
|
14 |
superclassName: superclassString
|
|
15 |
category: categoryString
|
|
16 |
instVarNames: ivarArray
|
|
17 |
classVarNames: cvarArray
|
|
18 |
poolDictionaryNames: poolArray
|
|
19 |
classInstVarNames: civarArray
|
|
20 |
type: typeSymbol
|
|
21 |
comment: commentString
|
|
22 |
commentStamp: stampString
|
|
23 |
^ self instanceLike:
|
|
24 |
(self new initializeWithName: nameString
|
|
25 |
superclassName: superclassString
|
|
26 |
category: categoryString
|
|
27 |
instVarNames: ivarArray
|
|
28 |
classVarNames: cvarArray
|
|
29 |
poolDictionaryNames: poolArray
|
|
30 |
classInstVarNames: civarArray
|
|
31 |
type: typeSymbol
|
|
32 |
comment: commentString
|
|
33 |
commentStamp: stampString)
|
|
34 |
! !
|
|
35 |
|
|
36 |
!MCClassDefinition class methodsFor:'obsolete'!
|
|
37 |
|
|
38 |
name: nameString
|
|
39 |
superclassName: superclassString
|
|
40 |
category: categoryString
|
|
41 |
instVarNames: ivarArray
|
|
42 |
classVarNames: cvarArray
|
|
43 |
poolDictionaryNames: poolArray
|
|
44 |
classInstVarNames: civarArray
|
|
45 |
comment: commentString
|
|
46 |
^ self name: nameString
|
|
47 |
superclassName: superclassString
|
|
48 |
category: categoryString
|
|
49 |
instVarNames: ivarArray
|
|
50 |
classVarNames: cvarArray
|
|
51 |
poolDictionaryNames: poolArray
|
|
52 |
classInstVarNames: civarArray
|
|
53 |
type: #normal
|
|
54 |
comment: commentString
|
|
55 |
!
|
|
56 |
|
|
57 |
name: nameString
|
|
58 |
superclassName: superclassString
|
|
59 |
category: categoryString
|
|
60 |
instVarNames: ivarArray
|
|
61 |
classVarNames: cvarArray
|
|
62 |
poolDictionaryNames: poolArray
|
|
63 |
classInstVarNames: civarArray
|
|
64 |
type: typeSymbol
|
|
65 |
comment: commentString
|
|
66 |
^ self
|
|
67 |
name: nameString
|
|
68 |
superclassName: superclassString
|
|
69 |
category: categoryString
|
|
70 |
instVarNames: ivarArray
|
|
71 |
classVarNames: cvarArray
|
|
72 |
poolDictionaryNames: poolArray
|
|
73 |
classInstVarNames: civarArray
|
|
74 |
type: typeSymbol
|
|
75 |
comment: commentString
|
|
76 |
commentStamp: nil
|
|
77 |
!
|
|
78 |
|
|
79 |
name: nameString
|
|
80 |
superclassName: superclassString
|
|
81 |
category: categoryString
|
|
82 |
instVarNames: ivarArray
|
|
83 |
comment: commentString
|
|
84 |
^ self name: nameString
|
|
85 |
superclassName: superclassString
|
|
86 |
category: categoryString
|
|
87 |
instVarNames: ivarArray
|
|
88 |
classVarNames: #()
|
|
89 |
poolDictionaryNames: #()
|
|
90 |
classInstVarNames: #()
|
|
91 |
comment: commentString
|
|
92 |
! !
|
|
93 |
|
|
94 |
!MCClassDefinition methodsFor:'accessing'!
|
|
95 |
|
|
96 |
actualClass
|
|
97 |
^Smalltalk classNamed: self className
|
|
98 |
!
|
|
99 |
|
|
100 |
category
|
|
101 |
^ category
|
|
102 |
!
|
|
103 |
|
|
104 |
classInstVarNames
|
|
105 |
^ self selectVariables: #isClassInstanceVariable
|
|
106 |
!
|
|
107 |
|
|
108 |
className
|
|
109 |
^ name
|
|
110 |
!
|
|
111 |
|
|
112 |
classVarNames
|
|
113 |
^ self selectVariables: #isClassVariable
|
|
114 |
!
|
|
115 |
|
|
116 |
comment
|
|
117 |
^ comment
|
|
118 |
!
|
|
119 |
|
|
120 |
commentStamp
|
|
121 |
^ commentStamp
|
|
122 |
!
|
|
123 |
|
|
124 |
description
|
|
125 |
^ Array with: name
|
|
126 |
!
|
|
127 |
|
|
128 |
instVarNames
|
|
129 |
^ self selectVariables: #isInstanceVariable
|
|
130 |
!
|
|
131 |
|
|
132 |
poolDictionaries
|
|
133 |
^ self selectVariables: #isPoolImport
|
|
134 |
!
|
|
135 |
|
|
136 |
selectVariables: aSelector
|
|
137 |
^ variables select: [:v | v perform: aSelector] thenCollect: [:v | v name]
|
|
138 |
!
|
|
139 |
|
|
140 |
sortKey
|
|
141 |
^ self className
|
|
142 |
!
|
|
143 |
|
|
144 |
superclassName
|
|
145 |
^ superclassName
|
|
146 |
!
|
|
147 |
|
|
148 |
type
|
|
149 |
^ type
|
|
150 |
!
|
|
151 |
|
|
152 |
variables
|
|
153 |
^ variables
|
|
154 |
! !
|
|
155 |
|
|
156 |
!MCClassDefinition methodsFor:'annotations'!
|
|
157 |
|
|
158 |
printAnnotations: requests on: aStream
|
|
159 |
"Add a string for an annotation pane, trying to fulfill the annotation requests.
|
|
160 |
These might include anything that
|
|
161 |
Preferences defaultAnnotationRequests
|
|
162 |
might return. Which includes anything in
|
|
163 |
Preferences annotationInfo
|
|
164 |
To edit these, use:"
|
|
165 |
"Preferences editAnnotations"
|
|
166 |
|
|
167 |
requests do: [ :aRequest |
|
|
168 |
aRequest == #requirements ifTrue: [
|
|
169 |
self requirements do: [ :req | aStream nextPutAll: req ] separatedBy: [ aStream space ]]
|
|
170 |
] separatedBy: [ aStream space ].
|
|
171 |
! !
|
|
172 |
|
|
173 |
!MCClassDefinition methodsFor:'comparing'!
|
|
174 |
|
|
175 |
= aDefinition
|
|
176 |
^ ((super = aDefinition)
|
|
177 |
and: [superclassName = aDefinition superclassName]
|
|
178 |
and: [category = aDefinition category]
|
|
179 |
and: [type = aDefinition type])
|
|
180 |
and: [variables = aDefinition variables]
|
|
181 |
and: [comment = aDefinition comment]
|
|
182 |
|
|
183 |
!
|
|
184 |
|
|
185 |
hash
|
|
186 |
| hash |
|
|
187 |
hash _ String stringHash: name initialHash: 0.
|
|
188 |
hash _ String stringHash: superclassName initialHash: hash.
|
|
189 |
hash _ String stringHash: (category ifNil: ['']) initialHash: hash.
|
|
190 |
hash _ String stringHash: type initialHash: hash.
|
|
191 |
variables do: [
|
|
192 |
:v |
|
|
193 |
hash _ String stringHash: v name initialHash: hash.
|
|
194 |
].
|
|
195 |
^ hash
|
|
196 |
!
|
|
197 |
|
|
198 |
provisions
|
|
199 |
^ Array with: name
|
|
200 |
!
|
|
201 |
|
|
202 |
requirements
|
|
203 |
^ (Array with: superclassName), self poolDictionaries
|
|
204 |
! !
|
|
205 |
|
|
206 |
!MCClassDefinition methodsFor:'initializing'!
|
|
207 |
|
|
208 |
addVariables: aCollection ofType: aClass
|
|
209 |
variables addAll: (aCollection collect: [:var | aClass name: var asString]).
|
|
210 |
!
|
|
211 |
|
|
212 |
defaultCommentStamp
|
|
213 |
^ String new
|
|
214 |
|
|
215 |
"The version below avoids stomping on stamps already in the image
|
|
216 |
|
|
217 |
^ (Smalltalk at: name ifPresent: [:c | c organization commentStamp])
|
|
218 |
ifNil: ['']
|
|
219 |
"
|
|
220 |
! !
|
|
221 |
|
|
222 |
!MCClassDefinition methodsFor:'installing'!
|
|
223 |
|
|
224 |
createClass
|
156
|
225 |
| superClass rslt |
|
|
226 |
superClass _ Smalltalk at: superclassName.
|
|
227 |
rslt := (ClassBuilder new)
|
|
228 |
name: name
|
|
229 |
inEnvironment: superClass environment
|
|
230 |
subclassOf: superClass
|
|
231 |
type: type
|
|
232 |
instanceVariableNames: self instanceVariablesString
|
|
233 |
classVariableNames: self classVariablesString
|
|
234 |
poolDictionaries: self sharedPoolsString
|
|
235 |
category: category.
|
|
236 |
|
|
237 |
"/ ST/X returns the builder; squeak the ready-made class
|
|
238 |
Smalltalk isSmalltalkX ifTrue: [
|
|
239 |
rslt := rslt buildClass.
|
|
240 |
].
|
|
241 |
^ rslt
|
48
|
242 |
!
|
|
243 |
|
|
244 |
load
|
|
245 |
self createClass ifNotNilDo:
|
|
246 |
[:class |
|
|
247 |
class class instanceVariableNames: self classInstanceVariablesString.
|
|
248 |
self hasComment ifTrue: [class classComment: comment stamp: commentStamp]]
|
|
249 |
!
|
|
250 |
|
|
251 |
stringForVariablesOfType: aSymbol
|
|
252 |
^ String streamContents:
|
|
253 |
[:stream |
|
|
254 |
(self selectVariables: aSymbol)
|
|
255 |
do: [:ea | stream nextPutAll: ea]
|
|
256 |
separatedBy: [stream space]]
|
|
257 |
!
|
|
258 |
|
|
259 |
unload
|
|
260 |
Smalltalk removeClassNamed: name
|
|
261 |
! !
|
|
262 |
|
|
263 |
!MCClassDefinition methodsFor:'printing'!
|
|
264 |
|
|
265 |
classInstanceVariablesString
|
|
266 |
^ self stringForVariablesOfType: #isClassInstanceVariable
|
|
267 |
!
|
|
268 |
|
|
269 |
classVariablesString
|
|
270 |
^ self stringForVariablesOfType: #isClassVariable
|
|
271 |
!
|
|
272 |
|
|
273 |
definitionString
|
|
274 |
^ String streamContents: [:stream | self printDefinitionOn: stream]
|
|
275 |
!
|
|
276 |
|
|
277 |
instanceVariablesString
|
|
278 |
^ self stringForVariablesOfType: #isInstanceVariable
|
|
279 |
!
|
|
280 |
|
|
281 |
kindOfSubclass
|
|
282 |
type = #normal ifTrue: [^ ' subclass: '].
|
|
283 |
type = #words ifTrue: [^ ' variableWordSubclass: '].
|
|
284 |
type = #variable ifTrue: [^ ' variableSubclass: '].
|
|
285 |
type = #bytes ifTrue: [^ ' variableByteSubclass: '].
|
|
286 |
type = #weak ifTrue: [^ ' weakSubclass: ' ].
|
|
287 |
type = #compiledMethod ifTrue: [^ ' variableByteSubclass: ' ].
|
|
288 |
self error: 'Unrecognized class type'
|
|
289 |
!
|
|
290 |
|
|
291 |
printDefinitionOn: stream
|
|
292 |
stream
|
|
293 |
nextPutAll: self superclassName;
|
|
294 |
nextPutAll: self kindOfSubclass;
|
|
295 |
nextPut: $# ;
|
|
296 |
nextPutAll: self className;
|
|
297 |
cr; tab;
|
|
298 |
nextPutAll: 'instanceVariableNames: ';
|
|
299 |
store: self instanceVariablesString;
|
|
300 |
cr; tab;
|
|
301 |
nextPutAll: 'classVariableNames: ';
|
|
302 |
store: self classVariablesString;
|
|
303 |
cr; tab;
|
|
304 |
nextPutAll: 'poolDictionaries: ';
|
|
305 |
store: self sharedPoolsString;
|
|
306 |
cr; tab;
|
|
307 |
nextPutAll: 'category: ';
|
|
308 |
store: self category asString
|
|
309 |
!
|
|
310 |
|
|
311 |
sharedPoolsString
|
|
312 |
^ self stringForVariablesOfType: #isPoolImport
|
|
313 |
!
|
|
314 |
|
|
315 |
source
|
|
316 |
^ self definitionString
|
|
317 |
!
|
|
318 |
|
|
319 |
summary
|
|
320 |
^ name
|
|
321 |
! !
|
|
322 |
|
|
323 |
!MCClassDefinition methodsFor:'serializing'!
|
|
324 |
|
|
325 |
initializeWithName: nameString
|
|
326 |
superclassName: superclassString
|
|
327 |
category: categoryString
|
|
328 |
instVarNames: ivarArray
|
|
329 |
classVarNames: cvarArray
|
|
330 |
poolDictionaryNames: poolArray
|
|
331 |
classInstVarNames: civarArray
|
|
332 |
type: typeSymbol
|
|
333 |
comment: commentString
|
|
334 |
commentStamp: stampStringOrNil
|
156
|
335 |
name _ nameString asSymbol.
|
|
336 |
superclassName _ superclassString ifNil: ['nil'] ifNotNil: [superclassString asSymbol].
|
|
337 |
category _ categoryString.
|
|
338 |
name = #CompiledMethod ifTrue: [type _ #compiledMethod] ifFalse: [type _ typeSymbol].
|
|
339 |
commentString notNil ifTrue:[ comment _ commentString withSqueakLineEndings ].
|
|
340 |
commentStamp _ stampStringOrNil ifNil: [self defaultCommentStamp].
|
|
341 |
variables _ OrderedCollection new.
|
|
342 |
self addVariables: ivarArray ofType: MCInstanceVariableDefinition.
|
|
343 |
self addVariables: cvarArray ofType: MCClassVariableDefinition.
|
|
344 |
self addVariables: poolArray ofType: MCPoolImportDefinition.
|
|
345 |
self addVariables: civarArray ofType: MCClassInstanceVariableDefinition.
|
48
|
346 |
! !
|
|
347 |
|
|
348 |
!MCClassDefinition methodsFor:'testing'!
|
|
349 |
|
|
350 |
hasClassInstanceVariables
|
|
351 |
^ (self selectVariables: #isClassInstanceVariable) isEmpty not
|
|
352 |
!
|
|
353 |
|
|
354 |
hasComment
|
|
355 |
^ comment notNil and: [comment ~= '']
|
|
356 |
!
|
|
357 |
|
|
358 |
isClassDefinition
|
|
359 |
^ true
|
|
360 |
!
|
|
361 |
|
|
362 |
isCodeDefinition
|
|
363 |
^ true
|
|
364 |
! !
|
|
365 |
|
|
366 |
!MCClassDefinition methodsFor:'visiting'!
|
|
367 |
|
|
368 |
accept: aVisitor
|
|
369 |
^ aVisitor visitClassDefinition: self
|
|
370 |
! !
|
|
371 |
|
|
372 |
!MCClassDefinition class methodsFor:'documentation'!
|
|
373 |
|
|
374 |
version
|
156
|
375 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCClassDefinition.st,v 1.2 2009-10-26 19:38:52 cg Exp $'
|
|
376 |
!
|
|
377 |
|
|
378 |
version_CVS
|
|
379 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCClassDefinition.st,v 1.2 2009-10-26 19:38:52 cg Exp $'
|
48
|
380 |
! !
|