--- a/Tools__MethodRewriter.st Sun May 10 01:16:39 2015 +0200
+++ b/Tools__MethodRewriter.st Mon May 11 15:18:55 2015 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague
Copyright (c) 2009-2010 eXept Software AG
@@ -29,16 +31,17 @@
ApplicationModel subclass:#MethodRewriter
instanceVariableNames:'replaceTextView methods classes packages searchTextView
- actionInProgresHolder infoHolder progressHolder
+ actionInProgressHolder infoHolder progressHolder
templateSearchPatternHolder templateReplacePatternHolder
selectedTemplateIndex templates selectedTabIndex
selectedClassesHolder selectedRuleIndex rules
ruleReplacePatternHolder ruleSearchPatternHolder
ruleSearchAndReplacePatternHolder ruleForRewriteOrNilForAdHoc
- adHocFindAndReplaceVisibleHolder ruleNameHolder'
+ adHocFindAndReplaceVisibleHolder ruleNameHolder
+ isMethodPatternHolder'
classVariableNames:''
poolDictionaries:''
- category:'Interface-MethodRewriter'
+ category:'Interface-Tools'
!
!MethodRewriter class methodsFor:'documentation'!
@@ -169,6 +172,35 @@
"Created: / 12-12-2007 / 11:03:32 / janfrog"
! !
+!MethodRewriter class methodsFor:'help specs'!
+
+flyByHelpSpec
+ "This resource specification was automatically generated
+ by the UIHelpTool of ST/X."
+
+ "Do not manually edit this!! If it is corrupted,
+ the UIHelpTool may not be able to read the specification."
+
+ "
+ UIHelpTool openOnClass:Tools::MethodRewriter
+ "
+
+ <resource: #help>
+
+ ^ super helpSpec addPairsFrom:#(
+
+#isMethodPattern
+'The patterns are applied to the method''s whole source (including selector)\as opposed to the code''s syntax tree nodes.\(read the pattern help on this)'
+
+#doSearchAction
+'Searches for matching methods and opens a browser on those.'
+
+#doReplaceAction
+'Searches for matching methods, generates the new code and presents a list of changes.\This list allows for inspection and individual selection of changes to be applied'
+
+)
+! !
+
!MethodRewriter class methodsFor:'interface specs'!
classesSpec
@@ -419,9 +451,27 @@
component:
(SpecCollection
collection: (
+ (ViewSpec
+ name: 'MethodPatternBox'
+ layout: (LayoutFrame 0 0 0 0 0 1 30 0)
+ component:
+ (SpecCollection
+ collection: (
+ (CheckBoxSpec
+ label: 'Method Pattern'
+ name: 'CheckBox1'
+ layout: (LayoutFrame 0 0 8 0 136 0 30 0)
+ activeHelpKey: isMethodPattern
+ model: isMethodPatternHolder
+ translateLabel: true
+ )
+ )
+
+ )
+ )
(VariableVerticalPanelSpec
name: 'FindAndReplacePanel'
- layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
+ layout: (LayoutFrame 0 0 30 0 0 1 -30 1)
visibilityChannel: adHocFindAndReplaceVisibleHolder
showHandle: true
snapMode: both
@@ -483,7 +533,7 @@
)
(ViewSpec
name: 'ExecuteRuleBox'
- layout: (LayoutFrame 0 0 0 0 0 1 -30 1)
+ layout: (LayoutFrame 0 0 30 0 0 1 -30 1)
visibilityChannel: ruleExecutionVisibleHolder
component:
(SpecCollection
@@ -524,7 +574,7 @@
label: 'Enjoy'
name: 'Label1'
layout: (LayoutFrame 5 0 -25 1 205 0 -5 1)
- visibilityChannel: actionInProgresHolder
+ visibilityChannel: actionInProgressHolder
translateLabel: true
labelChannel: infoHolder
adjust: left
@@ -532,7 +582,7 @@
(ProgressIndicatorSpec
name: 'ProgressIndicator1'
layout: (LayoutFrame 210 0 -25 1 -215 1 -5 1)
- visibilityChannel: actionInProgresHolder
+ visibilityChannel: actionInProgressHolder
model: progressHolder
)
(ActionButtonSpec
@@ -541,13 +591,15 @@
layout: (LayoutFrame -210 1 -26 1 -110 1 -5 1)
translateLabel: true
model: doSearchAction
+ activeHelpKey: doSearchAction
)
(ActionButtonSpec
- label: 'Rewrite'
+ label: 'Rewrite...'
name: 'Button1'
layout: (LayoutFrame -105 1 -25 1 -5 1 -5 1)
translateLabel: true
model: doRewriteAction
+ activeHelpKey: doRewriteAction
)
)
@@ -827,7 +879,7 @@
actionInProgress: aBoolean
- ^self actionInProgresHolder value: aBoolean
+ ^self actionInProgressHolder value: aBoolean
"Created: / 12-12-2007 / 10:06:16 / janfrog"
!
@@ -988,15 +1040,19 @@
methodsMatching isEmptyOrNil ifTrue:[^Dialog warn:'No methods matching'].
self withMethods: methodsMatching do:[:mth|
- | newTree newSource change |
+ | rewriter newTree newSource change |
- newTree := ParseTreeSourceRewriter new
- replace: self searchPattern
- with: self replacePattern;
- executeTree: mth parseTree;
- tree.
+ rewriter := ParseTreeSourceRewriter new.
+ (self isMethodPatternHolder value) ifTrue:[
+ rewriter replace: self searchPattern with: self replacePattern
+ ] ifFalse:[
+ rewriter replaceMethod: self searchPattern with: self replacePattern
+ ].
+ newTree := rewriter
+ executeTree: mth parseTree;
+ tree.
- change := InteractiveAddMethodChange compile: newTree newSource in:mth mclass classified:mth category.
+ change := InteractiveAddMethodChange compile: newTree newSource in:(mth mclass ? mth getMclass) classified:mth category.
"/ collect in order to have only one change in the undo-list (instead of many)
changes add: change.
@@ -1105,11 +1161,11 @@
!MethodRewriter methodsFor:'aspects'!
-actionInProgresHolder
- actionInProgresHolder isNil ifTrue:[
- actionInProgresHolder := true asValue.
+actionInProgressHolder
+ actionInProgressHolder isNil ifTrue:[
+ actionInProgressHolder := false asValue.
].
- ^ actionInProgresHolder.
+ ^ actionInProgressHolder.
"Created: / 12-12-2007 / 10:00:05 / janfrog"
!
@@ -1135,6 +1191,13 @@
"Modified: / 12-12-2007 / 11:40:17 / janfrog"
!
+isMethodPatternHolder
+ isMethodPatternHolder isNil ifTrue:[
+ isMethodPatternHolder := false asValue
+ ].
+ ^ isMethodPatternHolder.
+!
+
progressHolder
progressHolder isNil ifTrue:[
progressHolder := 0 asValue
@@ -1380,7 +1443,7 @@
matchingMethods := Set new.
self
withMethodsDo:[:mthd|
- | tree |
+ | tree searcher |
tree := mthd parseTree.
tree
ifNil:[
@@ -1388,9 +1451,15 @@
self breakPoint: #jv
]
ifNotNil:[
- (ParseTreeSearcher new)
- matches:pattern do:[:aNode :answer | matchingMethods add:mthd ];
- executeTree: tree
+ searcher := ParseTreeSearcher new.
+ (self isMethodPatternHolder value)
+ ifTrue:[
+ searcher matchesMethod:pattern do:[:aNode :answer | matchingMethods add:mthd ]
+ ]
+ ifFalse:[
+ searcher matches:pattern do:[:aNode :answer | matchingMethods add:mthd ]
+ ].
+ searcher executeTree: tree
]
]
finallyDo:[
@@ -1581,10 +1650,10 @@
!MethodRewriter class methodsFor:'documentation'!
version_CVS
- ^ '$Header: /cvs/stx/stx/libtool/Tools__MethodRewriter.st,v 1.23 2015-02-24 18:13:14 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/Tools__MethodRewriter.st,v 1.24 2015-05-11 13:18:55 cg Exp $'
!
version_SVN
- ^ '$Id: Tools__MethodRewriter.st,v 1.23 2015-02-24 18:13:14 cg Exp $'
+ ^ '$Id: Tools__MethodRewriter.st,v 1.24 2015-05-11 13:18:55 cg Exp $'
! !