SystemOrganization addCategory: #'OB-Regex-Commands'! SystemOrganization addCategory: #'OB-Regex-Tools'! ORCmdRefactoring subclass: #ORCmdRegexRefactoring instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Commands'! ORCmdRegexRefactoring subclass: #ORCmdClassRegexRefactoring instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Commands'! !ORCmdClassRegexRefactoring methodsFor: 'accessing' stamp: 'lr 2/7/2008 13:50'! label ^ 'class name...'! ! !ORCmdClassRegexRefactoring methodsFor: 'accessing' stamp: 'lr 2/3/2008 22:11'! refactoringClass ^ ORClassRegexRefactoring! ! !ORCmdRegexRefactoring methodsFor: 'accessing' stamp: 'lr 2/7/2008 13:46'! cluster ^ #'search and replace'! ! !ORCmdRegexRefactoring methodsFor: 'accessing' stamp: 'lr 2/4/2008 09:31'! refactoring | find replace | find := self request: 'Search for:'. replace := self request: 'Replace with:'. ^ self refactoringClass find: find replace: replace! ! !ORCmdRegexRefactoring methodsFor: 'accessing' stamp: 'lr 2/3/2008 21:49'! refactoringClass self subclassResponsibility! ! ORCmdRegexRefactoring subclass: #ORCmdSourceRegexRefactoring instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Commands'! !ORCmdSourceRegexRefactoring methodsFor: 'accessing' stamp: 'lr 2/7/2008 13:50'! label ^ 'method source...'! ! !ORCmdSourceRegexRefactoring methodsFor: 'accessing' stamp: 'lr 2/3/2008 21:50'! refactoringClass ^ ORSourceRegexRefactoring! ! ORCommand subclass: #ORCmdRegexEnvironment instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Commands'! ORCmdRegexEnvironment subclass: #ORCmdCategoryRegexEnvironment instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Commands'! !ORCmdCategoryRegexEnvironment methodsFor: 'accessing' stamp: 'lr 2/7/2008 13:48'! label ^ 'find categories...'! ! !ORCmdCategoryRegexEnvironment methodsFor: 'execution' stamp: 'lr 1/28/2008 23:28'! search: aMatcher | categories parent | categories := Set new. parent := self environment. parent categories do: [ :category | (aMatcher matches: category) ifTrue: [ categories add: category ] ]. ^ CategoryEnvironment onEnvironment: parent categories: categories! ! ORCmdRegexEnvironment subclass: #ORCmdClassRegexEnvironment instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Commands'! !ORCmdClassRegexEnvironment methodsFor: 'accessing' stamp: 'lr 2/7/2008 13:47'! label ^ 'find classes...'! ! !ORCmdClassRegexEnvironment methodsFor: 'execution' stamp: 'lr 1/28/2008 23:13'! search: aMatcher | parent environment | parent := self environment. environment := ClassEnvironment onEnvironment: parent. parent classesDo: [ :class | aMatcher matchesIn: class name do: [ :each | environment addClass: class; addSearchString: each ] ]. ^ environment! ! ORCmdRegexEnvironment subclass: #ORCmdProtocolRegexEnvironment instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Commands'! !ORCmdProtocolRegexEnvironment methodsFor: 'accessing' stamp: 'lr 2/7/2008 13:48'! label ^ 'find protocols...'! ! !ORCmdProtocolRegexEnvironment methodsFor: 'execution' stamp: 'lr 1/28/2008 23:14'! search: aMatcher | parent environment | parent := self environment. environment := SelectorEnvironment onEnvironment: parent. parent classesDo: [ :class | (parent protocolsFor: class) do: [ :protocol | (aMatcher matches: protocol) ifTrue: [ (parent selectorsFor: protocol in: class) do: [ :selector | environment addClass: class selector: selector ] ] ] ]. ^ environment! ! !ORCmdRegexEnvironment methodsFor: 'accessing' stamp: 'lr 1/28/2008 22:47'! cluster ^ #'open environment'! ! !ORCmdRegexEnvironment methodsFor: 'execution' stamp: 'lr 2/9/2008 15:10'! execute | expression matcher | expression := [ self request: 'Search for:' ] on: ORUICancellationError do: [ :err | ^ self ]. matcher := [ expression asRegex ] on: RegexError do: [ :err | ^ self inform: err messageText ]. (self search: matcher) openBrowser! ! !ORCmdRegexEnvironment methodsFor: 'accessing' stamp: 'lr 1/28/2008 22:25'! group ^ #regex! ! !ORCmdRegexEnvironment methodsFor: 'execution' stamp: 'lr 1/28/2008 22:52'! search: aMatcher self subclassResponsibility! ! ORCmdRegexEnvironment subclass: #ORCmdSelectorRegexEnvironment instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Commands'! !ORCmdSelectorRegexEnvironment methodsFor: 'accessing' stamp: 'lr 2/7/2008 13:48'! label ^ 'find selectors...'! ! !ORCmdSelectorRegexEnvironment methodsFor: 'execution' stamp: 'lr 1/28/2008 23:16'! search: aMatcher | parent environment | parent := self environment. environment := SelectorEnvironment onEnvironment: parent. parent classesAndSelectorsDo: [ :class :selector | aMatcher matchesIn: selector do: [ :each | environment addClass: class selector: selector; addSearchString: each ] ]. ^ environment! ! ORCmdRegexEnvironment subclass: #ORCmdSourceRegexEnvironment instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Commands'! !ORCmdSourceRegexEnvironment methodsFor: 'accessing' stamp: 'lr 2/7/2008 13:48'! label ^ 'find source...'! ! !ORCmdSourceRegexEnvironment methodsFor: 'execution' stamp: 'lr 1/28/2008 23:16'! search: aMatcher | parent environment | parent := self environment. environment := SelectorEnvironment onEnvironment: parent. parent classesAndSelectorsDo: [ :class :selector | aMatcher matchesIn: (class sourceCodeAt: selector) do: [ :each | environment addClass: class selector: selector; addSearchString: each ] ]. ^ environment! ! Refactoring subclass: #ORRegexRefactoring instanceVariableNames: 'find replace refactorings' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Tools'! ORRegexRefactoring subclass: #ORClassRegexRefactoring instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Tools'! !ORClassRegexRefactoring methodsFor: 'transforming' stamp: 'lr 2/4/2008 09:37'! transform | replacement refactoring | self model allClassesDo: [ :class | (class isNil or: [ class isMeta ]) ifFalse: [ replacement := self replace: class name asString. replacement = class name asString ifFalse: [ refactoring := RenameClassRefactoring model: self model rename: class to: replacement. refactoring preconditions check ifTrue: [ refactoring transform ] ifFalse: [ self refactoringWarning: 'Unable to rename ' , class name , ' to ' , replacement ] ] ] ]! ! !ORRegexRefactoring class methodsFor: 'instance-creation' stamp: 'lr 2/7/2008 13:51'! find: aFindString replace: aReplaceString "Answer a refactoring that searches for the regular-expression aFindString. Depending on the subclass implementation it replaces matches with aReplaceString, where $0 references the whole match, and $1..$9 the matched groups." ^ self new find: aFindString replace: aReplaceString! ! !ORRegexRefactoring methodsFor: 'initialization' stamp: 'lr 2/3/2008 22:00'! find: aFindString replace: aReplaceString find := aFindString asRegex. replace := aReplaceString readStream! ! !ORRegexRefactoring methodsFor: 'preconditions' stamp: 'lr 2/3/2008 22:02'! preconditions ^ RBCondition empty! ! !ORRegexRefactoring methodsFor: 'private' stamp: 'lr 2/7/2008 13:42'! replace: aString ^ find copy: aString translatingMatchesUsing: [ :match | String streamContents: [ :stream | [ replace atEnd ] whileFalse: [ stream nextPutAll: (replace upTo: $$). replace atEnd ifFalse: [ replace peek isDigit ifFalse: [ stream nextPut: replace next ] ifTrue: [ stream nextPutAll: (find subexpression: replace next asInteger - $0 asInteger + 1) ] ] ]. replace reset ] ]! ! ORRegexRefactoring subclass: #ORSourceRegexRefactoring instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'OB-Regex-Tools'! !ORSourceRegexRefactoring methodsFor: 'private' stamp: 'lr 2/4/2008 09:28'! parseMethod: aString ^ [ RBParser parseMethod: aString ] on: Error do: [ :err | nil ]! ! !ORSourceRegexRefactoring methodsFor: 'private' stamp: 'lr 2/4/2008 09:29'! parseSelector: aString ^ RBParser parseMethodPattern: aString! ! !ORSourceRegexRefactoring methodsFor: 'transforming' stamp: 'lr 2/4/2008 09:39'! transform | original replacement protocols | self model allClassesDo: [ :class | class selectors do: [ :selector | original := class sourceCodeFor: selector. replacement := self replace: original. replacement = original ifFalse: [ (self parseMethod: replacement) isNil ifTrue: [ self refactoringWarning: 'Unable to compile replacement:' , String cr , class name , '>>' , replacement ] ifFalse: [ protocols := class protocolsFor: selector. (self parseSelector: replacement) = selector ifFalse: [ class removeMethod: selector ]. class compile: replacement classified: protocols ] ] ] ]! ! !OBCodeBrowser methodsFor: '*ob-regex-commands' stamp: 'lr 2/3/2008 21:20'! cmdRegexEnvironment ^ ORCmdRegexEnvironment allSubclasses! ! !OBCodeBrowser methodsFor: '*ob-regex-commands' stamp: 'lr 2/3/2008 21:20'! cmdRegexRefactoring ^ ORCmdRegexRefactoring allSubclasses! !