Tools__MethodRewriter.st
changeset 17004 04522250f6ce
parent 16514 0a071f68ea56
child 17136 cb908d2ba02e
child 17883 88acb0d3c7b1
--- a/Tools__MethodRewriter.st	Wed Nov 02 14:50:26 2016 +0100
+++ b/Tools__MethodRewriter.st	Wed Nov 02 15:30:56 2016 +0100
@@ -216,75 +216,89 @@
 
     <resource: #canvas>
 
-    ^
+    ^ 
     #(FullSpec
        name: classesSpec
-       window:
+       window: 
       (WindowSpec
-	 label: 'Classes'
-	 name: 'Classes'
-	 min: (Point 10 10)
-	 bounds: (Rectangle 0 0 300 300)
+         label: 'Classes'
+         name: 'Classes'
+         min: (Point 10 10)
+         bounds: (Rectangle 0 0 300 300)
        )
-       component:
+       component: 
       (SpecCollection
-	 collection: (
-	  (LabelSpec
-	     label: 'Hint: drag''n''drop classes, methods or packages from browser'
-	     name: 'HintLabel'
-	     layout: (LayoutFrame 0 0 0 0 0 1 30 0)
-	     translateLabel: true
-	     adjust: left
-	   )
-	  (SelectionInListModelViewSpec
-	     name: 'ClassesList'
-	     layout: (LayoutFrame 0 0 30 0 0 1 -60 1)
-	     model: selectedClassesHolder
-	     hasHorizontalScrollBar: true
-	     hasVerticalScrollBar: true
-	     listModel: classes
-	     multipleSelectOk: true
-	     useIndex: false
-	     highlightMode: line
-	     properties:
-	    (PropertyListDictionary
-	       canDropSelector: canDropClasses:
-	       dropArgument: nil
-	       dropSelector: doDropClasses:
-	       dragArgument: nil
-	     )
-	   )
-	  (LabelSpec
-	     name: 'ClassInfoLabel'
-	     layout: (LayoutFrame 0 0 -60 1 0 1 -30 1)
-	     translateLabel: true
-	     labelChannel: classesInfoTextHolder
-	     adjust: left
-	   )
-	  (HorizontalPanelViewSpec
-	     name: 'HorizontalPanel1'
-	     layout: (LayoutFrame 0 0 -30 1 -16 1 0 1)
-	     horizontalLayout: center
-	     verticalLayout: center
-	     horizontalSpace: 3
-	     verticalSpace: 3
-	     component:
-	    (SpecCollection
-	       collection: (
-		(ActionButtonSpec
-		   label: 'Remove Selected Classes'
-		   name: 'RemoveClassesButton'
-		   translateLabel: true
-		   model: removeSeletedClassesAction
-		   useDefaultExtent: true
-		 )
-		)
-
-	     )
-	     keepSpaceForOSXResizeHandleH: true
-	   )
-	  )
-
+         collection: (
+          (LabelSpec
+             label: 'Hint: drag''n''drop classes, methods or packages from browser'
+             name: 'HintLabel'
+             layout: (LayoutFrame 0 0 0 0 0 1 30 0)
+             translateLabel: true
+             adjust: left
+           )
+          (SelectionInListModelViewSpec
+             name: 'ClassesList'
+             layout: (LayoutFrame 0 0 30 0 0 1 -60 1)
+             model: selectedClassesHolder
+             hasHorizontalScrollBar: true
+             hasVerticalScrollBar: true
+             listModel: classes
+             multipleSelectOk: true
+             useIndex: false
+             highlightMode: line
+             properties: 
+            (PropertyListDictionary
+               canDropSelector: canDropClasses:
+               dropArgument: nil
+               dropSelector: doDropClasses:
+               dragArgument: nil
+             )
+           )
+          (LabelSpec
+             name: 'ClassInfoLabel'
+             layout: (LayoutFrame 0 0 -60 1 0 1 -34 1)
+             translateLabel: true
+             labelChannel: classesInfoTextHolder
+             adjust: left
+           )
+          (HorizontalPanelViewSpec
+             name: 'HorizontalPanel1'
+             layout: (LayoutFrame 0 0 -34 1 0 1 0 1)
+             horizontalLayout: center
+             verticalLayout: center
+             horizontalSpace: 3
+             verticalSpace: 3
+             component: 
+            (SpecCollection
+               collection: (
+                (ActionButtonSpec
+                   label: 'Add All Your Packages'
+                   name: 'AddAllYourPackagesButton'
+                   translateLabel: true
+                   model: addAllYourPackagesAction
+                   useDefaultExtent: true
+                 )
+                (ActionButtonSpec
+                   label: 'Add All Packages'
+                   name: 'AddAllPackagesButton'
+                   translateLabel: true
+                   model: addAllPackagesAction
+                   useDefaultExtent: true
+                 )
+                (ActionButtonSpec
+                   label: 'Remove Selected Classes'
+                   name: 'RemoveSelectedClassesButton'
+                   translateLabel: true
+                   model: removeSeletedClassesAction
+                   useDefaultExtent: true
+                 )
+                )
+              
+             )
+             keepSpaceForOSXResizeHandleH: true
+           )
+          )
+        
        )
      )
 !
@@ -889,9 +903,25 @@
     "Created: / 20-07-2007 / 16:31:18 / janfrog"
 !
 
-classes: aCollection
-    self classes contents:((aCollection collect:[:cls|cls theNonMetaclass])
-			    sortBySelector:#name).
+classes:aCollectionOfClasses
+    |answer classesToAdd unloadedClasses|
+
+    classesToAdd := aCollectionOfClasses.
+    
+    unloadedClasses := classesToAdd reject:[:cls | cls isLoaded].
+    unloadedClasses notEmpty ifTrue:[
+        answer := Dialog confirmWithCancel:(resources stringWithCRs:'Some classes are unloaded.\\Load them now?').
+        answer isNil ifTrue:[ AbortSignal raise. ].
+        answer == true ifTrue:[
+            unloadedClasses do:[:each | each autoload].
+        ] ifFalse:[
+            classesToAdd := classesToAdd select:[:cls | cls isLoaded].
+        ].    
+    ].
+    classesToAdd := (classesToAdd collect:[:cls|cls theNonMetaclass])
+                        asOrderedCollection sortBySelector:#name.
+    
+    self classes contents:classesToAdd.
     self classesChanged
 
 
@@ -1033,6 +1063,24 @@
 
 !MethodRewriter methodsFor:'actions'!
 
+addAllPackagesAction
+    |classes|
+
+    classes := Smalltalk allClasses.
+    self classes: classes
+!
+
+addAllYourPackagesAction
+    |classes|
+
+    classes := Smalltalk 
+                    allClassesForWhich:[:cls | 
+                        cls isNameSpace not
+                        and:[ ((cls package ?'') startsWith:'stx:') not]
+                    ].
+    self classes: classes
+!
+
 doRewrite: methodsMatching
     | changes compositeChangeCollector |
 
@@ -1136,11 +1184,15 @@
 !
 
 removeSeletedClassesAction
+    |toRemove|
 
-    self classes removeAll: self selectedClasses.
-    classes changed:#content.
-    self classesChanged.
-
+    toRemove := self selectedClasses.
+    toRemove notEmptyOrNil ifTrue:[
+        self classes removeAll: self selectedClasses.
+        classes changed:#content.
+        self classesChanged.
+    ].
+    
     "Created: / 12-12-2007 / 12:05:15 / janfrog"
 !
 
@@ -1345,9 +1397,11 @@
     methods := nil.
 
     self classesInfoTextHolder
-	value:(((classes size == 1) ifTrue:['%1 class / %2 method(s)'] ifFalse:['%1 classes / %2 methods'])
-		    bindWith:classes size
-		    with:self methods size)
+        value:(((classes size == 1) 
+                    ifTrue:['%1 class / %2 method(s)'] 
+                    ifFalse:['%1 classes / %2 methods'])
+                        bindWith:classes size
+                        with:self methods size)
 !
 
 selectedRuleIndexChanged
@@ -1506,40 +1560,43 @@
     | matchingMethods searcher currentMethod|
 
     rule isNil ifTrue:[
-	Dialog warn:'No rule selected.'.
-	AbortSignal raise
+        Dialog warn:'No rule selected.'.
+        AbortSignal raise
     ].
 
     searcher := ParseTreeSearcher new.
     rule rewriteRule searches do:[:eachSearch |
-	searcher
-	    matchesTree:eachSearch searchTree
-	    do:[:aNode :answer |
-		(eachSearch canMatch: aNode) ifTrue:[
-		    matchingMethods add:currentMethod
-		]
-	    ]
+        searcher
+            matchesTree:eachSearch searchTree
+            do:[:aNode :answer |
+                (eachSearch canMatch: aNode) ifTrue:[
+                    matchingMethods add:currentMethod
+                ]
+            ]
     ].
+    searcher computeQuickSearchStrings.
 
     matchingMethods := Set new.
     self
-	withMethodsDo:[:mthd|
-	    | tree |
+        withMethodsDo:[:mthd|
+            | tree |
 
-	    tree := mthd parseTree.
-	    tree
-		ifNil:[
-		    Transcript showCR:'MethodRewriter: parse tree error in ',mthd whoString.
-		    self breakPoint: #jv
-		]
-		ifNotNil:[
-		    currentMethod := mthd.
-		    searcher executeTree: tree
-		]
-	]
-	finallyDo:[
-	    block value: matchingMethods
-	]
+            (searcher canQuicklyReject:mthd source) ifFalse:[
+                tree := mthd parseTree.
+                tree
+                    ifNil:[
+                        Transcript showCR:'MethodRewriter: parse tree error in ',mthd whoString.
+                        self breakPoint: #jv
+                    ]
+                    ifNotNil:[
+                        currentMethod := mthd.
+                        searcher executeTree: tree
+                    ]
+            ]
+        ]
+        finallyDo:[
+            block value: matchingMethods
+        ]
 
     "Created: / 12-12-2007 / 10:34:50 / janfrog"
     "Modified: / 07-04-2011 / 22:02:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -1646,27 +1703,34 @@
 withMethods: methods do: methodBlock finallyDo: finallyBlock
 
     [
-	|numMethods|
+        |numMethods|
+
+        numMethods := methods size.
 
-	numMethods := methods size.
+        self actionInProgress: true.
+        self progress: 0.
 
-	self actionInProgress: true.
-	self progress: 0.
+        methods asArray keysAndValuesDo:[:idx :mth|
+            |mclass|
 
-	methods asArray keysAndValuesDo:[:idx :mth|
-	    numMethods > 100 ifTrue:[
-		self info: mth mclass name.
-	    ] ifFalse:[
-		self info: mth selector storeString.
-	    ].
-	    methodBlock value: mth.
-	    self progress: ((100 / methods size) * idx) rounded
-	].
-	finallyBlock value
+            mclass := mth mclass.
+            mclass isNil ifTrue:[
+                Transcript showCR:'method no longer valid in ',mth getMclass printString.
+            ] ifFalse:[    
+                numMethods > 100 ifTrue:[
+                    self info: mclass name.
+                ] ifFalse:[
+                    self info: mth selector storeString.
+                ].
+                methodBlock value: mth.
+                self progress: ((100 / methods size) * idx) rounded
+            ].
+        ].
+        finallyBlock value
     ] ensure:[
-	"/self actionInProgress: false.
-	self progress: 0.
-	self info: ''
+        "/self actionInProgress: false.
+        self progress: 0.
+        self info: ''
     ]
 
     "Created: / 12-12-2007 / 10:32:16 / janfrog"