Kernel-Classes.st 18 KB

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