Kernel-Classes.st 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  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. stream
  300. nextPutAll: self superclass asString;
  301. nextPutAll: ' subclass: #';
  302. nextPutAll: self name;
  303. nextPutAll: String lf, String tab;
  304. nextPutAll: 'instanceVariableNames: '''.
  305. self instanceVariableNames
  306. do: [ :each | stream nextPutAll: each ]
  307. separatedBy: [ stream nextPutAll: ' ' ].
  308. stream
  309. nextPutAll: '''', String lf, String tab;
  310. nextPutAll: 'package: ''';
  311. nextPutAll: self category;
  312. nextPutAll: '''' ]
  313. !
  314. package
  315. ^ self basicAt: 'pkg'
  316. !
  317. package: aPackage
  318. | oldPackage |
  319. self package = aPackage ifTrue: [ ^ self ].
  320. oldPackage := self package.
  321. self basicAt: 'pkg' put: aPackage.
  322. oldPackage organization removeElement: self.
  323. aPackage organization addElement: self.
  324. SystemAnnouncer current announce: (ClassMoved new
  325. theClass: self;
  326. oldPackage: oldPackage;
  327. yourself)
  328. !
  329. rename: aString
  330. ClassBuilder new renameClass: self to: aString
  331. !
  332. subclasses
  333. <inlineJS: 'return self.subclasses._copy()'>
  334. !
  335. theMetaClass
  336. ^ self class
  337. !
  338. theNonMetaClass
  339. ^ self
  340. ! !
  341. !Class methodsFor: 'browsing'!
  342. browse
  343. Finder findClass: self
  344. ! !
  345. !Class methodsFor: 'class creation'!
  346. subclass: aString instanceVariableNames: anotherString
  347. "Kept for file-in compatibility."
  348. ^ self subclass: aString instanceVariableNames: anotherString package: nil
  349. !
  350. subclass: aString instanceVariableNames: aString2 category: aString3
  351. "Kept for file-in compatibility."
  352. ^ self subclass: aString instanceVariableNames: aString2 package: aString3
  353. !
  354. subclass: aString instanceVariableNames: aString2 classVariableNames: classVars poolDictionaries: pools category: aString3
  355. "Kept for file-in compatibility. ignores class variables and pools."
  356. ^ self subclass: aString instanceVariableNames: aString2 package: aString3
  357. !
  358. subclass: aString instanceVariableNames: aString2 package: aString3
  359. ^ ClassBuilder new
  360. superclass: self subclass: aString asString instanceVariableNames: aString2 package: aString3
  361. ! !
  362. !Class methodsFor: 'converting'!
  363. asJavascript
  364. ^ '$globals.', self name
  365. ! !
  366. !Class methodsFor: 'testing'!
  367. isClass
  368. ^ true
  369. ! !
  370. Behavior subclass: #Metaclass
  371. instanceVariableNames: ''
  372. package: 'Kernel-Classes'!
  373. !Metaclass commentStamp!
  374. I am the root of the class hierarchy.
  375. 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.!
  376. !Metaclass methodsFor: 'accessing'!
  377. definition
  378. ^ String streamContents: [ :stream |
  379. stream
  380. nextPutAll: self asString;
  381. nextPutAll: ' instanceVariableNames: '''.
  382. self instanceVariableNames
  383. do: [ :each | stream nextPutAll: each ]
  384. separatedBy: [ stream nextPutAll: ' ' ].
  385. stream nextPutAll: '''' ]
  386. !
  387. instanceClass
  388. <inlineJS: 'return self.instanceClass'>
  389. !
  390. instanceVariableNames: aCollection
  391. ClassBuilder new
  392. class: self instanceVariableNames: aCollection
  393. !
  394. name
  395. ^ self instanceClass name, ' class'
  396. !
  397. package
  398. ^ self instanceClass package
  399. !
  400. subclasses
  401. <inlineJS: 'return $core.metaSubclasses(self)'>
  402. !
  403. theMetaClass
  404. ^ self
  405. !
  406. theNonMetaClass
  407. ^ self instanceClass
  408. ! !
  409. !Metaclass methodsFor: 'converting'!
  410. asJavascript
  411. ^ '$globals.', self instanceClass name, '.klass'
  412. ! !
  413. !Metaclass methodsFor: 'testing'!
  414. isMetaclass
  415. ^ true
  416. ! !
  417. BehaviorBody subclass: #Trait
  418. instanceVariableNames: ''
  419. package: 'Kernel-Classes'!
  420. !Trait methodsFor: 'IDE compatibility'!
  421. allSubclassesDo: aBlock
  422. !
  423. superclass
  424. ^ nil
  425. ! !
  426. !Trait methodsFor: 'accessing'!
  427. category
  428. ^ self package ifNil: [ 'Unclassified' ] ifNotNil: [ self package name ]
  429. !
  430. classTag
  431. ^ 'trait'
  432. !
  433. definition
  434. ^ String streamContents: [ :stream |
  435. stream
  436. nextPutAll: 'Trait named: #';
  437. nextPutAll: self name;
  438. nextPutAll: String lf, String tab;
  439. nextPutAll: 'package: ''';
  440. nextPutAll: self category;
  441. nextPutAll: '''' ]
  442. !
  443. package
  444. ^ self basicAt: 'pkg'
  445. !
  446. theMetaClass
  447. ^ nil
  448. !
  449. theNonMetaClass
  450. ^ self
  451. ! !
  452. !Trait methodsFor: 'compiler compatibility'!
  453. allInstanceVariableNames
  454. ^ #()
  455. ! !
  456. !Trait class methodsFor: 'instance creation'!
  457. named: aString package: anotherString
  458. <return $core.addTrait(aString, anotherString)>
  459. ! !
  460. Object subclass: #ClassBuilder
  461. instanceVariableNames: ''
  462. package: 'Kernel-Classes'!
  463. !ClassBuilder commentStamp!
  464. I am responsible for compiling new classes or modifying existing classes in the system.
  465. Rather than using me directly to compile a class, use `Class >> subclass:instanceVariableNames:package:`.!
  466. !ClassBuilder methodsFor: 'accessing'!
  467. instanceVariableNamesFor: aString
  468. ^ (aString tokenize: ' ') reject: [ :each | each isEmpty ]
  469. ! !
  470. !ClassBuilder methodsFor: 'class definition'!
  471. addSubclassOf: aClass named: className instanceVariableNames: aCollection package: packageName
  472. | theClass thePackage |
  473. theClass := Smalltalk globals at: className.
  474. thePackage := Package named: packageName.
  475. theClass ifNotNil: [
  476. theClass package: thePackage.
  477. theClass superclass == aClass ifFalse: [
  478. ^ self
  479. migrateClassNamed: className
  480. superclass: aClass
  481. instanceVariableNames: aCollection
  482. package: packageName ] ].
  483. ^ self
  484. basicAddSubclassOf: aClass
  485. named: className
  486. instanceVariableNames: aCollection
  487. package: packageName
  488. !
  489. class: aClass instanceVariableNames: ivarNames
  490. self basicClass: aClass instanceVariableNames: ivarNames.
  491. SystemAnnouncer current
  492. announce: (ClassDefinitionChanged new
  493. theClass: aClass;
  494. yourself)
  495. !
  496. superclass: aClass subclass: className
  497. ^ self superclass: aClass subclass: className instanceVariableNames: '' package: nil
  498. !
  499. superclass: aClass subclass: className instanceVariableNames: ivarNames package: packageName
  500. | newClass |
  501. newClass := self addSubclassOf: aClass
  502. named: className instanceVariableNames: (self instanceVariableNamesFor: ivarNames)
  503. package: (packageName ifNil: [ 'unclassified' ]).
  504. SystemAnnouncer current
  505. announce: (ClassAdded new
  506. theClass: newClass;
  507. yourself).
  508. ^ newClass
  509. ! !
  510. !ClassBuilder methodsFor: 'class migration'!
  511. migrateClass: aClass superclass: anotherClass
  512. ^ self
  513. migrateClassNamed: aClass name
  514. superclass: anotherClass
  515. instanceVariableNames: aClass instanceVariableNames
  516. package: aClass package name
  517. !
  518. migrateClassNamed: className superclass: aClass instanceVariableNames: aCollection package: packageName
  519. | oldClass newClass tmp |
  520. tmp := 'new*', className.
  521. oldClass := Smalltalk globals at: className.
  522. newClass := self
  523. addSubclassOf: aClass
  524. named: tmp
  525. instanceVariableNames: aCollection
  526. package: packageName.
  527. self basicSwapClassNames: oldClass with: newClass.
  528. [ self copyClass: oldClass to: newClass ]
  529. on: Error
  530. do: [ :exception |
  531. self
  532. basicSwapClassNames: oldClass with: newClass;
  533. basicRemoveClass: newClass.
  534. exception resignal ].
  535. self
  536. rawRenameClass: oldClass to: tmp;
  537. rawRenameClass: newClass to: className.
  538. oldClass subclasses
  539. do: [ :each | self migrateClass: each superclass: newClass ].
  540. self basicRemoveClass: oldClass.
  541. SystemAnnouncer current announce: (ClassMigrated new
  542. theClass: newClass;
  543. oldClass: oldClass;
  544. yourself).
  545. ^ newClass
  546. !
  547. renameClass: aClass to: className
  548. self basicRenameClass: aClass to: className.
  549. "Recompile the class to fix potential issues with super sends"
  550. aClass recompile.
  551. SystemAnnouncer current
  552. announce: (ClassRenamed new
  553. theClass: aClass;
  554. yourself)
  555. ! !
  556. !ClassBuilder methodsFor: 'copying'!
  557. copyClass: aClass named: className
  558. | newClass |
  559. newClass := self
  560. addSubclassOf: aClass superclass
  561. named: className
  562. instanceVariableNames: aClass instanceVariableNames
  563. package: aClass package name.
  564. self copyClass: aClass to: newClass.
  565. SystemAnnouncer current
  566. announce: (ClassAdded new
  567. theClass: newClass;
  568. yourself).
  569. ^ newClass
  570. !
  571. copyClass: aClass to: anotherClass
  572. anotherClass comment: aClass comment.
  573. aClass methodDictionary valuesDo: [ :each |
  574. Compiler new install: each source forClass: anotherClass protocol: each protocol ].
  575. self basicClass: anotherClass class instanceVariables: aClass class instanceVariableNames.
  576. aClass class methodDictionary valuesDo: [ :each |
  577. Compiler new install: each source forClass: anotherClass class protocol: each protocol ]
  578. ! !
  579. !ClassBuilder methodsFor: 'method definition'!
  580. installMethod: aCompiledMethod forClass: aBehavior protocol: aString
  581. aCompiledMethod protocol: aString.
  582. aBehavior addCompiledMethod: aCompiledMethod.
  583. ^ aCompiledMethod
  584. ! !
  585. !ClassBuilder methodsFor: 'private'!
  586. basicAddSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  587. <inlineJS: '
  588. return $core.addClass(aString, aClass, aCollection, packageName);
  589. '>
  590. !
  591. basicClass: aClass instanceVariableNames: aString
  592. self basicClass: aClass instanceVariables: (self instanceVariableNamesFor: aString)
  593. !
  594. basicClass: aClass instanceVariables: aCollection
  595. aClass isMetaclass ifFalse: [ self error: aClass name, ' is not a metaclass' ].
  596. aClass basicAt: 'iVarNames' put: aCollection
  597. !
  598. basicRemoveClass: aClass
  599. <inlineJS: '$core.removeClass(aClass)'>
  600. !
  601. basicRenameClass: aClass to: aString
  602. <inlineJS: '
  603. $globals[aString] = aClass;
  604. delete $globals[aClass.className];
  605. aClass.className = aString;
  606. '>
  607. !
  608. basicSwapClassNames: aClass with: anotherClass
  609. <inlineJS: '
  610. var tmp = aClass.className;
  611. aClass.className = anotherClass.className;
  612. anotherClass.className = tmp;
  613. '>
  614. !
  615. rawRenameClass: aClass to: aString
  616. <inlineJS: '
  617. $globals[aString] = aClass;
  618. '>
  619. ! !
  620. !ClassBuilder methodsFor: 'public'!
  621. setupClass: aClass
  622. self deprecatedAPI: 'Classes are now auto-inited.'
  623. ! !
  624. Object subclass: #ClassSorterNode
  625. instanceVariableNames: 'theClass level nodes'
  626. package: 'Kernel-Classes'!
  627. !ClassSorterNode commentStamp!
  628. I provide an algorithm for sorting classes alphabetically.
  629. See [Issue #143](https://lolg.it/amber/amber/issues/143).!
  630. !ClassSorterNode methodsFor: 'accessing'!
  631. getNodesFrom: aCollection
  632. | children others |
  633. children := #().
  634. others := #().
  635. aCollection do: [ :each |
  636. (each superclass = self theClass)
  637. ifTrue: [ children add: each ]
  638. ifFalse: [ others add: each ]].
  639. nodes:= children collect: [ :each |
  640. ClassSorterNode on: each classes: others level: self level + 1 ]
  641. !
  642. level
  643. ^ level
  644. !
  645. level: anInteger
  646. level := anInteger
  647. !
  648. nodes
  649. ^ nodes
  650. !
  651. theClass
  652. ^ theClass
  653. !
  654. theClass: aClass
  655. theClass := aClass
  656. ! !
  657. !ClassSorterNode methodsFor: 'visiting'!
  658. traverseClassesWith: aCollection
  659. "sort classes alphabetically Issue #143"
  660. aCollection add: self theClass.
  661. (self nodes sorted: [ :a :b | a theClass name <= b theClass name ]) do: [ :aNode |
  662. aNode traverseClassesWith: aCollection ].
  663. ! !
  664. !ClassSorterNode class methodsFor: 'instance creation'!
  665. on: aClass classes: aCollection level: anInteger
  666. ^ self new
  667. theClass: aClass;
  668. level: anInteger;
  669. getNodesFrom: aCollection;
  670. yourself
  671. ! !