Class.st
changeset 328 7b542c0bf1dd
parent 326 d2902942491d
child 333 18e7d5971e16
equal deleted inserted replaced
327:183f094cfd72 328:7b542c0bf1dd
    19 
    19 
    20 Class comment:'
    20 Class comment:'
    21 COPYRIGHT (c) 1989 by Claus Gittinger
    21 COPYRIGHT (c) 1989 by Claus Gittinger
    22 	      All Rights Reserved
    22 	      All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libbasic/Class.st,v 1.39 1995-04-11 14:48:39 claus Exp $
    24 $Header: /cvs/stx/stx/libbasic/Class.st,v 1.40 1995-05-01 21:28:45 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !Class class methodsFor:'documentation'!
    27 !Class class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libbasic/Class.st,v 1.39 1995-04-11 14:48:39 claus Exp $
    45 $Header: /cvs/stx/stx/libbasic/Class.st,v 1.40 1995-05-01 21:28:45 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
   505     "the comment is either a string, or an integer specifying the
   505     "the comment is either a string, or an integer specifying the
   506      position within the classes sourcefile ...
   506      position within the classes sourcefile ...
   507     "
   507     "
   508     comment isNumber ifTrue:[
   508     comment isNumber ifTrue:[
   509 	classFilename notNil ifTrue:[
   509 	classFilename notNil ifTrue:[
   510 	    stream := Smalltalk systemFileStreamFor:('source/' , classFilename).
   510 	    stream := Smalltalk sourceFileStreamFor:classFilename.
   511 	    stream notNil ifTrue:[
   511 	    stream notNil ifTrue:[
   512 		stream position:comment.
   512 		stream position:comment.
   513 		string := String readFrom:stream onError:''.
   513 		string := String readFrom:stream onError:''.
   514 		stream close.
   514 		stream close.
   515 		^ string
   515 		^ string
   540 	oldComment := self comment.
   540 	oldComment := self comment.
   541 	comment := aString.
   541 	comment := aString.
   542 	self changed:#comment with:oldComment.
   542 	self changed:#comment with:oldComment.
   543 	self addChangeRecordForClassComment:self.
   543 	self addChangeRecordForClassComment:self.
   544     ]
   544     ]
   545 !
       
   546 
       
   547 organization
       
   548     ^ ClassOrganization for:self
       
   549 !
   545 !
   550 
   546 
   551 package
   547 package
   552     "return the package of the class"
   548     "return the package of the class"
   553 
   549 
   826 !
   822 !
   827 
   823 
   828 unload
   824 unload
   829     "if the receiver was autoloaded, unload and reinstall it as
   825     "if the receiver was autoloaded, unload and reinstall it as
   830      autoloaded. Can be used to get rid of no longer needed autoloaded
   826      autoloaded. Can be used to get rid of no longer needed autoloaded
   831      classes. (maybe, autoloaded classes should unload themselfes when no
   827      classes. 
   832      longer needed - for example, when tha application view is closed ...)"
   828      (maybe, autoloaded classes should unload themselfes when no
       
   829       longer needed - for example, after some delay when the last instance 
       
   830       is gone ...)"
   833 
   831 
   834     |nm|
   832     |nm|
   835 
   833 
   836     self wasAutoloaded ifFalse:[
   834     self wasAutoloaded ifFalse:[
   837 
   835 
  1174 ! !
  1172 ! !
  1175 
  1173 
  1176 !Class methodsFor:'compiling'!
  1174 !Class methodsFor:'compiling'!
  1177 
  1175 
  1178 compile:code
  1176 compile:code
  1179     "compile code, aString for this class; if sucessful update method
  1177     "compile code, aString for this class; 
  1180      dictionary."
  1178      if sucessful update the method dictionary."
  1181 
  1179 
  1182     self compilerClass compile:code forClass:self
  1180     self compilerClass 
       
  1181 	compile:code 
       
  1182 	forClass:self
       
  1183 !
       
  1184 
       
  1185 compile:code classified:category
       
  1186     "compile code, aString for this class; 
       
  1187      if sucessful update the method dictionary. 
       
  1188      The method is classified under category."
       
  1189 
       
  1190     self compilerClass 
       
  1191 	compile:code 
       
  1192 	forClass:self 
       
  1193 	inCategory:category
  1183 !
  1194 !
  1184 
  1195 
  1185 compile:code notifying:requestor
  1196 compile:code notifying:requestor
  1186     "compile code, aString for this class; on any error, notify
  1197     "compile code, aString for this class; on any error, notify
  1187      requestor, anObject with the error reason"
  1198      requestor, anObject with the error reason."
  1188 
  1199 
  1189     self compilerClass compile:code forClass:self notifying:requestor
  1200     self compilerClass 
       
  1201 	compile:code 
       
  1202 	forClass:self 
       
  1203 	notifying:requestor
  1190 !
  1204 !
  1191 
  1205 
  1192 recompileMethodsAccessingAny:setOfNames
  1206 recompileMethodsAccessingAny:setOfNames
  1193     "recompile all methods accessing a variable from setOfNames"
  1207     "recompile all methods accessing a variable from setOfNames"
  1194 
  1208 
  1321      Point allCategories 
  1335      Point allCategories 
  1322     "
  1336     "
  1323 !
  1337 !
  1324 
  1338 
  1325 wasAutoloaded
  1339 wasAutoloaded
       
  1340     "return true, if this class came into the system via an
       
  1341      autoload; false otherwise.
       
  1342      This is not an attribute of the class, but instead remembered in
       
  1343      Autoload. The interface here is for covenience."
       
  1344 
  1326     ^ Autoload wasAutoloaded:self
  1345     ^ Autoload wasAutoloaded:self
       
  1346 !
       
  1347 
       
  1348 whichClassDefinesInstVar:aVariableName
       
  1349     "return the class which defines the instance variable
       
  1350      named aVariableName. This method should not be used for
       
  1351      repeated searches (i.e. in the compiler/parser), since it creates
       
  1352      many throw away intermediate objects."
       
  1353 
       
  1354     |cls|
       
  1355 
       
  1356     cls := self.
       
  1357     [cls notNil] whileTrue:[
       
  1358 	(cls instVarNames includes:aVariableName) ifTrue:[ ^ cls].
       
  1359 	cls := cls superclass
       
  1360     ].
       
  1361     ^ nil
       
  1362 
       
  1363     "
       
  1364      StandardSystemView whichClassDefinesInstVar:'label'  
       
  1365      StandardSystemView whichClassDefinesInstVar:'paint'  
       
  1366      StandardSystemView whichClassDefinesInstVar:'foo'  
       
  1367     "
       
  1368 !
       
  1369 
       
  1370 whichClassDefinesClassVar:aVariableName
       
  1371     "return the class which defines the class variable
       
  1372      named aVariableName. This method should not be used for
       
  1373      repeated searches (i.e. in the compiler/parser), since it creates
       
  1374      many throw away intermediate objects."
       
  1375 
       
  1376     |cls|
       
  1377 
       
  1378     cls := self.
       
  1379     [cls notNil] whileTrue:[
       
  1380 	(cls classVarNames includes:aVariableName) ifTrue:[ ^ cls].
       
  1381 	cls := cls superclass
       
  1382     ].
       
  1383     ^ nil
       
  1384 
       
  1385     "
       
  1386      StandardSystemView whichClassDefinesClassVar:'ErrorSignal'
       
  1387      StandardSystemView whichClassDefinesClassVar:'Foo'
       
  1388     "
  1327 ! !
  1389 ! !
  1328 
  1390 
  1329 !Class methodsFor:'private'!
  1391 !Class methodsFor:'private'!
  1330 
  1392 
  1331 addAllClassVarNamesTo:aCollection
  1393 addAllClassVarNamesTo:aCollection
  1376     "the primitiveSpec is either a string, or an integer specifying the
  1438     "the primitiveSpec is either a string, or an integer specifying the
  1377      position within the classes sourcefile ...
  1439      position within the classes sourcefile ...
  1378     "
  1440     "
  1379     pos isNumber ifTrue:[
  1441     pos isNumber ifTrue:[
  1380 	classFilename notNil ifTrue:[
  1442 	classFilename notNil ifTrue:[
  1381 	    stream := Smalltalk systemFileStreamFor:('source/' , classFilename).
  1443 	    stream := Smalltalk sourceFileStreamFor:classFilename.
  1382 	    stream notNil ifTrue:[
  1444 	    stream notNil ifTrue:[
  1383 		stream position:pos+1.
  1445 		stream position:pos+1.
  1384 		string := stream nextChunk.
  1446 		string := stream nextChunk.
  1385 		stream close.
  1447 		stream close.
  1386 		^ string
  1448 		^ string
  1751 	source isNil ifTrue:[
  1813 	source isNil ifTrue:[
  1752 	    FileOutErrorSignal 
  1814 	    FileOutErrorSignal 
  1753 		raiseRequestWith:self
  1815 		raiseRequestWith:self
  1754 		errorString:('no source for method: ' ,
  1816 		errorString:('no source for method: ' ,
  1755 			     self name , '>>' ,
  1817 			     self name , '>>' ,
  1756 			     (self selectorForMethod:aMethod))
  1818 			     (self selectorAtMethod:aMethod))
  1757 	] ifFalse:[
  1819 	] ifFalse:[
  1758 	    aStream nextChunkPut:(aMethod source).
  1820 	    aStream nextChunkPut:(aMethod source).
  1759 	].
  1821 	].
  1760 	aStream space.
  1822 	aStream space.
  1761 	aStream nextPut:sep.
  1823 	aStream nextPut:sep.
  1930      If the current project is not nil, create the file in the projects
  1992      If the current project is not nil, create the file in the projects
  1931      directory."
  1993      directory."
  1932 
  1994 
  1933     |aStream fileName selector|
  1995     |aStream fileName selector|
  1934 
  1996 
  1935     selector := self selectorForMethod:aMethod.
  1997     selector := self selectorAtMethod:aMethod.
  1936     selector notNil ifTrue:[
  1998     selector notNil ifTrue:[
  1937 	fileName := name , '-' , selector, '.st'.
  1999 	fileName := name , '-' , selector, '.st'.
  1938 	fileName replaceAll:$: by:$_.
  2000 	fileName replaceAll:$: by:$_.
  1939 	"
  2001 	"
  1940 	 this test allows a smalltalk to be built without Projects/ChangeSets
  2002 	 this test allows a smalltalk to be built without Projects/ChangeSets