From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:52:32 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>RegexCodeTool</name> <environment>Refactory.Browser</environment> <super>Refactory.Browser.SmalllintCodeTool</super> <private>false</private> none searchHolder replaceHolder <imports></imports> <category>Browser-Code Tools</category> <attributes> <package>RBRegexExtensions</package> </attributes> </class> <comment> Refactory.Browser.RegexCodeTool
RegexCodeTool is the browser tab that allows to enter a regular expression and an optional substitution pattern, and search for (and optionally replace) occurrences of the regular expression. Instance Variables: searchHolder <ValueHolder on: String> Holds onto the string with the regular expression to search for. replaceHolder <ValueHolder on: String> Holds onto a substitution pattern, if provided. A substitution pattern can be a string, or a string with subexpression placeholders. See the comment to RegexTransformationRule for details.
</comment> <class> <name>RegexTransformationRule</name> <environment>Refactory.Browser</environment> <super>Refactory.Browser.TransformationRule</super> <private>false</private> none regex replacementString <imports></imports> <category>Browser-Lint</category> <attributes> <package>RBRegexExtensions</package> </attributes> </class> <comment> Refactory.Browser.RegexTransformationRule
RegexTransformationRule transforms code by searching for a regular expression in the source and replacing its matches with replacementString (see below). Instance Variables: regex <RxMatcher> The regular expression matcher used in the search. replacementString <String> The substitution pattern. In the simplest form, it is a string that replaces all matches of the regular expression. It can also contain subexpression references. A subexpression reference has the form $N, where N is the number of the subexpression (subexpression numbering is explained in Regex documentation). During substitution, subexpression references are expanded to substrings of the original code that matched parts of the regular expression.
</comment> <methods> Refactory.Browser.RegexCodeTool <category>private</category>
doesRegex: aRegex match: aString aRegex matchesIn: aString do: [:each | ^true]. ^false
</methods> <methods> Refactory.Browser.RegexCodeTool <category>aspects</category>
replaceHolder "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^replaceHolder isNil ifTrue: [replaceHolder := String new asValue] ifFalse: [replaceHolder]
searchHolder "This method was generated by UIDefiner. Any edits made here may be lost whenever methods are automatically defined. The initialization provided below may have been preempted by an initialize method." ^searchHolder isNil ifTrue: [searchHolder := String new asValue] ifFalse: [searchHolder]
</methods> <methods> Refactory.Browser.RegexCodeTool <category>updating</category>
updateRunning super updateRunning. checkerProcess notNil ifTrue: [self disable: #replace] ifFalse: [self enable: #replace]
</methods> <methods> Refactory.Browser.RegexCodeTool <category>actions</category>
find | regex rule | regex := self searchHolder value asRegex. rule := BlockLintRule new. rule name: (#MatchesRegularExpression << #browser >> 'Matches regular expression') asString. rule methodBlock: [:context :result | (self doesRegex: regex match: context methodSource) ifTrue: [result addClass: context selectedClass selector: context selector]]. self runRule: rule
replace self runRule: (RegexTransformationRule named: (#RegularExpressionTransformations << #browser >> 'Regular Expression Transformations') asString searchFor: self searchHolder value replaceWith: self replaceHolder value)
</methods> <methods> Refactory.Browser.RegexCodeTool <category>tab APIs</category>
tabName ^(#RegularExpression << #browser >> 'Regular Expression') asString
</methods> <methods> Refactory.Browser.RegexCodeTool class <category>private-interface building</category>
markedAsSystemClass "This class not to be shown when browsing user classes."
</methods> <methods> Refactory.Browser.RegexTransformationRule <category>accessing</category>
checkMethod: aSmalllintContext | source changed | changed := false. source := regex copy: aSmalllintContext methodSource translatingMatchesUsing: [:each | changed := true. self replacementStringForMatch]. changed ifTrue: [changes compile: source in: aSmalllintContext selectedClass classified: aSmalllintContext protocol]
</methods> <methods> Refactory.Browser.RegexTransformationRule <category>private</category>
replacementStringForMatch | readStream char writeStream | writeStream := WriteStream on: (String new: 20). readStream := ReadStream on: replacementString. [readStream atEnd] whileFalse: [char := readStream next. char == $$ ifTrue: [writeStream nextPutAll: (self stringForMatch: readStream)] ifFalse: [writeStream nextPut: char]]. ^writeStream contents
stringForMatch: readStream | submatch | readStream atEnd ifTrue: [^'$']. (readStream peekFor: $_) ifTrue: [^regex subexpression: 1]. submatch := self submatchIn: readStream. ^submatch isNil ifTrue: ['$'] ifFalse: [submatch]
submatchIn: readStream | submatches count char | submatches := regex subexpressionCount - 1. count := 0. [readStream atEnd] whileFalse: [char := readStream peek. (char between: $0 and: $9) ifFalse: [^regex subexpression: count + 1]. count := count * 10 + (char asInteger - $0 asInteger). count > submatches ifTrue: [count := count // 10. ^regex subexpression: count + 1]. readStream next]. ^regex subexpression: count + 1
</methods> <methods> Refactory.Browser.RegexTransformationRule <category>initialize-release</category>
searchFor: aString replaceWith: replaceString regex := aString asRegex. replacementString := replaceString
</methods> <methods> Refactory.Browser.RegexTransformationRule class <category>instance creation</category>
named: aString searchFor: searchString replaceWith: replaceString ^(self new) name: aString; searchFor: searchString replaceWith: replaceString; yourself
</methods> <methods> Refactory.Browser.RegexCodeTool class <category>resources</category>
mainMenu "MenuEditor new openOnClass: self andSelector: #mainMenu" <resource: #menu> ^#(#{UI.Menu} #( #(#{UI.MenuItem} #rawLabel: #(#{Kernel.UserMessage} #key: #SearchDots #defaultString: 'Search...' #catalogID: #browser) #nameKey: #'Rewriter Search' #value: #action: ) #(#{UI.MenuItem} #rawLabel: #(#{Kernel.UserMessage} #key: #ReplaceDots #defaultString: 'Replace...' #catalogID: #browser) #nameKey: #'Rewriter Replace' #value: #action: ) ) #(2 ) nil ) decodeAsLiteralArray
</methods> <methods> Refactory.Browser.RegexCodeTool class <category>interface specs</category>
windowSpec "UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#{UI.FullSpec} #window: #(#{UI.WindowSpec} #label: #(#{Kernel.UserMessage} #key: #UnlabeledCanvas #defaultString: 'Unlabeled Canvas' #catalogID: #browser) #bounds: #(#{Graphics.Rectangle} 512 384 940 681 ) ) #component: #(#{UI.SpecCollection} #collection: #( #(#{UI.LabelSpec} #layout: #(#{Core.Point} 2 2 ) #name: #Label7 #label: #(#{Kernel.UserMessage} #key: #SearchForC #defaultString: 'Search for:' #catalogID: #browser) ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.LayoutFrame} 100 0 2 0 -2 1 27 0 ) #name: #search #model: #searchHolder ) #(#{UI.LabelSpec} #layout: #(#{Core.Point} 2 30 ) #name: #Label6 #label: #(#{Kernel.UserMessage} #key: #ReplaceWithC #defaultString: 'Replace with:' #catalogID: #browser) ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.LayoutFrame} 100 0 30 0 -2 1 55 0 ) #name: #replace #model: #replaceHolder ) #(#{UI.DividerSpec} #layout: #(#{Graphics.LayoutFrame} 0 0 90 0 0 1 92 0 ) #name: #Divider1 ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.LayoutFrame} -40 0.25 96 0 40 0.25 120 0 ) #name: #run #model: #find #label: #(#{Kernel.UserMessage} #key: #SearchDots #defaultString: 'Search...' #catalogID: #browser) ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.LayoutFrame} -40 0.5 96 0 40 0.5 120 0 ) #name: #replace #model: #replace #label: #(#{Kernel.UserMessage} #key: #ReplaceDots #defaultString: 'Replace...' #catalogID: #browser) ) #(#{UI.ActionButtonSpec} #layout: #(#{Graphics.LayoutFrame} -40 0.75 96 0 40 0.75 120 0 ) #name: #abort #flags: 40 #model: #abort #label: #(#{Kernel.UserMessage} #key: #Abort #defaultString: 'Abort' #catalogID: #browser) ) #(#{UI.InputFieldSpec} #layout: #(#{Graphics.LayoutFrame} 2 0 58 0 -127 1 83 0 ) #name: #action #flags: 0 #model: #actionHolder ) #(#{UI.ProgressWidgetSpec} #layout: #(#{Graphics.LayoutFrame} -125 1 58 0 -2 1 83 0 ) #name: #percentDone #isOpaque: true #colors: #(#{UI.LookPreferences} #setForegroundColor: #(#{Graphics.ColorValue} #blue ) #setBackgroundColor: #(#{Graphics.ColorValue} #white ) ) #model: #percentDoneHolder #direction: #horizontal #position: #topLeft #area: true #reverse: false ) ) ) )
</methods> <methods> Refactory.Browser.CodeModel class <category>tool registration</category>
regexToolClass <tool> ^RegexCodeTool
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>SmalllintCodeTool</name> <environment>Refactory.Browser</environment> <super>Refactory.Browser.CodeTool</super> <private>false</private> none lintRuleList transformationList percentDoneHolder actionHolder checkerProcess isTransformationRule <imports></imports> <category>Browser-Code Tools</category> <attributes> <package>Browser-SmalllintUI</package> </attributes> </class> <class> <name>TransformationRule</name> <environment>Refactory.Browser</environment> <super>Refactory.Browser.LintRule</super> <private>false</private> none changes <imports></imports> <category>Browser-Lint</category> <attributes> <package>Browser-Smalllint</package> </attributes> </class>