ClassDefinitionChange.st
branchjv
changeset 3058 c4388bddfcb1
parent 3042 48e76977cdc3
child 3062 3bef6850206d
equal deleted inserted replaced
3057:99b7b9518c91 3058:c4388bddfcb1
   194 
   194 
   195     objectType := something.
   195     objectType := something.
   196 !
   196 !
   197 
   197 
   198 poolDictionaries
   198 poolDictionaries
       
   199     poolDictionaries isNil ifTrue:[
       
   200         self setupFromSource.
       
   201     ].
   199     ^ poolDictionaries
   202     ^ poolDictionaries
       
   203 
       
   204     "Modified: / 13-06-2012 / 12:23:41 / cg"
   200 !
   205 !
   201 
   206 
   202 poolDictionaries:something
   207 poolDictionaries:something
   203     poolDictionaries := something.
   208     poolDictionaries := something.
   204 !
   209 !
   338 ! !
   343 ! !
   339 
   344 
   340 !ClassDefinitionChange methodsFor:'printing & storing'!
   345 !ClassDefinitionChange methodsFor:'printing & storing'!
   341 
   346 
   342 definitionString
   347 definitionString
   343     |ns classNameUsed superClassNameUsed|
   348     |ns classNameUsed superClassNameUsed selPart|
   344 
   349 
   345     ns := self nameSpaceOverride.
   350     ns := self nameSpaceOverride.
   346 
   351 
   347     objectType == #variable ifTrue:[
   352     objectType == #variable ifTrue:[
   348         ^ String streamContents:[:stream |
   353         ^ String streamContents:[:stream |
   349             ns notNil ifTrue:[
   354             ns notNil ifTrue:[
   350                 stream 
   355                 stream nextPutAll:((ns asCollectionOfSubstringsSeparatedBy:$.) asStringWith:'::')
   351                     nextPutAll:((ns asCollectionOfSubstringsSeparatedBy:$.) asStringWith:'::')
       
   352             ] ifFalse:[
   356             ] ifFalse:[
   353                 self halt:'can this happen ?'.
   357                 self halt:'can this happen ?'.
   354                 stream 
   358                 stream nextPutAll:'Smalltalk'
   355                     nextPutAll:'Smalltalk'
       
   356             ].
   359             ].
   357 
   360 
   358             stream 
   361             stream 
   359                 nextPutAll:' addClassVarName:';
   362                 nextPutAll:' addClassVarName:';
   360                 nextPutAll:className asString storeString
   363                 nextPutAll:className asString storeString
   361           ].
   364           ].
   362     ].
   365     ].
   363 
   366 
   364     superClassNameUsed := self superClassName.
   367     superClassNameUsed := self superClassName.
   365     classNameUsed := self className.
   368     classNameUsed := self className.
       
   369     selPart := (self definitionSelector ? #'subclass:instanceVariableNames:classVariableNames:poolDictionaries:category:')
       
   370                     keywords first.         
   366 
   371 
   367     ^ String streamContents:[:stream |
   372     ^ String streamContents:[:stream |
   368         self isPrivateClassDefinitionChange ifFalse:[
   373         stream 
       
   374             nextPutAll:superClassNameUsed;
       
   375             nextPutAll:' ',selPart;
       
   376             nextPutAll: classNameUsed asSymbol storeString;
       
   377             cr;
       
   378             spaces:4;
       
   379             nextPutAll:'instanceVariableNames: ';
       
   380             nextPutAll:(instanceVariableNames ? '') storeString;
       
   381             cr;
       
   382             spaces:4;
       
   383             nextPutAll:'classVariableNames: ';
       
   384             nextPutAll:(classVariableNames ? '') storeString;
       
   385             cr;
       
   386             spaces:4;
       
   387             nextPutAll:'poolDictionaries: ';
       
   388             nextPutAll:(poolDictionaries ? '') storeString;
       
   389             cr.
       
   390         private == true ifTrue:[
   369             stream 
   391             stream 
   370                 nextPutAll:superClassNameUsed;
   392                 spaces:4;
   371                 nextPutAll:' subclass:';
   393                 nextPutAll:'privateIn: ';
   372                 nextPutAll: classNameUsed asSymbol storeString
   394                 nextPutAll:(self owningClassName)
   373                 ;
   395         ] ifFalse:[
   374                 cr;
       
   375                 tab;
       
   376                 nextPutAll:'instanceVariableNames:';
       
   377                 nextPutAll:(instanceVariableNames ? '') storeString;
       
   378                 cr;
       
   379                 tab;
       
   380                 nextPutAll:'classVariableNames:';
       
   381                 nextPutAll:(classVariableNames ? '') storeString;
       
   382                 cr;
       
   383                 tab;
       
   384                 nextPutAll:'poolDictionaries:';
       
   385                 nextPutAll:(poolDictionaries ? '') storeString;
       
   386                 cr;
       
   387                 tab;
       
   388                 nextPutAll:'category:';
       
   389                 nextPutAll:(category ? '') storeString;
       
   390                 cr
       
   391         ] ifTrue:[
       
   392             stream 
   396             stream 
   393                 nextPutAll:superClassNameUsed;
   397                 spaces:4;
   394                 nextPutAll:' subclass:';
   398                 nextPutAll:'category: ';
   395                 nextPutAll: (classNameUsed copyFrom: owningClassName size + 3) asSymbol storeString
   399                 nextPutAll:(category ? '') storeString
   396                 ;
   400         ].
   397                 cr;
   401       ]
   398                 tab;
   402 
   399                 nextPutAll:'instanceVariableNames:';
   403     "Modified: / 13-06-2012 / 13:01:58 / cg"
   400                 nextPutAll:(instanceVariableNames ? '') storeString;
       
   401                 cr;
       
   402                 tab;
       
   403                 nextPutAll:'classVariableNames:';
       
   404                 nextPutAll:(classVariableNames ? '') storeString;
       
   405                 cr;
       
   406                 tab;
       
   407                 nextPutAll:'poolDictionaries:';
       
   408                 nextPutAll:(poolDictionaries ? '') storeString;
       
   409                 cr;
       
   410                 tab;
       
   411                 nextPutAll:'privateIn:';
       
   412                 nextPutAll:owningClassName;
       
   413                 cr
       
   414         ]
       
   415     ]
       
   416 
       
   417     "Modified: / 06-10-2011 / 17:02:05 / cg"
       
   418     "Modified: / 19-03-2012 / 19:19:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   419 !
       
   420 
       
   421 definitionStringInNamespace: ns
       
   422     | classNameUsed superClassNameUsed |
       
   423 
       
   424     objectType == #variable ifTrue:[
       
   425         ^ String streamContents:[:stream |
       
   426             ns notNil ifTrue:[
       
   427                 stream 
       
   428                     nextPutAll:((ns asCollectionOfSubstringsSeparatedBy:$.) asStringWith:'::')
       
   429             ] ifFalse:[
       
   430                 self halt:'can this happen ?'.
       
   431                 stream 
       
   432                     nextPutAll:'Smalltalk'
       
   433             ].
       
   434 
       
   435             stream 
       
   436                 nextPutAll:' addClassVarName:';
       
   437                 nextPutAll:className asString storeString
       
   438           ].
       
   439     ].
       
   440 
       
   441     superClassNameUsed := self superClassName.
       
   442     classNameUsed := self classNameWithoutNamespace.
       
   443 
       
   444     ^ String streamContents:[:stream |
       
   445         self isPrivateClassDefinitionChange ifFalse:[
       
   446             stream 
       
   447                 nextPutAll:superClassNameUsed ? 'nil';
       
   448                 nextPutAll:' subclass:';
       
   449                 nextPutAll: classNameUsed asSymbol storeString
       
   450                 ;
       
   451                 cr;
       
   452                 tab;
       
   453                 nextPutAll:'instanceVariableNames:';
       
   454                 nextPutAll:(instanceVariableNames ? '') storeString;
       
   455                 cr;
       
   456                 tab;
       
   457                 nextPutAll:'classVariableNames:';
       
   458                 nextPutAll:(classVariableNames ? '') storeString;
       
   459                 cr;
       
   460                 tab;
       
   461                 nextPutAll:'poolDictionaries:';
       
   462                 nextPutAll:(poolDictionaries ? '') storeString;
       
   463                 cr;
       
   464                 tab;
       
   465                 nextPutAll:'category:';
       
   466                 nextPutAll:(category ? '') storeString;
       
   467                 cr
       
   468         ] ifTrue:[
       
   469             stream 
       
   470                 nextPutAll:superClassNameUsed;
       
   471                 nextPutAll:' subclass:';
       
   472                 nextPutAll: (self className copyFrom: owningClassName size + 3) asSymbol storeString
       
   473                 ;
       
   474                 cr;
       
   475                 tab;
       
   476                 nextPutAll:'instanceVariableNames:';
       
   477                 nextPutAll:(instanceVariableNames ? '') storeString;
       
   478                 cr;
       
   479                 tab;
       
   480                 nextPutAll:'classVariableNames:';
       
   481                 nextPutAll:(classVariableNames ? '') storeString;
       
   482                 cr;
       
   483                 tab;
       
   484                 nextPutAll:'poolDictionaries:';
       
   485                 nextPutAll:(poolDictionaries ? '') storeString;
       
   486                 cr;
       
   487                 tab;
       
   488                 nextPutAll:'privateIn:';
       
   489                 nextPutAll:
       
   490                     (ns isNil
       
   491                         ifTrue:[owningClassName]
       
   492                         ifFalse:[owningClassName copyFrom: ns size + 3]);
       
   493                 cr
       
   494         ]
       
   495     ]
       
   496 
       
   497     "Modified: / 06-10-2011 / 17:02:05 / cg"
       
   498     "Created: / 20-03-2012 / 19:40:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   499 !
       
   500 
       
   501 definitionStringWithoutNamespace
       
   502     |ns classNameUsed superClassNameUsed|
       
   503 
       
   504     ns := self nameSpaceOverride.
       
   505 
       
   506     objectType == #variable ifTrue:[
       
   507         ^ String streamContents:[:stream |
       
   508             ns notNil ifTrue:[
       
   509                 stream 
       
   510                     nextPutAll:((ns asCollectionOfSubstringsSeparatedBy:$.) asStringWith:'::')
       
   511             ] ifFalse:[
       
   512                 self halt:'can this happen ?'.
       
   513                 stream 
       
   514                     nextPutAll:'Smalltalk'
       
   515             ].
       
   516 
       
   517             stream 
       
   518                 nextPutAll:' addClassVarName:';
       
   519                 nextPutAll:className asString storeString
       
   520           ].
       
   521     ].
       
   522 
       
   523     superClassNameUsed := self superClassName.
       
   524     classNameUsed := self classNameWithoutNamespace.
       
   525 
       
   526     ^ String streamContents:[:stream |
       
   527         self isPrivateClassDefinitionChange ifFalse:[
       
   528             stream 
       
   529                 nextPutAll:superClassNameUsed;
       
   530                 nextPutAll:' subclass:';
       
   531                 nextPutAll: classNameUsed asSymbol storeString
       
   532                 ;
       
   533                 cr;
       
   534                 tab;
       
   535                 nextPutAll:'instanceVariableNames:';
       
   536                 nextPutAll:(instanceVariableNames ? '') storeString;
       
   537                 cr;
       
   538                 tab;
       
   539                 nextPutAll:'classVariableNames:';
       
   540                 nextPutAll:(classVariableNames ? '') storeString;
       
   541                 cr;
       
   542                 tab;
       
   543                 nextPutAll:'poolDictionaries:';
       
   544                 nextPutAll:(poolDictionaries ? '') storeString;
       
   545                 cr;
       
   546                 tab;
       
   547                 nextPutAll:'category:';
       
   548                 nextPutAll:(category ? '') storeString;
       
   549                 cr
       
   550         ] ifTrue:[
       
   551             stream 
       
   552                 nextPutAll:superClassNameUsed;
       
   553                 nextPutAll:' subclass:';
       
   554                 nextPutAll: (self className copyFrom: owningClassName size + 3) asSymbol storeString
       
   555                 ;
       
   556                 cr;
       
   557                 tab;
       
   558                 nextPutAll:'instanceVariableNames:';
       
   559                 nextPutAll:(instanceVariableNames ? '') storeString;
       
   560                 cr;
       
   561                 tab;
       
   562                 nextPutAll:'classVariableNames:';
       
   563                 nextPutAll:(classVariableNames ? '') storeString;
       
   564                 cr;
       
   565                 tab;
       
   566                 nextPutAll:'poolDictionaries:';
       
   567                 nextPutAll:(poolDictionaries ? '') storeString;
       
   568                 cr;
       
   569                 tab;
       
   570                 nextPutAll:'privateIn:';
       
   571                 nextPutAll:
       
   572                     ((ns := self nameSpaceName) isNil
       
   573                         ifTrue:[owningClassName]
       
   574                         ifFalse:[owningClassName copyFrom: ns size + 3]);
       
   575                 cr
       
   576         ]
       
   577     ]
       
   578 
       
   579     "Modified: / 06-10-2011 / 17:02:05 / cg"
       
   580     "Created: / 20-03-2012 / 16:37:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   581 !
   404 !
   582 
   405 
   583 printOn:aStream
   406 printOn:aStream
   584     aStream 
   407     aStream 
   585         nextPutAll:className; nextPutAll:' {definition}'
   408         nextPutAll:className; nextPutAll:' {definition}'
   600         self setupFromSource.
   423         self setupFromSource.
   601     ].
   424     ].
   602     ^ definitionSelector
   425     ^ definitionSelector
   603 
   426 
   604     "Modified: / 11-10-2006 / 14:11:44 / cg"
   427     "Modified: / 11-10-2006 / 14:11:44 / cg"
       
   428 !
       
   429 
       
   430 definitionSelector:aSelector
       
   431     definitionSelector := aSelector
       
   432 
       
   433     "Created: / 13-06-2012 / 12:45:02 / cg"
   605 !
   434 !
   606 
   435 
   607 isClassDefinitionChange
   436 isClassDefinitionChange
   608     ^ true
   437     ^ true
   609 !
   438 !
   716 !
   545 !
   717 
   546 
   718 setupFromSource
   547 setupFromSource
   719     "extract privacy, category and selector from the source"
   548     "extract privacy, category and selector from the source"
   720 
   549 
   721     |parseTree idx|
   550     |parseTree catIdx poolIdx|
   722 
   551 
   723     source notNil ifTrue:[
   552     source notNil ifTrue:[
   724         parseTree := Parser parseExpression:source.
   553         parseTree := Parser parseExpression:source.
   725         (parseTree notNil and:[parseTree isMessage]) ifFalse:[
   554         (parseTree notNil and:[parseTree isMessage]) ifFalse:[
   726             self error:'bad change source' mayProceed:true.
   555             self error:'bad change source' mayProceed:true.
   732         private := (definitionSelector endsWith:':privateIn:').
   561         private := (definitionSelector endsWith:':privateIn:').
   733         private ifTrue:[
   562         private ifTrue:[
   734             owningClassName := parseTree args last name.
   563             owningClassName := parseTree args last name.
   735         ].
   564         ].
   736 
   565 
   737         #(  instanceVariableNames: 
   566         catIdx := definitionSelector keywords indexOf:'category:'.  
   738             classVariableNames: 
   567         catIdx ~~ 0 ifTrue:[
   739             poolDictionaries:
   568             category := (parseTree args at:catIdx) evaluate.
   740         ) do:[:kw|
   569         ].
   741             idx := definitionSelector keywords indexOf:kw.  
   570 
   742             idx ~~ 0 ifTrue:[
   571         poolIdx := definitionSelector keywords indexOf:'poolDictionaries:'.  
   743                 self perform: kw with: (parseTree args at:idx) evaluate.
   572         poolIdx ~~ 0 ifTrue:[
   744             ].
   573             poolDictionaries := (parseTree args at:poolIdx) evaluate.
   745         ].
   574         ].
   746 
   575 
   747         superClassName := parseTree receiver name.
   576         superClassName := parseTree receiver name.
   748     ].
   577     ].
   749 
   578 
   750     "Created: / 11-10-2006 / 14:10:02 / cg"
   579     "Created: / 11-10-2006 / 14:10:02 / cg"
   751     "Modified: / 26-10-2006 / 19:29:17 / cg"
   580     "Modified: / 08-11-2010 / 13:47:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   752     "Modified: / 21-03-2012 / 01:12:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   581     "Modified: / 13-06-2012 / 12:25:10 / cg"
   753 ! !
   582 ! !
   754 
   583 
   755 !ClassDefinitionChange methodsFor:'visiting'!
   584 !ClassDefinitionChange methodsFor:'visiting'!
   756 
   585 
   757 acceptChangeVisitor:aVisitor
   586 acceptChangeVisitor:aVisitor
   761 ! !
   590 ! !
   762 
   591 
   763 !ClassDefinitionChange class methodsFor:'documentation'!
   592 !ClassDefinitionChange class methodsFor:'documentation'!
   764 
   593 
   765 version
   594 version
   766     ^ '$Id: ClassDefinitionChange.st 1909 2012-03-31 00:14:49Z vranyj1 $'
   595     ^ '$Header: /cvs/stx/stx/libbasic3/ClassDefinitionChange.st,v 1.70 2012/06/13 11:03:04 cg Exp $'
   767 !
   596 !
   768 
   597 
   769 version_CVS
   598 version_CVS
   770     ^ '§Header: /cvs/stx/stx/libbasic3/ClassDefinitionChange.st,v 1.66 2012/01/24 22:17:07 vrany Exp §'
   599     ^ 'Header: /cvs/stx/stx/libbasic3/ClassDefinitionChange.st,v 1.70 2012/06/13 11:03:04 cg Exp '
   771 !
   600 !
   772 
   601 
   773 version_SVN
   602 version_SVN
   774     ^ '$Id: ClassDefinitionChange.st 1909 2012-03-31 00:14:49Z vranyj1 $'
   603     ^ '$ Id: ClassDefinitionChange.st 1867 2011-06-08 21:57:08Z vranyj1  $'
   775 ! !
   604 ! !