added option of generating aspects as instvars.
authorClaus Gittinger <cg@exept.de>
Wed, 29 Jul 1998 13:26:10 +0200
changeset 925 e6ddd46581c3
parent 924 0416d7cbae92
child 926 04887448fab8
added option of generating aspects as instvars.
UIPainterView.st
--- a/UIPainterView.st	Wed Jul 29 13:23:19 1998 +0200
+++ b/UIPainterView.st	Wed Jul 29 13:26:10 1998 +0200
@@ -13,7 +13,7 @@
 UIObjectView subclass:#UIPainterView
 	instanceVariableNames:'treeView listHolder superclassName className methodName
 		categoryName handleColor handleMasterColor'
-	classVariableNames:'HandCursor RedefineAspectMethods'
+	classVariableNames:'HandCursor RedefineAspectMethods AspectsAsInstances'
 	poolDictionaries:''
 	category:'Interface-UIPainter'
 !
@@ -58,6 +58,26 @@
 
 !UIPainterView class methodsFor:'code generation mode'!
 
+generateAspectsAsInstanceVariables
+    "if on, aspects are held as instance variables;
+     if off (the default), they are kept in the bindings dictionary.
+    "
+    ^ AspectsAsInstances
+
+    "Created: / 29.7.1998 / 11:21:38 / cg"
+    "Modified: / 29.7.1998 / 11:22:01 / cg"
+!
+
+generateAspectsAsInstanceVariables:aBoolean
+    "if on, aspects are held as instance variables;
+     if off (the default), they are kept in the bindings dictionary.
+    "
+    AspectsAsInstances := aBoolean
+
+    "Created: / 29.7.1998 / 11:21:26 / cg"
+    "Modified: / 29.7.1998 / 11:22:11 / cg"
+!
+
 redefineAspectMethods
     "redefine methods yes or no. If a method is defined in super class
      should the message be reinstalled ?
@@ -639,18 +659,26 @@
       '    "*** (which may not be the one you wanted)"\' ,
       '    "*** Please change as required and accept in the browser."\'.
 
-    code := (code ,
-      '\' ,
-      '    |holder|\' ,
-      '\' ,
-      '    (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' ,
-      '        builder aspectAt:#' , aspect , ' put:(holder := ' , ' ' , modelGen , ').\' ,
-      '    ].\' ,
-      '    ^ holder\' ,
-      '!! !!\\') withCRs.
-    ^ code
+    AspectsAsInstances ifTrue:[
+        code := (code , '\' ,
+          '    ' , aspect , ' isNil ifTrue:[\' ,
+          '        ' , aspect , ' := ' , ' ' , modelGen , '.\' ,
+          '    ].\' ,
+          '    ^ ' , aspect ,'.\' ,
+          '!! !!\\') 
+    ] ifFalse:[
+        code := (code , '\' ,
+          '    |holder|\' ,
+          '\' ,
+          '    (holder := builder bindingAt:#' , aspect , ') isNil ifTrue:[\' ,
+          '        builder aspectAt:#' , aspect , ' put:(holder := ' , ' ' , modelGen , ').\' ,
+          '    ].\' ,
+          '    ^ holder.\' ,
+          '!! !!\\') 
+    ].
+    ^ code withCRs
 
-    "Modified: / 5.6.1998 / 01:17:41 / cg"
+    "Modified: / 29.7.1998 / 11:29:16 / cg"
 !
 
 generateAspectMethods
@@ -659,7 +687,7 @@
      Return a string ready to compile into the application class."
 
     |cls code skip menuSelector protoSpec thisCode
-     definedMethodSelectors|
+     definedMethodSelectors iVars t|
 
     definedMethodSelectors := IdentitySet new.
 
@@ -750,9 +778,21 @@
                 ].
     ].
 
+    AspectsAsInstances ifTrue:[
+        iVars := cls instVarNames asOrderedCollection.
+        definedMethodSelectors do:[:ivar |
+            (iVars includes:ivar) ifFalse:[
+                iVars add:ivar
+            ]
+        ].
+        iVars := iVars asArray.
+        t := cls shallowCopy.
+        t setInstanceVariableString:iVars asStringCollection asString.
+        code := (t definition) , '!!\' withCRs , code.
+    ].
     ^ code
 
-    "Modified: / 5.6.1998 / 01:21:35 / cg"
+    "Modified: / 29.7.1998 / 12:21:19 / cg"
 !
 
 generateCodeFrom:aListOfSelectors in:aClass do:aBlock