Class.st
changeset 2553 4993919699a3
parent 2544 c3a2791de289
child 2561 205ee33decf9
equal deleted inserted replaced
2552:c4eae9ddfd0a 2553:4993919699a3
  2753      directory. Care is taken, to not clobber any existing file in
  2753      directory. Care is taken, to not clobber any existing file in
  2754      case of errors (for example: disk full). 
  2754      case of errors (for example: disk full). 
  2755      Also, since the classes methods need a valid sourcefile, the current 
  2755      Also, since the classes methods need a valid sourcefile, the current 
  2756      sourceFile may not be rewritten."
  2756      sourceFile may not be rewritten."
  2757 
  2757 
  2758     |aStream baseName dirName fileNameString fileName newFileName needRename
  2758     |baseName dirName fileNameString|
  2759      mySourceFileName sameFile s mySourceFileID anySourceRef|
       
  2760 
  2759 
  2761     baseName := (Smalltalk fileNameForClass:self name).
  2760     baseName := (Smalltalk fileNameForClass:self name).
  2762     fileNameString := baseName , '.st'.
  2761     fileNameString := baseName , '.st'.
  2763 
  2762 
  2764     "
  2763     "
  2768         dirName := Project currentProjectDirectory
  2767         dirName := Project currentProjectDirectory
  2769     ] ifFalse:[
  2768     ] ifFalse:[
  2770         dirName := ''
  2769         dirName := ''
  2771     ].
  2770     ].
  2772     fileNameString := dirName , fileNameString.
  2771     fileNameString := dirName , fileNameString.
       
  2772 
       
  2773     self fileOutAs:fileNameString.
       
  2774 
       
  2775     "
       
  2776      add a change record; that way, administration is much easier,
       
  2777      since we can see in that changeBrowser, which changes have 
       
  2778      already found their way into a sourceFile and which must be
       
  2779      applied again
       
  2780     "
       
  2781     self addChangeRecordForClassFileOut:self
       
  2782 
       
  2783     "Modified: 7.6.1996 / 09:14:43 / stefan"
       
  2784     "Modified: 16.4.1997 / 20:45:33 / cg"
       
  2785 !
       
  2786 
       
  2787 fileOutAllDefinitionsOn:aStream
       
  2788     "append expressions on aStream, which defines myself and all of my private classes."
       
  2789 
       
  2790     self fileOutDefinitionOn:aStream.
       
  2791     aStream nextPutChunkSeparator. 
       
  2792     aStream cr; cr.
       
  2793 
       
  2794     "/
       
  2795     "/ optional classInstanceVariables
       
  2796     "/
       
  2797     self class instanceVariableString isBlank ifFalse:[
       
  2798         self fileOutClassInstVarDefinitionOn:aStream.
       
  2799         aStream nextPutChunkSeparator. 
       
  2800         aStream cr; cr
       
  2801     ].
       
  2802 
       
  2803     self privateClassesSorted do:[:aClass |
       
  2804         aClass fileOutAllDefinitionsOn:aStream
       
  2805     ]
       
  2806 
       
  2807     "Created: 15.10.1996 / 11:15:19 / cg"
       
  2808     "Modified: 22.3.1997 / 16:11:56 / cg"
       
  2809 !
       
  2810 
       
  2811 fileOutAllMethodsOn:aStream
       
  2812     |collectionOfCategories|
       
  2813 
       
  2814     collectionOfCategories := self class categories asSortedCollection.
       
  2815     collectionOfCategories notNil ifTrue:[
       
  2816         collectionOfCategories do:[:aCategory |
       
  2817             self class fileOutCategory:aCategory on:aStream.
       
  2818             aStream cr
       
  2819         ]
       
  2820     ].
       
  2821     collectionOfCategories := self categories asSortedCollection.
       
  2822     collectionOfCategories notNil ifTrue:[
       
  2823         collectionOfCategories do:[:aCategory |
       
  2824             self fileOutCategory:aCategory on:aStream.
       
  2825             aStream cr
       
  2826         ]
       
  2827     ].
       
  2828 
       
  2829     self privateClassesSorted do:[:aClass |
       
  2830         aClass fileOutAllMethodsOn:aStream
       
  2831     ].
       
  2832 
       
  2833     "Created: 15.10.1996 / 11:13:00 / cg"
       
  2834     "Modified: 22.3.1997 / 16:12:17 / cg"
       
  2835 !
       
  2836 
       
  2837 fileOutAs:fileNameString
       
  2838     "create a file consisting of all methods in myself in
       
  2839      sourceForm, from which the class can be reconstructed (by filing in).
       
  2840      The given fileName should be a full path, including suffix.
       
  2841      If the current project is not nil, create the file in the projects
       
  2842      directory. Care is taken, to not clobber any existing file in
       
  2843      case of errors (for example: disk full). 
       
  2844      Also, since the classes methods need a valid sourcefile, the current 
       
  2845      sourceFile may not be rewritten."
       
  2846 
       
  2847     |aStream baseName dirName fileName newFileName needRename
       
  2848      mySourceFileName sameFile s mySourceFileID anySourceRef|
       
  2849 
       
  2850     baseName := fileNameString asFilename baseName.
       
  2851     dirName := fileNameString asFilename directoryName.
  2773     fileName := fileNameString asFilename.
  2852     fileName := fileNameString asFilename.
  2774 
  2853 
  2775     "
  2854     "
  2776      if file exists, copy the existing to a .sav-file,
  2855      if file exists, copy the existing to a .sav-file,
  2777      create the new file as XXX.new-file,
  2856      create the new file as XXX.new-file,
  2862     "
  2941     "
  2863     self addChangeRecordForClassFileOut:self
  2942     self addChangeRecordForClassFileOut:self
  2864 
  2943 
  2865     "Modified: 7.6.1996 / 09:14:43 / stefan"
  2944     "Modified: 7.6.1996 / 09:14:43 / stefan"
  2866     "Modified: 1.11.1996 / 20:23:57 / cg"
  2945     "Modified: 1.11.1996 / 20:23:57 / cg"
  2867 !
  2946     "Created: 16.4.1997 / 20:44:05 / cg"
  2868 
       
  2869 fileOutAllDefinitionsOn:aStream
       
  2870     "append expressions on aStream, which defines myself and all of my private classes."
       
  2871 
       
  2872     self fileOutDefinitionOn:aStream.
       
  2873     aStream nextPutChunkSeparator. 
       
  2874     aStream cr; cr.
       
  2875 
       
  2876     "/
       
  2877     "/ optional classInstanceVariables
       
  2878     "/
       
  2879     self class instanceVariableString isBlank ifFalse:[
       
  2880         self fileOutClassInstVarDefinitionOn:aStream.
       
  2881         aStream nextPutChunkSeparator. 
       
  2882         aStream cr; cr
       
  2883     ].
       
  2884 
       
  2885     self privateClassesSorted do:[:aClass |
       
  2886         aClass fileOutAllDefinitionsOn:aStream
       
  2887     ]
       
  2888 
       
  2889     "Created: 15.10.1996 / 11:15:19 / cg"
       
  2890     "Modified: 22.3.1997 / 16:11:56 / cg"
       
  2891 !
       
  2892 
       
  2893 fileOutAllMethodsOn:aStream
       
  2894     |collectionOfCategories|
       
  2895 
       
  2896     collectionOfCategories := self class categories asSortedCollection.
       
  2897     collectionOfCategories notNil ifTrue:[
       
  2898         collectionOfCategories do:[:aCategory |
       
  2899             self class fileOutCategory:aCategory on:aStream.
       
  2900             aStream cr
       
  2901         ]
       
  2902     ].
       
  2903     collectionOfCategories := self categories asSortedCollection.
       
  2904     collectionOfCategories notNil ifTrue:[
       
  2905         collectionOfCategories do:[:aCategory |
       
  2906             self fileOutCategory:aCategory on:aStream.
       
  2907             aStream cr
       
  2908         ]
       
  2909     ].
       
  2910 
       
  2911     self privateClassesSorted do:[:aClass |
       
  2912         aClass fileOutAllMethodsOn:aStream
       
  2913     ].
       
  2914 
       
  2915     "Created: 15.10.1996 / 11:13:00 / cg"
       
  2916     "Modified: 22.3.1997 / 16:12:17 / cg"
       
  2917 !
  2947 !
  2918 
  2948 
  2919 fileOutCategory:aCategory
  2949 fileOutCategory:aCategory
  2920     "create a file 'class-category.st' consisting of all methods in aCategory.
  2950     "create a file 'class-category.st' consisting of all methods in aCategory.
  2921      If the current project is not nil, create the file in the projects
  2951      If the current project is not nil, create the file in the projects
  4889 ! !
  4919 ! !
  4890 
  4920 
  4891 !Class class methodsFor:'documentation'!
  4921 !Class class methodsFor:'documentation'!
  4892 
  4922 
  4893 version
  4923 version
  4894     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.273 1997-04-13 00:18:58 cg Exp $'
  4924     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.274 1997-04-16 18:48:27 cg Exp $'
  4895 ! !
  4925 ! !
  4896 Class initialize!
  4926 Class initialize!