Kernel-Classes.st 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. Smalltalk current createPackage: 'Kernel-Classes' properties: #{}!
  2. Object subclass: #Behavior
  3. instanceVariableNames: ''
  4. category: 'Kernel-Classes'!
  5. !Behavior methodsFor: 'accessing'!
  6. name
  7. <return self.className || nil>
  8. !
  9. superclass
  10. <return self.superclass || nil>
  11. !
  12. subclasses
  13. <return smalltalk.subclasses(self)>
  14. !
  15. allSubclasses
  16. | result |
  17. result := self subclasses.
  18. self subclasses do: [:each |
  19. result addAll: each allSubclasses].
  20. ^result
  21. !
  22. withAllSubclasses
  23. ^(Array with: self) addAll: self allSubclasses; yourself
  24. !
  25. prototype
  26. <return self.fn.prototype>
  27. !
  28. methodDictionary
  29. <var dict = smalltalk.HashedCollection._new();
  30. var methods = self.fn.prototype.methods;
  31. for(var i in methods) {
  32. if(methods[i].selector) {
  33. dict._at_put_(methods[i].selector, methods[i]);
  34. }
  35. };
  36. return dict>
  37. !
  38. methodsFor: aString
  39. ^ClassCategoryReader new
  40. class: self category: aString;
  41. yourself
  42. !
  43. addCompiledMethod: aMethod
  44. <smalltalk.addMethod(aMethod.selector._asSelector(), aMethod, self)>
  45. !
  46. instanceVariableNames
  47. <return self.iVarNames>
  48. !
  49. comment
  50. ^(self basicAt: 'comment') ifNil: ['']
  51. !
  52. comment: aString
  53. self basicAt: 'comment' put: aString
  54. !
  55. commentStamp
  56. ^ClassCommentReader new
  57. class: self;
  58. yourself
  59. !
  60. removeCompiledMethod: aMethod
  61. <delete self.fn.prototype[aMethod.selector._asSelector()];
  62. delete self.fn.prototype.methods[aMethod.selector];
  63. smalltalk.init(self);>
  64. !
  65. protocols
  66. | protocols |
  67. protocols := Array new.
  68. self methodDictionary do: [:each |
  69. (protocols includes: each category) ifFalse: [
  70. protocols add: each category]].
  71. ^protocols sort
  72. !
  73. protocolsDo: aBlock
  74. "Execute aBlock for each method category with
  75. its collection of methods in the sort order of category name."
  76. | methodsByCategory |
  77. methodsByCategory := HashedCollection new.
  78. self methodDictionary values do: [:m |
  79. (methodsByCategory at: m category ifAbsentPut: [Array new])
  80. add: m].
  81. self protocols do: [:category |
  82. aBlock value: category value: (methodsByCategory at: category)]
  83. !
  84. allInstanceVariableNames
  85. | result |
  86. result := self instanceVariableNames copy.
  87. self superclass ifNotNil: [
  88. result addAll: self superclass allInstanceVariableNames].
  89. ^result
  90. !
  91. methodAt: aString
  92. <return smalltalk.methods(self)[aString]>
  93. !
  94. methodsFor: aString stamp: aStamp
  95. "Added for compatibility, right now ignores stamp."
  96. ^self methodsFor: aString
  97. !
  98. commentStamp: aStamp prior: prior
  99. ^self commentStamp
  100. ! !
  101. !Behavior methodsFor: 'compiling'!
  102. compile: aString
  103. self compile: aString category: ''
  104. !
  105. compile: aString category: anotherString
  106. | method |
  107. method := Compiler new load: aString forClass: self.
  108. method category: anotherString.
  109. self addCompiledMethod: method
  110. ! !
  111. !Behavior methodsFor: 'instance creation'!
  112. new
  113. ^self basicNew initialize
  114. !
  115. basicNew
  116. <return new self.fn()>
  117. !
  118. inheritsFrom: aClass
  119. ^aClass allSubclasses includes: self
  120. ! !
  121. Behavior subclass: #Class
  122. instanceVariableNames: ''
  123. category: 'Kernel-Classes'!
  124. !Class methodsFor: 'accessing'!
  125. category
  126. ^self package ifNil: ['Unclassified'] ifNotNil: [self package name]
  127. !
  128. rename: aString
  129. <
  130. smalltalk[aString] = self;
  131. delete smalltalk[self.className];
  132. self.className = aString;
  133. >
  134. !
  135. package
  136. <return self.pkg>
  137. !
  138. package: aPackage
  139. <self.pkg = aPackage>
  140. ! !
  141. !Class methodsFor: 'class creation'!
  142. subclass: aString instanceVariableNames: anotherString
  143. "Kept for compatibility."
  144. ^self subclass: aString instanceVariableNames: anotherString package: nil
  145. !
  146. subclass: aString instanceVariableNames: aString2 category: aString3
  147. "Kept for compatibility."
  148. self deprecatedAPI.
  149. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  150. !
  151. subclass: aString instanceVariableNames: aString2 classVariableNames: classVars poolDictionaries: pools category: aString3
  152. "Just ignore class variables and pools. Added for compatibility."
  153. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  154. !
  155. subclass: aString instanceVariableNames: aString2 package: aString3
  156. ^ClassBuilder new
  157. superclass: self subclass: aString asString instanceVariableNames: aString2 package: aString3
  158. ! !
  159. !Class methodsFor: 'printing'!
  160. printString
  161. ^self name
  162. ! !
  163. !Class methodsFor: 'testing'!
  164. isClass
  165. ^true
  166. ! !
  167. Behavior subclass: #Metaclass
  168. instanceVariableNames: ''
  169. category: 'Kernel-Classes'!
  170. !Metaclass methodsFor: 'accessing'!
  171. instanceClass
  172. <return self.instanceClass>
  173. !
  174. instanceVariableNames: aCollection
  175. ClassBuilder new
  176. class: self instanceVariableNames: aCollection
  177. ! !
  178. !Metaclass methodsFor: 'printing'!
  179. printString
  180. ^self instanceClass name, ' class'
  181. ! !
  182. !Metaclass methodsFor: 'testing'!
  183. isMetaclass
  184. ^true
  185. ! !
  186. Object subclass: #ClassBuilder
  187. instanceVariableNames: ''
  188. category: 'Kernel-Classes'!
  189. !ClassBuilder methodsFor: 'class creation'!
  190. superclass: aClass subclass: aString
  191. ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
  192. !
  193. class: aClass instanceVariableNames: aString
  194. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  195. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  196. self setupClass: aClass
  197. !
  198. superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
  199. | newClass |
  200. newClass := self addSubclassOf: aClass
  201. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  202. package: (aString3 ifNil: ['unclassified']).
  203. self setupClass: newClass.
  204. ^newClass
  205. ! !
  206. !ClassBuilder methodsFor: 'private'!
  207. instanceVariableNamesFor: aString
  208. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  209. !
  210. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  211. <smalltalk.addClass(aString, aClass, aCollection);
  212. return smalltalk[aString]>
  213. !
  214. setupClass: aClass
  215. <smalltalk.init(aClass);>
  216. !
  217. addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  218. <smalltalk.addClass(aString, aClass, aCollection, packageName);
  219. return smalltalk[aString]>
  220. !
  221. copyClass: aClass named: aString
  222. | newClass |
  223. newClass := self
  224. addSubclassOf: aClass superclass
  225. named: aString
  226. instanceVariableNames: aClass instanceVariableNames
  227. package: aClass package name.
  228. self setupClass: newClass.
  229. aClass methodDictionary values do: [:each |
  230. newClass addCompiledMethod: (Compiler new load: each source forClass: newClass).
  231. (newClass methodDictionary at: each selector) category: each category].
  232. aClass class methodDictionary values do: [:each |
  233. newClass class addCompiledMethod: (Compiler new load: each source forClass: newClass class).
  234. (newClass class methodDictionary at: each selector) category: each category].
  235. self setupClass: newClass.
  236. ^newClass
  237. ! !
  238. Object subclass: #ClassCategoryReader
  239. instanceVariableNames: 'class category chunkParser'
  240. category: 'Kernel-Classes'!
  241. !ClassCategoryReader methodsFor: 'accessing'!
  242. class: aClass category: aString
  243. class := aClass.
  244. category := aString
  245. ! !
  246. !ClassCategoryReader methodsFor: 'fileIn'!
  247. scanFrom: aChunkParser
  248. | chunk |
  249. [chunk := aChunkParser nextChunk.
  250. chunk isEmpty] whileFalse: [
  251. self compileMethod: chunk]
  252. ! !
  253. !ClassCategoryReader methodsFor: 'initialization'!
  254. initialize
  255. super initialize.
  256. chunkParser := ChunkParser new.
  257. ! !
  258. !ClassCategoryReader methodsFor: 'private'!
  259. compileMethod: aString
  260. | method |
  261. method := Compiler new load: aString forClass: class.
  262. method category: category.
  263. class addCompiledMethod: method
  264. ! !
  265. Object subclass: #ClassCommentReader
  266. instanceVariableNames: 'class chunkParser'
  267. category: 'Kernel-Classes'!
  268. !ClassCommentReader methodsFor: 'accessing'!
  269. class: aClass
  270. class := aClass
  271. ! !
  272. !ClassCommentReader methodsFor: 'fileIn'!
  273. scanFrom: aChunkParser
  274. | chunk |
  275. chunk := aChunkParser nextChunk.
  276. chunk isEmpty ifFalse: [
  277. self setComment: chunk].
  278. ! !
  279. !ClassCommentReader methodsFor: 'initialization'!
  280. initialize
  281. super initialize.
  282. chunkParser := ChunkParser new.
  283. ! !
  284. !ClassCommentReader methodsFor: 'private'!
  285. setComment: aString
  286. class comment: aString
  287. ! !