Kernel-Classes.st 18 KB

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