CypressClass.st
changeset 12 ec118792047a
parent 11 333528cd629a
child 13 f90704544ca0
--- a/CypressClass.st	Mon Sep 10 23:52:10 2012 +0000
+++ b/CypressClass.st	Tue Sep 11 10:56:07 2012 +0000
@@ -13,7 +13,7 @@
 fromClass: aClass
     "Returns a CypressPackage for given (real) class"
 
-    ^self class initializeFromClass: aClass.
+    ^self new initializeFromClass: aClass.
 
     "Created: / 10-09-2012 / 23:48:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
@@ -49,7 +49,7 @@
         at:'name'           put: aClass nameWithoutPrefix;
         at:'super'          put: aClass superclass nameWithoutPrefix;
         at:'namespace'      put: aClass nameSpace nameWithoutPrefix;
-        at:'superNamespace' put: aClass nameSpace nameSpace;
+        at:'superNamespace' put: aClass nameSpace nameSpace name;
 
         at:'instvars'       put: aClass instVarNames;
         at:'classinstvars'  put: aClass class instVarNames;
@@ -65,6 +65,12 @@
     ].
 
     "Created: / 10-09-2012 / 23:48:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+initializeWithMethods: aCollection
+    methods := aCollection
+
+    "Created: / 11-09-2012 / 11:15:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CypressClass methodsFor:'reading & writing'!
@@ -75,11 +81,61 @@
     ^ self shouldImplement
 !
 
-writeTo:filename notice:copyrightNotice
-    "Writes the receiver into directory/file named 'filename'
-     with given copyrightNotice"
+writeTo:directory notice:copyrightNotice
+     "Writes the receiver into given 'directory' with
+      copyrightNotice in each file"
+
+    | dir |
+
+    dir := directory asFilename.
+    dir exists ifFalse: [ dir recursiveMakeDirectory ].
+
+
+    self writePropertiesTo: directory notice: copyrightNotice.
+    self writeMethodsTo: directory notice: copyrightNotice.
+
+    "Modified (comment): / 11-09-2012 / 11:19:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CypressClass methodsFor:'reading & writing - private'!
+
+writeMethodsTo:directory notice:copyrightNotice
+     "Writes methods into given 'directory' with copyrightNotice in each file"
+
+    | obsolete instDir classDir |
+
+    instDir := directory / 'instance'.
+    classDir := directory / 'class'.
 
-    ^ self shouldImplement
+    " collect possibly obsolete directories/files "
+    obsolete := Set new.
+    instDir exists ifTrue:[
+        obsolete add: instDir.
+        obsolete add: instDir directoryContentsAsFilenames
+    ].
+    classDir exists ifTrue:[
+        obsolete add: classDir.
+        obsolete add: classDir directoryContentsAsFilenames
+    ].
+
+    self methods do:[:cpsMthd|
+        | dir dottedSel file  |
+
+        dir := cpsMthd meta ifTrue:[classDir] ifFalse:[instDir].
+        dir exists ifFalse:[ dir makeDirectory ].
+        file := dir / ((dottedSel := cpsMthd selector copyReplaceAll:$: with: $.) , '.st').
+        cpsMthd writeTo: file notice:copyrightNotice.
+        obsolete := obsolete reject:[:each|
+            each withoutSuffix baseName = dottedSel
+        ].
+    ].
+
+    " wipe out obsolete directories / files  "
+    obsolete do:[:each|
+        each exists ifTrue:[ each recursiveRemove ]
+    ].
+
+    "Created: / 11-09-2012 / 11:19:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CypressClass class methodsFor:'documentation'!