How to search a string inside a class in Squeak smalltalk? How about inside the package?

I searched and searched.

I went to IRC

Hope the question is not stupid. If that were the case, then the correct google search string would be appreciated

+6
source share
2 answers

The answer to such questions with the refactoring mechanism is quite simple. The following code finds all occurrences / in the system:

 allCodeWithSlash := RBBrowserEnvironment new matches: '/' 

From there you can expand your search, for example. inside class:

 allCodeWithSlashInClass := allCodeWithSlash forClasses: (Array with: DosFileDirectory) 

Or inside the package:

 allCodeWithSlashInPackage := allCodeWithSlash forPackageNames: (Array with: 'Files') 

If you have a user interface loaded, you can open a browser in any of these search results:

 allCodeWithSlashInPackage open 

If you use OmniBrowser, you can also create and navigate these areas without entering any code through the Refactoring area menu.

+2
source

Here is an example that shows you all the methods in DosFileDirectory containing the string '\'.

 aString := '\\'. class := DosFileDirectory. methodsContainingString := class methodDictionary values select: [:method | method hasLiteralSuchThat: [:lit | (lit isString and: [lit isSymbol not]) and: [lit = aString]]]. messageList := methodsContainingString collect: [ :e | MethodReference new setStandardClass: class methodSymbol: e selector ]. SystemNavigation new browseMessageList: messageList name: 'methods containing string'. 

To search the entire package, wrap the search part in:

 package := PackageOrganizer default packageNamed: packageName ifAbsent: [ self error: 'package doesn't exist' ]. package classesAndMetaClasses do: [ :class | ... ] 
+1
source

Source: https://habr.com/ru/post/904441/


All Articles