Kernel-Classes.st 19 KB

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