Kernel-Classes.st 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  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. BehaviorBody subclass: #Trait
  419. instanceVariableNames: ''
  420. package: 'Kernel-Classes'!
  421. !Trait methodsFor: 'IDE compatibility'!
  422. allSubclassesDo: aBlock
  423. !
  424. superclass
  425. ^ nil
  426. ! !
  427. !Trait methodsFor: 'accessing'!
  428. category
  429. ^ self package ifNil: [ 'Unclassified' ] ifNotNil: [ self package name ]
  430. !
  431. classTag
  432. ^ 'trait'
  433. !
  434. definition
  435. ^ String streamContents: [ :stream |
  436. stream
  437. nextPutAll: 'Trait named: #';
  438. nextPutAll: self name;
  439. nextPutAll: String lf, String tab;
  440. nextPutAll: 'package: ''';
  441. nextPutAll: self category;
  442. nextPutAll: '''' ]
  443. !
  444. package
  445. ^ self basicAt: 'pkg'
  446. !
  447. theMetaClass
  448. ^ nil
  449. !
  450. theNonMetaClass
  451. ^ self
  452. ! !
  453. !Trait methodsFor: 'compiler compatibility'!
  454. allInstanceVariableNames
  455. ^ #()
  456. ! !
  457. !Trait class methodsFor: 'instance creation'!
  458. named: aString package: anotherString
  459. <return $core.addTrait(aString, anotherString)>
  460. ! !
  461. Object subclass: #ClassBuilder
  462. instanceVariableNames: ''
  463. package: 'Kernel-Classes'!
  464. !ClassBuilder commentStamp!
  465. I am responsible for compiling new classes or modifying existing classes in the system.
  466. Rather than using me directly to compile a class, use `Class >> subclass:instanceVariableNames:package:`.!
  467. !ClassBuilder methodsFor: 'accessing'!
  468. instanceVariableNamesFor: aString
  469. ^ (aString tokenize: ' ') reject: [ :each | each isEmpty ]
  470. ! !
  471. !ClassBuilder methodsFor: 'class definition'!
  472. addSubclassOf: aClass named: className instanceVariableNames: aCollection package: packageName
  473. | theClass thePackage |
  474. theClass := Smalltalk globals at: className.
  475. thePackage := Package named: packageName.
  476. theClass ifNotNil: [
  477. theClass package: thePackage.
  478. theClass superclass == aClass ifFalse: [
  479. ^ self
  480. migrateClassNamed: className
  481. superclass: aClass
  482. instanceVariableNames: aCollection
  483. package: packageName ] ].
  484. ^ self
  485. basicAddSubclassOf: aClass
  486. named: className
  487. instanceVariableNames: aCollection
  488. package: packageName
  489. !
  490. class: aClass instanceVariableNames: ivarNames
  491. self basicClass: aClass instanceVariableNames: ivarNames.
  492. SystemAnnouncer current
  493. announce: (ClassDefinitionChanged new
  494. theClass: aClass;
  495. yourself)
  496. !
  497. superclass: aClass subclass: className
  498. ^ self superclass: aClass subclass: className instanceVariableNames: '' package: nil
  499. !
  500. superclass: aClass subclass: className instanceVariableNames: ivarNames package: packageName
  501. | newClass |
  502. newClass := self addSubclassOf: aClass
  503. named: className instanceVariableNames: (self instanceVariableNamesFor: ivarNames)
  504. package: (packageName ifNil: [ 'unclassified' ]).
  505. SystemAnnouncer current
  506. announce: (ClassAdded new
  507. theClass: newClass;
  508. yourself).
  509. ^ newClass
  510. ! !
  511. !ClassBuilder methodsFor: 'class migration'!
  512. migrateClass: aClass superclass: anotherClass
  513. ^ self
  514. migrateClassNamed: aClass name
  515. superclass: anotherClass
  516. instanceVariableNames: aClass instanceVariableNames
  517. package: aClass package name
  518. !
  519. migrateClassNamed: className superclass: aClass instanceVariableNames: aCollection package: packageName
  520. | oldClass newClass tmp |
  521. tmp := 'new*', className.
  522. oldClass := Smalltalk globals at: className.
  523. newClass := self
  524. addSubclassOf: aClass
  525. named: tmp
  526. instanceVariableNames: aCollection
  527. package: packageName.
  528. self basicSwapClassNames: oldClass with: newClass.
  529. [ self copyClass: oldClass to: newClass ]
  530. on: Error
  531. do: [ :exception |
  532. self
  533. basicSwapClassNames: oldClass with: newClass;
  534. basicRemoveClass: newClass.
  535. exception resignal ].
  536. self
  537. rawRenameClass: oldClass to: tmp;
  538. rawRenameClass: newClass to: className.
  539. oldClass subclasses
  540. do: [ :each | self migrateClass: each superclass: newClass ].
  541. self basicRemoveClass: oldClass.
  542. SystemAnnouncer current announce: (ClassMigrated new
  543. theClass: newClass;
  544. oldClass: oldClass;
  545. yourself).
  546. ^ newClass
  547. !
  548. renameClass: aClass to: className
  549. self basicRenameClass: aClass to: className.
  550. "Recompile the class to fix potential issues with super sends"
  551. aClass recompile.
  552. SystemAnnouncer current
  553. announce: (ClassRenamed new
  554. theClass: aClass;
  555. yourself)
  556. ! !
  557. !ClassBuilder methodsFor: 'copying'!
  558. copyClass: aClass named: className
  559. | newClass |
  560. newClass := self
  561. addSubclassOf: aClass superclass
  562. named: className
  563. instanceVariableNames: aClass instanceVariableNames
  564. package: aClass package name.
  565. self copyClass: aClass to: newClass.
  566. SystemAnnouncer current
  567. announce: (ClassAdded new
  568. theClass: newClass;
  569. yourself).
  570. ^ newClass
  571. !
  572. copyClass: aClass to: anotherClass
  573. anotherClass comment: aClass comment.
  574. aClass methodDictionary valuesDo: [ :each |
  575. Compiler new install: each source forClass: anotherClass protocol: each protocol ].
  576. self basicClass: anotherClass class instanceVariables: aClass class instanceVariableNames.
  577. aClass class methodDictionary valuesDo: [ :each |
  578. Compiler new install: each source forClass: anotherClass class protocol: each protocol ]
  579. ! !
  580. !ClassBuilder methodsFor: 'method definition'!
  581. installMethod: aCompiledMethod forClass: aBehavior protocol: aString
  582. aCompiledMethod protocol: aString.
  583. aBehavior addCompiledMethod: aCompiledMethod.
  584. ^ aCompiledMethod
  585. ! !
  586. !ClassBuilder methodsFor: 'private'!
  587. basicAddSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  588. <inlineJS: '
  589. return $core.addClass(aString, aClass, aCollection, packageName);
  590. '>
  591. !
  592. basicClass: aClass instanceVariableNames: aString
  593. self basicClass: aClass instanceVariables: (self instanceVariableNamesFor: aString)
  594. !
  595. basicClass: aClass instanceVariables: aCollection
  596. aClass isMetaclass ifFalse: [ self error: aClass name, ' is not a metaclass' ].
  597. aClass basicAt: 'iVarNames' put: aCollection
  598. !
  599. basicRemoveClass: aClass
  600. <inlineJS: '$core.removeClass(aClass)'>
  601. !
  602. basicRenameClass: aClass to: aString
  603. <inlineJS: '
  604. $globals[aString] = aClass;
  605. delete $globals[aClass.className];
  606. aClass.className = aString;
  607. '>
  608. !
  609. basicSwapClassNames: aClass with: anotherClass
  610. <inlineJS: '
  611. var tmp = aClass.className;
  612. aClass.className = anotherClass.className;
  613. anotherClass.className = tmp;
  614. '>
  615. !
  616. rawRenameClass: aClass to: aString
  617. <inlineJS: '
  618. $globals[aString] = aClass;
  619. '>
  620. ! !
  621. !ClassBuilder methodsFor: 'public'!
  622. setupClass: aClass
  623. self deprecatedAPI: 'Classes are now auto-inited.'
  624. ! !
  625. Object subclass: #ClassSorterNode
  626. instanceVariableNames: 'theClass level nodes'
  627. package: 'Kernel-Classes'!
  628. !ClassSorterNode commentStamp!
  629. I provide an algorithm for sorting classes alphabetically.
  630. See [Issue #143](https://lolg.it/amber/amber/issues/143).!
  631. !ClassSorterNode methodsFor: 'accessing'!
  632. getNodesFrom: aCollection
  633. | children others |
  634. children := #().
  635. others := #().
  636. aCollection do: [ :each |
  637. (each superclass = self theClass)
  638. ifTrue: [ children add: each ]
  639. ifFalse: [ others add: each ]].
  640. nodes:= children collect: [ :each |
  641. ClassSorterNode on: each classes: others level: self level + 1 ]
  642. !
  643. level
  644. ^ level
  645. !
  646. level: anInteger
  647. level := anInteger
  648. !
  649. nodes
  650. ^ nodes
  651. !
  652. theClass
  653. ^ theClass
  654. !
  655. theClass: aClass
  656. theClass := aClass
  657. ! !
  658. !ClassSorterNode methodsFor: 'visiting'!
  659. traverseClassesWith: aCollection
  660. "sort classes alphabetically Issue #143"
  661. aCollection add: self theClass.
  662. (self nodes sorted: [ :a :b | a theClass name <= b theClass name ]) do: [ :aNode |
  663. aNode traverseClassesWith: aCollection ].
  664. ! !
  665. !ClassSorterNode class methodsFor: 'instance creation'!
  666. on: aClass classes: aCollection level: anInteger
  667. ^ self new
  668. theClass: aClass;
  669. level: anInteger;
  670. getNodesFrom: aCollection;
  671. yourself
  672. ! !