Kernel-Classes.st 19 KB

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