Kernel-Classes.st 18 KB

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