Kernel-Classes.st 18 KB

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