1
0

Kernel-Classes.st 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. Smalltalk current createPackage: 'Kernel-Classes'!
  2. Object subclass: #Behavior
  3. instanceVariableNames: ''
  4. package: 'Kernel-Classes'!
  5. !Behavior commentStamp!
  6. I am the superclass of all class objects.
  7. I define the protocol for creating instances of a class with `#basicNew` and `#new` (see `boot.js` for class constructors details).
  8. My instances know about the subclass/superclass relationships between classes, contain the description that instances are created from,
  9. and hold the method dictionary that's associated with each class.
  10. I also provides methods for compiling methods, examining the method dictionary, and iterating over the class hierarchy.!
  11. !Behavior methodsFor: 'accessing'!
  12. >> aString
  13. ^ self methodAt: aString
  14. !
  15. allInstanceVariableNames
  16. | result |
  17. result := self instanceVariableNames copy.
  18. self superclass ifNotNil: [
  19. result addAll: self superclass allInstanceVariableNames].
  20. ^result
  21. !
  22. allSelectors
  23. ^ self allSuperclasses
  24. inject: self selectors
  25. into: [ :acc :each | acc addAll: each selectors; yourself ]
  26. !
  27. allSubclasses
  28. "Answer an collection of the receiver's and the receiver's descendent's subclasses. "
  29. | subclasses index |
  30. subclasses := self subclasses.
  31. index := 1.
  32. [ index > subclasses size ]
  33. whileFalse: [ subclasses addAll: (subclasses at: index) subclasses.
  34. index := index + 1 ].
  35. ^ subclasses
  36. !
  37. allSuperclasses
  38. self superclass ifNil: [ ^ #() ].
  39. ^ (OrderedCollection with: self superclass)
  40. addAll: self superclass allSuperclasses;
  41. yourself
  42. !
  43. comment
  44. ^(self basicAt: 'comment') ifNil: ['']
  45. !
  46. comment: aString
  47. self basicAt: 'comment' put: aString.
  48. SystemAnnouncer current
  49. announce: (ClassCommentChanged new
  50. theClass: self;
  51. yourself)
  52. !
  53. commentStamp
  54. ^ClassCommentReader new
  55. class: self;
  56. yourself
  57. !
  58. commentStamp: aStamp prior: prior
  59. ^self commentStamp
  60. !
  61. definition
  62. ^ ''
  63. !
  64. instanceVariableNames
  65. <return self.iVarNames>
  66. !
  67. javascriptConstructor
  68. "Answer the JS constructor used to instantiate. See boot.js"
  69. <return self.fn>
  70. !
  71. javascriptConstructor: aJavaScriptFunction
  72. "Set the JS constructor used to instantiate.
  73. See the JS counter-part in boot.js `smalltalk.setClassConstructor'"
  74. <smalltalk.setClassConstructor(self, aJavaScriptFunction);>
  75. !
  76. lookupSelector: selector
  77. "Look up the given selector in my methodDictionary.
  78. Return the corresponding method if found.
  79. Otherwise chase the superclass chain and try again.
  80. Return nil if no method is found."
  81. | lookupClass |
  82. lookupClass := self.
  83. [ lookupClass = nil ] whileFalse: [
  84. (lookupClass includesSelector: selector)
  85. ifTrue: [ ^ lookupClass methodAt: selector ].
  86. lookupClass := lookupClass superclass ].
  87. ^ nil
  88. !
  89. methodAt: aString
  90. ^ self methodDictionary at: aString
  91. !
  92. methodDictionary
  93. <var dict = smalltalk.HashedCollection._new();
  94. var methods = self.methods;
  95. for(var i in methods) {
  96. if(methods[i].selector) {
  97. dict._at_put_(methods[i].selector, methods[i]);
  98. }
  99. };
  100. return dict>
  101. !
  102. methods
  103. ^ self methodDictionary values
  104. !
  105. methodsFor: aString
  106. ^ClassCategoryReader new
  107. class: self category: aString;
  108. yourself
  109. !
  110. methodsFor: aString stamp: aStamp
  111. "Added for compatibility, right now ignores stamp."
  112. ^self methodsFor: aString
  113. !
  114. methodsInProtocol: aString
  115. ^ self methodDictionary values select: [ :each | each protocol = aString ]
  116. !
  117. name
  118. <return self.className || nil>
  119. !
  120. organization
  121. ^ self basicAt: 'organization'
  122. !
  123. ownMethods
  124. "Answer the methods of the receiver that are not package extensions"
  125. ^ (self ownProtocols
  126. inject: OrderedCollection new
  127. into: [ :acc :each | acc, (self methodsInProtocol: each) ])
  128. sorted: [ :a :b | a selector <= b selector ]
  129. !
  130. ownProtocols
  131. "Answer the protocols of the receiver that are not package extensions"
  132. ^ self protocols reject: [ :each |
  133. each match: '^\*' ]
  134. !
  135. protocols
  136. ^ self organization elements sorted
  137. !
  138. prototype
  139. <return self.fn.prototype>
  140. !
  141. selectors
  142. ^ self methodDictionary keys
  143. !
  144. subclasses
  145. self subclassResponsibility
  146. !
  147. superclass
  148. <return self.superclass || nil>
  149. !
  150. theMetaClass
  151. ^ self class
  152. !
  153. theNonMetaClass
  154. ^ self
  155. !
  156. withAllSubclasses
  157. ^(Array with: self) addAll: self allSubclasses; yourself
  158. ! !
  159. !Behavior methodsFor: 'compiling'!
  160. addCompiledMethod: aMethod
  161. | oldMethod announcement |
  162. oldMethod := self methodDictionary
  163. at: aMethod selector
  164. ifAbsent: [ nil ].
  165. (self protocols includes: aMethod protocol)
  166. ifFalse: [ self organization addElement: aMethod protocol ].
  167. self basicAddCompiledMethod: aMethod.
  168. announcement := oldMethod
  169. ifNil: [
  170. MethodAdded new
  171. method: aMethod;
  172. yourself ]
  173. ifNotNil: [
  174. MethodModified new
  175. oldMethod: oldMethod;
  176. method: aMethod;
  177. yourself ].
  178. SystemAnnouncer current
  179. announce: announcement
  180. !
  181. compile: aString
  182. ^ self compile: aString category: ''
  183. !
  184. compile: aString category: anotherString
  185. ^ Compiler new
  186. install: aString
  187. forClass: self
  188. category: anotherString
  189. !
  190. recompile
  191. ^ Compiler new recompile: self
  192. !
  193. removeCompiledMethod: aMethod
  194. self basicRemoveCompiledMethod: aMethod.
  195. self methods
  196. detect: [ :each | each protocol = aMethod protocol ]
  197. ifNone: [ self organization removeElement: aMethod protocol ].
  198. SystemAnnouncer current
  199. announce: (MethodRemoved new
  200. method: aMethod;
  201. yourself)
  202. ! !
  203. !Behavior methodsFor: 'enumerating'!
  204. allSubclassesDo: aBlock
  205. "Evaluate the argument, aBlock, for each of the receiver's subclasses."
  206. self allSubclasses do: [ :each |
  207. aBlock value: each ]
  208. !
  209. protocolsDo: aBlock
  210. "Execute aBlock for each method category with
  211. its collection of methods in the sort order of category name."
  212. | methodsByCategory |
  213. methodsByCategory := HashedCollection new.
  214. self methodDictionary values do: [:m |
  215. (methodsByCategory at: m category ifAbsentPut: [Array new])
  216. add: m].
  217. self protocols do: [:category |
  218. aBlock value: category value: (methodsByCategory at: category)]
  219. ! !
  220. !Behavior methodsFor: 'instance creation'!
  221. basicNew
  222. <return new self.fn()>
  223. !
  224. new
  225. ^self basicNew initialize
  226. ! !
  227. !Behavior methodsFor: 'private'!
  228. basicAddCompiledMethod: aMethod
  229. <smalltalk.addMethod(aMethod, self)>
  230. !
  231. basicRemoveCompiledMethod: aMethod
  232. <smalltalk.removeMethod(aMethod,self)>
  233. ! !
  234. !Behavior methodsFor: 'testing'!
  235. canUnderstand: aSelector
  236. ^(self methodDictionary keys includes: aSelector asString) or: [
  237. self superclass notNil and: [self superclass canUnderstand: aSelector]]
  238. !
  239. includesBehavior: aClass
  240. ^ self == aClass or: [
  241. self inheritsFrom: aClass ]
  242. !
  243. includesSelector: aString
  244. ^ self methodDictionary includesKey: aString
  245. !
  246. inheritsFrom: aClass
  247. self superclass ifNil: [ ^ false ].
  248. ^ aClass == self superclass or: [
  249. self superclass inheritsFrom: aClass ]
  250. !
  251. isBehavior
  252. ^ true
  253. ! !
  254. Behavior subclass: #Class
  255. instanceVariableNames: ''
  256. package: 'Kernel-Classes'!
  257. !Class commentStamp!
  258. I am __the__ class object.
  259. My instances are the classes of the system.
  260. Class creation is done throught a `ClassBuilder` instance.!
  261. !Class methodsFor: 'accessing'!
  262. category
  263. ^self package ifNil: ['Unclassified'] ifNotNil: [self package name]
  264. !
  265. definition
  266. ^ String streamContents: [ :stream |
  267. stream
  268. nextPutAll: self superclass asString;
  269. nextPutAll: ' subclass: #';
  270. nextPutAll: self name;
  271. nextPutAll: String lf, String tab;
  272. nextPutAll: 'instanceVariableNames: '''.
  273. self instanceVariableNames
  274. do: [ :each | stream nextPutAll: each ]
  275. separatedBy: [ stream nextPutAll: ' ' ].
  276. stream
  277. nextPutAll: '''', String lf, String tab;
  278. nextPutAll: 'package: ''';
  279. nextPutAll: self category;
  280. nextPutAll: '''' ]
  281. !
  282. package
  283. ^ self basicAt: 'pkg'
  284. !
  285. package: aPackage
  286. | oldPackage |
  287. self package = aPackage ifTrue: [ ^ self ].
  288. oldPackage := self package.
  289. self basicAt: 'pkg' put: aPackage.
  290. oldPackage organization removeElement: self.
  291. aPackage organization addElement: self.
  292. SystemAnnouncer current announce: (ClassMoved new
  293. theClass: self;
  294. oldPackage: oldPackage;
  295. yourself)
  296. !
  297. rename: aString
  298. ClassBuilder new renameClass: self to: aString
  299. !
  300. subclasses
  301. <return self.subclasses._copy()>
  302. ! !
  303. !Class methodsFor: 'class creation'!
  304. subclass: aString instanceVariableNames: anotherString
  305. "Kept for compatibility."
  306. ^self subclass: aString instanceVariableNames: anotherString package: nil
  307. !
  308. subclass: aString instanceVariableNames: aString2 category: aString3
  309. "Kept for compatibility."
  310. self deprecatedAPI.
  311. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  312. !
  313. subclass: aString instanceVariableNames: aString2 classVariableNames: classVars poolDictionaries: pools category: aString3
  314. "Just ignore class variables and pools. Added for compatibility."
  315. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  316. !
  317. subclass: aString instanceVariableNames: aString2 package: aString3
  318. ^ClassBuilder new
  319. superclass: self subclass: aString asString instanceVariableNames: aString2 package: aString3
  320. ! !
  321. !Class methodsFor: 'converting'!
  322. asJavascript
  323. ^ 'smalltalk.', self name
  324. ! !
  325. !Class methodsFor: 'printing'!
  326. printOn: aStream
  327. aStream nextPutAll: self name
  328. ! !
  329. !Class methodsFor: 'testing'!
  330. isClass
  331. ^true
  332. ! !
  333. Behavior subclass: #Metaclass
  334. instanceVariableNames: ''
  335. package: 'Kernel-Classes'!
  336. !Metaclass commentStamp!
  337. I am the root of the class hierarchy.
  338. My instances are metaclasses, one for each real class, and have a single instance, which they hold onto: the class that they are the metaclass of.!
  339. !Metaclass methodsFor: 'accessing'!
  340. definition
  341. ^ String streamContents: [ :stream |
  342. stream
  343. nextPutAll: self asString;
  344. nextPutAll: ' instanceVariableNames: '''.
  345. self instanceVariableNames
  346. do: [ :each | stream nextPutAll: each ]
  347. separatedBy: [ stream nextPutAll: ' ' ].
  348. stream nextPutAll: '''' ]
  349. !
  350. instanceClass
  351. <return self.instanceClass>
  352. !
  353. instanceVariableNames: aCollection
  354. ClassBuilder new
  355. class: self instanceVariableNames: aCollection
  356. !
  357. subclasses
  358. ^ (self instanceClass subclasses
  359. select: [ :each | each isMetaclass not ])
  360. collect: [ :each | each theMetaClass ]
  361. !
  362. theMetaClass
  363. ^ self
  364. !
  365. theNonMetaClass
  366. ^ self instanceClass
  367. ! !
  368. !Metaclass methodsFor: 'converting'!
  369. asJavascript
  370. ^ 'smalltalk.', self instanceClass name, '.klass'
  371. ! !
  372. !Metaclass methodsFor: 'printing'!
  373. printOn: aStream
  374. aStream
  375. nextPutAll: self instanceClass name;
  376. nextPutAll: ' class'
  377. ! !
  378. !Metaclass methodsFor: 'testing'!
  379. isMetaclass
  380. ^true
  381. ! !
  382. Object subclass: #ClassBuilder
  383. instanceVariableNames: ''
  384. package: 'Kernel-Classes'!
  385. !ClassBuilder commentStamp!
  386. I am responsible for compiling new classes or modifying existing classes in the system.
  387. Rather than using me directly to compile a class, use `Class >> subclass:instanceVariableNames:package:`.!
  388. !ClassBuilder methodsFor: 'accessing'!
  389. instanceVariableNamesFor: aString
  390. ^(aString tokenize: ' ') reject: [ :each | each isEmpty ]
  391. ! !
  392. !ClassBuilder methodsFor: 'class definition'!
  393. addSubclassOf: aClass named: className instanceVariableNames: aCollection package: packageName
  394. | theClass thePackage |
  395. theClass := Smalltalk current at: className.
  396. thePackage := self createPackageNamed: packageName.
  397. theClass ifNotNil: [
  398. theClass package: thePackage.
  399. theClass superclass == aClass ifFalse: [
  400. ^ self
  401. migrateClassNamed: className
  402. superclass: aClass
  403. instanceVariableNames: aCollection
  404. package: packageName ] ].
  405. ^ self
  406. basicAddSubclassOf: aClass
  407. named: className
  408. instanceVariableNames: aCollection
  409. package: packageName
  410. !
  411. class: aClass instanceVariableNames: ivarNames
  412. self basicClass: aClass instanceVariableNames: ivarNames.
  413. self setupClass: aClass.
  414. SystemAnnouncer current
  415. announce: (ClassDefinitionChanged new
  416. theClass: aClass;
  417. yourself)
  418. !
  419. superclass: aClass subclass: className
  420. ^self superclass: aClass subclass: className instanceVariableNames: '' package: nil
  421. !
  422. superclass: aClass subclass: className instanceVariableNames: ivarNames package: packageName
  423. | newClass |
  424. newClass := self addSubclassOf: aClass
  425. named: className instanceVariableNames: (self instanceVariableNamesFor: ivarNames)
  426. package: (packageName ifNil: ['unclassified']).
  427. self setupClass: newClass.
  428. SystemAnnouncer current
  429. announce: (ClassAdded new
  430. theClass: newClass;
  431. yourself).
  432. ^newClass
  433. ! !
  434. !ClassBuilder methodsFor: 'class migration'!
  435. migrateClass: aClass superclass: anotherClass
  436. ^ self
  437. migrateClassNamed: aClass name
  438. superclass: anotherClass
  439. instanceVariableNames: aClass instanceVariableNames
  440. package: aClass package name
  441. !
  442. migrateClassNamed: className superclass: aClass instanceVariableNames: aCollection package: packageName
  443. | oldClass newClass tmp |
  444. tmp := 'new*', className.
  445. oldClass := Smalltalk current at: className.
  446. newClass := self
  447. addSubclassOf: aClass
  448. named: tmp
  449. instanceVariableNames: aCollection
  450. package: packageName.
  451. self basicSwapClassNames: oldClass with: newClass.
  452. [ self copyClass: oldClass to: newClass ]
  453. on: Error
  454. do: [ :exception |
  455. self
  456. basicSwapClassNames: oldClass with: newClass;
  457. basicRemoveClass: newClass.
  458. exception signal ].
  459. self
  460. rawRenameClass: oldClass to: tmp;
  461. rawRenameClass: newClass to: className.
  462. oldClass subclasses
  463. do: [ :each | self migrateClass: each superclass: newClass ]
  464. displayingProgress: 'Recompiling ', newClass name, '...'.
  465. self basicRemoveClass: oldClass.
  466. SystemAnnouncer current announce: (ClassMigrated new
  467. theClass: newClass;
  468. oldClass: oldClass;
  469. yourself).
  470. ^newClass
  471. !
  472. renameClass: aClass to: className
  473. self basicRenameClass: aClass to: className.
  474. "Recompile the class to fix potential issues with super sends"
  475. aClass recompile.
  476. SystemAnnouncer current
  477. announce: (ClassRenamed new
  478. theClass: aClass;
  479. yourself)
  480. ! !
  481. !ClassBuilder methodsFor: 'copying'!
  482. copyClass: aClass named: className
  483. | newClass |
  484. newClass := self
  485. addSubclassOf: aClass superclass
  486. named: className
  487. instanceVariableNames: aClass instanceVariableNames
  488. package: aClass package name.
  489. self copyClass: aClass to: newClass.
  490. SystemAnnouncer current
  491. announce: (ClassAdded new
  492. theClass: newClass;
  493. yourself).
  494. ^newClass
  495. !
  496. copyClass: aClass to: anotherClass
  497. anotherClass comment: aClass comment.
  498. aClass methodDictionary values do: [ :each |
  499. Compiler new install: each source forClass: anotherClass category: each category ].
  500. self basicClass: anotherClass class instanceVariables: aClass class instanceVariableNames.
  501. aClass class methodDictionary values do: [ :each |
  502. Compiler new install: each source forClass: anotherClass class category: each category ].
  503. self setupClass: anotherClass
  504. ! !
  505. !ClassBuilder methodsFor: 'method definition'!
  506. installMethod: aCompiledMethod forClass: aBehavior category: aString
  507. aCompiledMethod category: aString.
  508. aBehavior addCompiledMethod: aCompiledMethod.
  509. self setupClass: aBehavior.
  510. ^aCompiledMethod
  511. ! !
  512. !ClassBuilder methodsFor: 'private'!
  513. basicAddSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  514. <
  515. smalltalk.addClass(aString, aClass, aCollection, packageName);
  516. return smalltalk[aString]
  517. >
  518. !
  519. basicClass: aClass instanceVariableNames: aString
  520. self basicClass: aClass instanceVariables: (self instanceVariableNamesFor: aString)
  521. !
  522. basicClass: aClass instanceVariables: aCollection
  523. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  524. aClass basicAt: 'iVarNames' put: aCollection
  525. !
  526. basicRemoveClass: aClass
  527. <smalltalk.removeClass(aClass)>
  528. !
  529. basicRenameClass: aClass to: aString
  530. <
  531. smalltalk[aString] = aClass;
  532. delete smalltalk[aClass.className];
  533. aClass.className = aString;
  534. >
  535. !
  536. basicSwapClassNames: aClass with: anotherClass
  537. <
  538. var tmp = aClass.className;
  539. aClass.className = anotherClass.className;
  540. anotherClass.className = tmp;
  541. >
  542. !
  543. createPackageNamed: aString
  544. ^ Package named: aString ifAbsent: [
  545. Smalltalk current createPackage: aString ]
  546. !
  547. rawRenameClass: aClass to: aString
  548. <
  549. smalltalk[aString] = aClass;
  550. >
  551. ! !
  552. !ClassBuilder methodsFor: 'public'!
  553. setupClass: aClass
  554. <smalltalk.init(aClass);>
  555. ! !
  556. Object subclass: #ClassCategoryReader
  557. instanceVariableNames: 'class category'
  558. package: 'Kernel-Classes'!
  559. !ClassCategoryReader commentStamp!
  560. I provide a mechanism for retrieving class descriptions stored on a file in the Smalltalk chunk format.!
  561. !ClassCategoryReader methodsFor: 'accessing'!
  562. class: aClass category: aString
  563. class := aClass.
  564. category := aString
  565. ! !
  566. !ClassCategoryReader methodsFor: 'fileIn'!
  567. scanFrom: aChunkParser
  568. | chunk |
  569. [chunk := aChunkParser nextChunk.
  570. chunk isEmpty] whileFalse: [
  571. self compileMethod: chunk].
  572. ClassBuilder new setupClass: class
  573. ! !
  574. !ClassCategoryReader methodsFor: 'initialization'!
  575. initialize
  576. super initialize.
  577. ! !
  578. !ClassCategoryReader methodsFor: 'private'!
  579. compileMethod: aString
  580. Compiler new install: aString forClass: class category: category
  581. ! !
  582. Object subclass: #ClassCommentReader
  583. instanceVariableNames: 'class'
  584. package: 'Kernel-Classes'!
  585. !ClassCommentReader commentStamp!
  586. I provide a mechanism for retrieving class comments stored on a file.
  587. See also `ClassCategoryReader`.!
  588. !ClassCommentReader methodsFor: 'accessing'!
  589. class: aClass
  590. class := aClass
  591. ! !
  592. !ClassCommentReader methodsFor: 'fileIn'!
  593. scanFrom: aChunkParser
  594. | chunk |
  595. chunk := aChunkParser nextChunk.
  596. chunk isEmpty ifFalse: [
  597. self setComment: chunk].
  598. ! !
  599. !ClassCommentReader methodsFor: 'initialization'!
  600. initialize
  601. super initialize.
  602. ! !
  603. !ClassCommentReader methodsFor: 'private'!
  604. setComment: aString
  605. class comment: aString
  606. ! !
  607. Object subclass: #ClassSorterNode
  608. instanceVariableNames: 'theClass level nodes'
  609. package: 'Kernel-Classes'!
  610. !ClassSorterNode commentStamp!
  611. I provide an algorithm for sorting classes alphabetically.
  612. See [Issue #143](https://github.com/amber-smalltalk/amber/issues/143) on GitHub.!
  613. !ClassSorterNode methodsFor: 'accessing'!
  614. getNodesFrom: aCollection
  615. | children others |
  616. children := #().
  617. others := #().
  618. aCollection do: [:each |
  619. (each superclass = self theClass)
  620. ifTrue: [children add: each]
  621. ifFalse: [others add: each]].
  622. nodes:= children collect: [:each |
  623. ClassSorterNode on: each classes: others level: self level + 1]
  624. !
  625. level
  626. ^level
  627. !
  628. level: anInteger
  629. level := anInteger
  630. !
  631. nodes
  632. ^nodes
  633. !
  634. theClass
  635. ^theClass
  636. !
  637. theClass: aClass
  638. theClass := aClass
  639. ! !
  640. !ClassSorterNode methodsFor: 'visiting'!
  641. traverseClassesWith: aCollection
  642. "sort classes alphabetically Issue #143"
  643. aCollection add: self theClass.
  644. (self nodes sorted: [:a :b | a theClass name <= b theClass name ]) do: [:aNode |
  645. aNode traverseClassesWith: aCollection ].
  646. ! !
  647. !ClassSorterNode class methodsFor: 'instance creation'!
  648. on: aClass classes: aCollection level: anInteger
  649. ^self new
  650. theClass: aClass;
  651. level: anInteger;
  652. getNodesFrom: aCollection;
  653. yourself
  654. ! !