Kernel-Classes.st 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  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. 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. <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: 'printing'!
  367. printOn: aStream
  368. aStream nextPutAll: self name
  369. ! !
  370. !Class methodsFor: 'testing'!
  371. isClass
  372. ^ true
  373. ! !
  374. Behavior subclass: #Metaclass
  375. instanceVariableNames: ''
  376. package: 'Kernel-Classes'!
  377. !Metaclass commentStamp!
  378. I am the root of the class hierarchy.
  379. 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.!
  380. !Metaclass methodsFor: 'accessing'!
  381. definition
  382. ^ String streamContents: [ :stream |
  383. stream
  384. nextPutAll: self asString;
  385. nextPutAll: ' instanceVariableNames: '''.
  386. self instanceVariableNames
  387. do: [ :each | stream nextPutAll: each ]
  388. separatedBy: [ stream nextPutAll: ' ' ].
  389. stream nextPutAll: '''' ]
  390. !
  391. instanceClass
  392. <return self.instanceClass>
  393. !
  394. instanceVariableNames: aCollection
  395. ClassBuilder new
  396. class: self instanceVariableNames: aCollection
  397. !
  398. package
  399. ^ self instanceClass package
  400. !
  401. subclasses
  402. ^ (self instanceClass subclasses
  403. select: [ :each | each isMetaclass not ])
  404. collect: [ :each | each theMetaClass ]
  405. !
  406. theMetaClass
  407. ^ self
  408. !
  409. theNonMetaClass
  410. ^ self instanceClass
  411. ! !
  412. !Metaclass methodsFor: 'converting'!
  413. asJavascript
  414. ^ '$globals.', self instanceClass name, '.klass'
  415. ! !
  416. !Metaclass methodsFor: 'printing'!
  417. printOn: aStream
  418. aStream
  419. nextPutAll: self instanceClass name;
  420. nextPutAll: ' class'
  421. ! !
  422. !Metaclass methodsFor: 'testing'!
  423. isMetaclass
  424. ^ true
  425. ! !
  426. Object subclass: #ClassBuilder
  427. instanceVariableNames: ''
  428. package: 'Kernel-Classes'!
  429. !ClassBuilder commentStamp!
  430. I am responsible for compiling new classes or modifying existing classes in the system.
  431. Rather than using me directly to compile a class, use `Class >> subclass:instanceVariableNames:package:`.!
  432. !ClassBuilder methodsFor: 'accessing'!
  433. instanceVariableNamesFor: aString
  434. ^ (aString tokenize: ' ') reject: [ :each | each isEmpty ]
  435. ! !
  436. !ClassBuilder methodsFor: 'class definition'!
  437. addSubclassOf: aClass named: className instanceVariableNames: aCollection package: packageName
  438. | theClass thePackage |
  439. theClass := Smalltalk globals at: className.
  440. thePackage := Package named: packageName.
  441. theClass ifNotNil: [
  442. theClass package: thePackage.
  443. theClass superclass == aClass ifFalse: [
  444. ^ self
  445. migrateClassNamed: className
  446. superclass: aClass
  447. instanceVariableNames: aCollection
  448. package: packageName ] ].
  449. ^ self
  450. basicAddSubclassOf: aClass
  451. named: className
  452. instanceVariableNames: aCollection
  453. package: packageName
  454. !
  455. class: aClass instanceVariableNames: ivarNames
  456. self basicClass: aClass instanceVariableNames: ivarNames.
  457. self setupClass: aClass.
  458. SystemAnnouncer current
  459. announce: (ClassDefinitionChanged new
  460. theClass: aClass;
  461. yourself)
  462. !
  463. superclass: aClass subclass: className
  464. ^ self superclass: aClass subclass: className instanceVariableNames: '' package: nil
  465. !
  466. superclass: aClass subclass: className instanceVariableNames: ivarNames package: packageName
  467. | newClass |
  468. newClass := self addSubclassOf: aClass
  469. named: className instanceVariableNames: (self instanceVariableNamesFor: ivarNames)
  470. package: (packageName ifNil: [ 'unclassified' ]).
  471. self setupClass: newClass.
  472. SystemAnnouncer current
  473. announce: (ClassAdded new
  474. theClass: newClass;
  475. yourself).
  476. ^ newClass
  477. ! !
  478. !ClassBuilder methodsFor: 'class migration'!
  479. migrateClass: aClass superclass: anotherClass
  480. ^ self
  481. migrateClassNamed: aClass name
  482. superclass: anotherClass
  483. instanceVariableNames: aClass instanceVariableNames
  484. package: aClass package name
  485. !
  486. migrateClassNamed: className superclass: aClass instanceVariableNames: aCollection package: packageName
  487. | oldClass newClass tmp |
  488. tmp := 'new*', className.
  489. oldClass := Smalltalk globals at: className.
  490. newClass := self
  491. addSubclassOf: aClass
  492. named: tmp
  493. instanceVariableNames: aCollection
  494. package: packageName.
  495. self basicSwapClassNames: oldClass with: newClass.
  496. [ self copyClass: oldClass to: newClass ]
  497. on: Error
  498. do: [ :exception |
  499. self
  500. basicSwapClassNames: oldClass with: newClass;
  501. basicRemoveClass: newClass.
  502. exception signal ].
  503. self
  504. rawRenameClass: oldClass to: tmp;
  505. rawRenameClass: newClass to: className.
  506. oldClass subclasses
  507. do: [ :each | self migrateClass: each superclass: newClass ].
  508. self basicRemoveClass: oldClass.
  509. SystemAnnouncer current announce: (ClassMigrated new
  510. theClass: newClass;
  511. oldClass: oldClass;
  512. yourself).
  513. ^ newClass
  514. !
  515. renameClass: aClass to: className
  516. self basicRenameClass: aClass to: className.
  517. "Recompile the class to fix potential issues with super sends"
  518. aClass recompile.
  519. SystemAnnouncer current
  520. announce: (ClassRenamed new
  521. theClass: aClass;
  522. yourself)
  523. ! !
  524. !ClassBuilder methodsFor: 'copying'!
  525. copyClass: aClass named: className
  526. | newClass |
  527. newClass := self
  528. addSubclassOf: aClass superclass
  529. named: className
  530. instanceVariableNames: aClass instanceVariableNames
  531. package: aClass package name.
  532. self copyClass: aClass to: newClass.
  533. SystemAnnouncer current
  534. announce: (ClassAdded new
  535. theClass: newClass;
  536. yourself).
  537. ^ newClass
  538. !
  539. copyClass: aClass to: anotherClass
  540. anotherClass comment: aClass comment.
  541. aClass methodDictionary valuesDo: [ :each |
  542. Compiler new install: each source forClass: anotherClass protocol: each protocol ].
  543. self basicClass: anotherClass class instanceVariables: aClass class instanceVariableNames.
  544. aClass class methodDictionary valuesDo: [ :each |
  545. Compiler new install: each source forClass: anotherClass class protocol: each protocol ].
  546. self setupClass: anotherClass
  547. ! !
  548. !ClassBuilder methodsFor: 'method definition'!
  549. installMethod: aCompiledMethod forClass: aBehavior protocol: aString
  550. aCompiledMethod protocol: aString.
  551. aBehavior addCompiledMethod: aCompiledMethod.
  552. ^ aCompiledMethod
  553. ! !
  554. !ClassBuilder methodsFor: 'private'!
  555. basicAddSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  556. <
  557. $core.addClass(aString, aClass, aCollection, packageName);
  558. return $globals[aString]
  559. >
  560. !
  561. basicClass: aClass instanceVariableNames: aString
  562. self basicClass: aClass instanceVariables: (self instanceVariableNamesFor: aString)
  563. !
  564. basicClass: aClass instanceVariables: aCollection
  565. aClass isMetaclass ifFalse: [ self error: aClass name, ' is not a metaclass' ].
  566. aClass basicAt: 'iVarNames' put: aCollection
  567. !
  568. basicRemoveClass: aClass
  569. <$core.removeClass(aClass)>
  570. !
  571. basicRenameClass: aClass to: aString
  572. <
  573. $globals[aString] = aClass;
  574. delete $globals[aClass.className];
  575. aClass.className = aString;
  576. >
  577. !
  578. basicSwapClassNames: aClass with: anotherClass
  579. <
  580. var tmp = aClass.className;
  581. aClass.className = anotherClass.className;
  582. anotherClass.className = tmp;
  583. >
  584. !
  585. rawRenameClass: aClass to: aString
  586. <
  587. $globals[aString] = aClass;
  588. >
  589. ! !
  590. !ClassBuilder methodsFor: 'public'!
  591. setupClass: aClass
  592. <$core.init(aClass);>
  593. ! !
  594. Object subclass: #ClassCategoryReader
  595. instanceVariableNames: 'class category'
  596. package: 'Kernel-Classes'!
  597. !ClassCategoryReader commentStamp!
  598. I provide a mechanism for retrieving class descriptions stored on a file in the Smalltalk chunk format.!
  599. !ClassCategoryReader methodsFor: 'accessing'!
  600. class: aClass category: aString
  601. class := aClass.
  602. category := aString
  603. ! !
  604. !ClassCategoryReader methodsFor: 'fileIn'!
  605. scanFrom: aChunkParser
  606. | chunk |
  607. [ chunk := aChunkParser nextChunk.
  608. chunk isEmpty ] whileFalse: [
  609. self compileMethod: chunk ].
  610. ClassBuilder new setupClass: class
  611. ! !
  612. !ClassCategoryReader methodsFor: 'initialization'!
  613. initialize
  614. super initialize.
  615. ! !
  616. !ClassCategoryReader methodsFor: 'private'!
  617. compileMethod: aString
  618. Compiler new install: aString forClass: class protocol: category
  619. ! !
  620. Object subclass: #ClassCommentReader
  621. instanceVariableNames: 'class'
  622. package: 'Kernel-Classes'!
  623. !ClassCommentReader commentStamp!
  624. I provide a mechanism for retrieving class comments stored on a file.
  625. See also `ClassCategoryReader`.!
  626. !ClassCommentReader methodsFor: 'accessing'!
  627. class: aClass
  628. class := aClass
  629. ! !
  630. !ClassCommentReader methodsFor: 'fileIn'!
  631. scanFrom: aChunkParser
  632. | chunk |
  633. chunk := aChunkParser nextChunk.
  634. chunk isEmpty ifFalse: [
  635. self setComment: chunk ].
  636. ! !
  637. !ClassCommentReader methodsFor: 'initialization'!
  638. initialize
  639. super initialize.
  640. ! !
  641. !ClassCommentReader methodsFor: 'private'!
  642. setComment: aString
  643. class comment: aString
  644. ! !
  645. Object subclass: #ClassSorterNode
  646. instanceVariableNames: 'theClass level nodes'
  647. package: 'Kernel-Classes'!
  648. !ClassSorterNode commentStamp!
  649. I provide an algorithm for sorting classes alphabetically.
  650. See [Issue #143](https://github.com/amber-smalltalk/amber/issues/143) on GitHub.!
  651. !ClassSorterNode methodsFor: 'accessing'!
  652. getNodesFrom: aCollection
  653. | children others |
  654. children := #().
  655. others := #().
  656. aCollection do: [ :each |
  657. (each superclass = self theClass)
  658. ifTrue: [ children add: each ]
  659. ifFalse: [ others add: each ]].
  660. nodes:= children collect: [ :each |
  661. ClassSorterNode on: each classes: others level: self level + 1 ]
  662. !
  663. level
  664. ^ level
  665. !
  666. level: anInteger
  667. level := anInteger
  668. !
  669. nodes
  670. ^ nodes
  671. !
  672. theClass
  673. ^ theClass
  674. !
  675. theClass: aClass
  676. theClass := aClass
  677. ! !
  678. !ClassSorterNode methodsFor: 'visiting'!
  679. traverseClassesWith: aCollection
  680. "sort classes alphabetically Issue #143"
  681. aCollection add: self theClass.
  682. (self nodes sorted: [ :a :b | a theClass name <= b theClass name ]) do: [ :aNode |
  683. aNode traverseClassesWith: aCollection ].
  684. ! !
  685. !ClassSorterNode class methodsFor: 'instance creation'!
  686. on: aClass classes: aCollection level: anInteger
  687. ^ self new
  688. theClass: aClass;
  689. level: anInteger;
  690. getNodesFrom: aCollection;
  691. yourself
  692. ! !