Marcel Taeumel uploaded a new version of ToolBuilder-Kernel to project The Trunk:
http://source.squeak.org/trunk/ToolBuilder-Kernel-mt.126.mcz ==================== Summary ==================== Name: ToolBuilder-Kernel-mt.126 Author: mt Time: 15 July 2019, 6:00:39.98495 pm UUID: d492e86b-b9f0-3b46-84c4-1a0d18da0d4d Ancestors: ToolBuilder-Kernel-mt.125 Minor improvement of the latest class-search changes. Thanks to Kjell Godo. =============== Diff against ToolBuilder-Kernel-mt.125 =============== Item was changed: ----- Method: UIManager>>classOrTraitFrom:pattern:label: (in category 'system introspecting') ----- classOrTraitFrom: environment pattern: pattern label: label "Given a pattern and an environment, try to find a class or trait using several strategies: - EXACT: If there is a class or trait whose name exactly given by pattern, return it. - UPPER: If the pattern is upper-case only, find camel-case letters with that sequence. - WILD: Try the pattern as-is for regular wild-card search. - FEATURE: Split patterns at feature boundaries and insert wild cards between. - FUZZY: Split patterns at feature boundaries BUT treat each feature as a full class name. If there is only one class or trait in the given environment whose name matches pattern, return it. Otherwise, put up a menu offering the names of all classes that match pattern, and return the class chosen, else nil if nothing chosen. !!!! In any case, separator characters in the pattern are ignored." | toMatch potentialNames names selectedIndex | "If there's a class or trait named as pattern, then return it." (environment classOrTraitNamed: pattern) ifNotNil: [:classOrTrait | ^ classOrTrait]. "Validate pattern." toMatch := pattern copyWithoutAll: Character separators. toMatch := toMatch asLowercase copyWithout: $.. toMatch ifEmpty: [ ^nil ]. "Fetch search space." names := OrderedCollection new. potentialNames := environment classAndTraitNames asOrderedCollection. "Try uppercase-only patterns for patterns such as 'WKD' to find 'WeakIdentityKeyDictionary' etc." names ifEmpty: [ (pattern allSatisfy: [:char | char isUppercase]) ifTrue: [ + | patternStream | + patternStream := pattern readStream. potentialNames do: [:each | + patternStream reset. - | patternStream | - patternStream := pattern readStream. each detect: [:char | (patternStream atEnd not and: [patternStream peek = char]) ifTrue: [ patternStream next. patternStream atEnd ifTrue: [names add: each. true "Match!!"] ifFalse: [false "Not yet..."]] ifFalse: [false "No match..."] ] ifNone: [] ] ]]. "Try wildcard search for patterns such as 'Weak*Dict*' to find 'WeakIdentityKeyDictionary' etc." names ifEmpty: [ names := potentialNames select: [ :each | toMatch match: each ]]. "Try feature-based search for patterns such as 'WeakDict' to find 'WeakIdentityKeyDictionary' etc." names ifEmpty: [ toMatch := pattern copyWithoutAll: '.*#'. toMatch findFeatures in: [:features | "1) Insert wildcards between features and at the end." toMatch := (features joinSeparatedBy: '*'), '*'. names := potentialNames select: [ :each | toMatch match: each ]. names ifEmpty: [ "2) Insert wildcards before, between, and after features." toMatch := '*', (features joinSeparatedBy: '*'), '*'. names := potentialNames select: [ :each | toMatch match: each ] ]] ]. "Try some fuzzy matching." names addAll: (pattern suggestedTypeNames select: [ :each | potentialNames includes: each ]). "Still no match?" names ifEmpty: [ ^ nil ]. "Let the user select if there's more than one possible match. This may give surprising results." selectedIndex := names size = 1 ifTrue: [ 1 ] ifFalse: [ self chooseFrom: names title: label ]. selectedIndex = 0 ifTrue: [ ^nil ]. ^environment at: (names at: selectedIndex) asSymbol! |
Free forum by Nabble | Edit this page |