check for references before removing a variable
authorClaus Gittinger <cg@exept.de>
Wed, 30 Sep 2009 09:53:34 +0200
changeset 8814 2eafcda487de
parent 8813 39184c1f09e6
child 8815 dd77b7871f5b
check for references before removing a variable
NewSystemBrowser.st
Tools__NewSystemBrowser.st
--- a/NewSystemBrowser.st	Wed Sep 30 08:59:48 2009 +0200
+++ b/NewSystemBrowser.st	Wed Sep 30 09:53:34 2009 +0200
@@ -24463,7 +24463,7 @@
 codeMenuRemoveClassVariable:oldName inClass:aClass
     "remove a class variable"
 
-    |cls change|
+    |cls change methods|
 
     (self askIfModified) ifFalse:[
         ^ self
@@ -24471,7 +24471,19 @@
 
     cls := aClass theNonMetaclass whichClassDefinesClassVar:oldName.
 
-"/    change := RemoveClassVariableRefactoring variable:oldName class:cls.
+    methods := self class 
+                    findClassRefsTo:oldName 
+                    under:cls theNonMetaclass access:#readOrWrite.
+    methods addAll:(self class 
+                    findClassRefsTo:oldName 
+                    under:cls theMetaclass access:#readOrWrite).
+    methods notEmpty ifTrue:[
+        (Dialog confirm:(resources 
+                            stringWithCRs:'"%1" is still referenced by %2 method(s).\\Remove anyway ?'
+                            with:oldName
+                            with:methods size)) ifFalse:[^ self].
+    ].
+
     change := RemoveClassVariableChange remove:oldName from:cls.
     self performRefactoring:change.
 !
@@ -24479,7 +24491,7 @@
 codeMenuRemoveInstanceVariable:oldName inClass:aClass
     "remove an instance variable"
 
-    |cls refactoring|
+    |cls refactoring methods|
 
     (self askIfModified) ifFalse:[ ^ self ].
 
@@ -24488,6 +24500,16 @@
         self error:'no class'
     ].
 
+    methods := self class 
+                    findInstRefsTo:oldName 
+                    under:cls access:#readOrWrite.
+    methods notEmpty ifTrue:[
+        (Dialog confirm:(resources 
+                            stringWithCRs:'"%1" is still referenced by %2 method(s).\\Remove anyway ?'
+                            with:oldName
+                            with:methods size)) ifFalse:[^ self].
+    ].
+
     refactoring := RemoveInstanceVariableChange remove:oldName from:cls.
     "/ refactoring := RemoveInstanceVariableRefactoring variable:oldName class:cls.
     "/ refactoring model name:('remove instvar %1 from %2' bindWith:oldName with:cls name).
@@ -32817,7 +32839,8 @@
 !
 
 browseVarRefsToAny:varNameList classes:classesIn variables:varType access:accessType all:browseAll title:browserTitle in:openHow
-    "Open a new browser or add a buffer showing methods referring/modifying to any var in varNames"
+    "Open a new browser or add a buffer showing methods referring/modifying to any var in varNames.
+     accessType is one of #readOrWrite, #read or #write."
 
     |varNames brwsr classes searchBlock methods|
 
@@ -33964,6 +33987,27 @@
     "Modified: / 12-09-2006 / 13:59:24 / cg"
 !
 
+variablesRemoveWithConfirmation
+    "remove selected variable(s)."
+
+    |variablesToRemove msg|
+
+    variablesToRemove := self selectedVariables value.
+    variablesToRemove size > 0 ifTrue:[
+        variablesToRemove size == 1 ifTrue:[
+            msg := 'Remove variable ''%1'' ?'
+        ] ifFalse:[
+            msg := 'Remove %2 selected variables ?'.
+        ].
+        (self confirm:(resources
+                    string:msg
+                    with:variablesToRemove first allBold
+                    with:variablesToRemove size)) ifTrue:[
+            self variablesMenuRemove
+        ].
+    ].
+!
+
 withSelectedVariableDo:aBlock
     "pull/push common code"
 
@@ -42359,25 +42403,15 @@
     "filter keyboard events for some function key.
      Return true, if I have eaten the event"
 
-    |variablesToRemove msg|
+    |variablesToRemove|
 
     (rawKey == #Delete) ifTrue:[
         variablesToRemove := self selectedVariables value.
         variablesToRemove size > 0 ifTrue:[
-            variablesToRemove size == 1 ifTrue:[
-                msg := 'Remove variable ''%1'' ?'
-            ] ifFalse:[
-                msg := 'Remove %2 selected variables ?'.
-            ].
-            (self confirm:(resources
-                        string:msg
-                        with:variablesToRemove first allBold
-                        with:variablesToRemove size)) ifTrue:[
-                self
-                    enqueueMessage:#variablesMenuRemove
-                    for:self
-                    arguments:#().
-            ].
+            self
+                enqueueMessage:#variablesRemoveWithConfirmation
+                for:self
+                arguments:#().
         ].
         ^ true
     ].
@@ -42483,11 +42517,11 @@
 !NewSystemBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Attic/NewSystemBrowser.st,v 1.1307 2009-09-30 06:59:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Attic/NewSystemBrowser.st,v 1.1308 2009-09-30 07:53:34 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Attic/NewSystemBrowser.st,v 1.1307 2009-09-30 06:59:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Attic/NewSystemBrowser.st,v 1.1308 2009-09-30 07:53:34 cg Exp $'
 ! !
 
 NewSystemBrowser initialize!
--- a/Tools__NewSystemBrowser.st	Wed Sep 30 08:59:48 2009 +0200
+++ b/Tools__NewSystemBrowser.st	Wed Sep 30 09:53:34 2009 +0200
@@ -24463,7 +24463,7 @@
 codeMenuRemoveClassVariable:oldName inClass:aClass
     "remove a class variable"
 
-    |cls change|
+    |cls change methods|
 
     (self askIfModified) ifFalse:[
         ^ self
@@ -24471,7 +24471,19 @@
 
     cls := aClass theNonMetaclass whichClassDefinesClassVar:oldName.
 
-"/    change := RemoveClassVariableRefactoring variable:oldName class:cls.
+    methods := self class 
+                    findClassRefsTo:oldName 
+                    under:cls theNonMetaclass access:#readOrWrite.
+    methods addAll:(self class 
+                    findClassRefsTo:oldName 
+                    under:cls theMetaclass access:#readOrWrite).
+    methods notEmpty ifTrue:[
+        (Dialog confirm:(resources 
+                            stringWithCRs:'"%1" is still referenced by %2 method(s).\\Remove anyway ?'
+                            with:oldName
+                            with:methods size)) ifFalse:[^ self].
+    ].
+
     change := RemoveClassVariableChange remove:oldName from:cls.
     self performRefactoring:change.
 !
@@ -24479,7 +24491,7 @@
 codeMenuRemoveInstanceVariable:oldName inClass:aClass
     "remove an instance variable"
 
-    |cls refactoring|
+    |cls refactoring methods|
 
     (self askIfModified) ifFalse:[ ^ self ].
 
@@ -24488,6 +24500,16 @@
         self error:'no class'
     ].
 
+    methods := self class 
+                    findInstRefsTo:oldName 
+                    under:cls access:#readOrWrite.
+    methods notEmpty ifTrue:[
+        (Dialog confirm:(resources 
+                            stringWithCRs:'"%1" is still referenced by %2 method(s).\\Remove anyway ?'
+                            with:oldName
+                            with:methods size)) ifFalse:[^ self].
+    ].
+
     refactoring := RemoveInstanceVariableChange remove:oldName from:cls.
     "/ refactoring := RemoveInstanceVariableRefactoring variable:oldName class:cls.
     "/ refactoring model name:('remove instvar %1 from %2' bindWith:oldName with:cls name).
@@ -32817,7 +32839,8 @@
 !
 
 browseVarRefsToAny:varNameList classes:classesIn variables:varType access:accessType all:browseAll title:browserTitle in:openHow
-    "Open a new browser or add a buffer showing methods referring/modifying to any var in varNames"
+    "Open a new browser or add a buffer showing methods referring/modifying to any var in varNames.
+     accessType is one of #readOrWrite, #read or #write."
 
     |varNames brwsr classes searchBlock methods|
 
@@ -33964,6 +33987,27 @@
     "Modified: / 12-09-2006 / 13:59:24 / cg"
 !
 
+variablesRemoveWithConfirmation
+    "remove selected variable(s)."
+
+    |variablesToRemove msg|
+
+    variablesToRemove := self selectedVariables value.
+    variablesToRemove size > 0 ifTrue:[
+        variablesToRemove size == 1 ifTrue:[
+            msg := 'Remove variable ''%1'' ?'
+        ] ifFalse:[
+            msg := 'Remove %2 selected variables ?'.
+        ].
+        (self confirm:(resources
+                    string:msg
+                    with:variablesToRemove first allBold
+                    with:variablesToRemove size)) ifTrue:[
+            self variablesMenuRemove
+        ].
+    ].
+!
+
 withSelectedVariableDo:aBlock
     "pull/push common code"
 
@@ -42359,25 +42403,15 @@
     "filter keyboard events for some function key.
      Return true, if I have eaten the event"
 
-    |variablesToRemove msg|
+    |variablesToRemove|
 
     (rawKey == #Delete) ifTrue:[
         variablesToRemove := self selectedVariables value.
         variablesToRemove size > 0 ifTrue:[
-            variablesToRemove size == 1 ifTrue:[
-                msg := 'Remove variable ''%1'' ?'
-            ] ifFalse:[
-                msg := 'Remove %2 selected variables ?'.
-            ].
-            (self confirm:(resources
-                        string:msg
-                        with:variablesToRemove first allBold
-                        with:variablesToRemove size)) ifTrue:[
-                self
-                    enqueueMessage:#variablesMenuRemove
-                    for:self
-                    arguments:#().
-            ].
+            self
+                enqueueMessage:#variablesRemoveWithConfirmation
+                for:self
+                arguments:#().
         ].
         ^ true
     ].
@@ -42483,11 +42517,11 @@
 !NewSystemBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.1307 2009-09-30 06:59:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.1308 2009-09-30 07:53:34 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.1307 2009-09-30 06:59:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__NewSystemBrowser.st,v 1.1308 2009-09-30 07:53:34 cg Exp $'
 ! !
 
 NewSystemBrowser initialize!