Kernel-Classes.st 19 KB

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