So if you look at a selected variable in an inspector you know with one click which methods change and use the variable.
The code:
- Code: Select all
browseReferencesToInstanceVariable
"from #stsInstanceVariableReferences"
| failed value aClass varName theMethods |
self isOneValueSelected ifFalse: [^self].
failed := false.
value := self retrieveValue: self selectedVariables first ifFail: [failed := true].
failed ifTrue: [^self closeCorruptBrowser].
aClass := self selectedVariables first reference object class.
varName := self selectedVariables first reference name.
self execShortOperation: [
theMethods := aClass allMethodsReferencingInstVarName: varName.
theMethods isEmpty
ifTrue: [
self owningImage message:
( ( NlsCatEMT residentMsg: 'MxEMT351' ) bindWith: varName storeString)] "$NLS$ No methods reference %1."
ifFalse: [
((self browser: #highlightingMethods)
on: theMethods
labeled:
( ( NlsCatEMT residentMsg: 'MxEMT6' ) bindWith: varName) "$NLS$ References to %1"
highlighting: varName)
owningImage: self owningImage;
open] ]
and for the menu e.g.
- Code: Select all
variablesMenu
"Answer the variables list menu."
| menu |
(menu := super variablesMenu)
add: #browseReferencesToInstanceVariable
label: 'Browse References to Instance Variable'
enable: [self dirty not and: [self selectedVariables size = 1 and: [self selectedVariables first reference class = DbgNamedInstVarReference]]]
after: #browseHierarchy;
yourself.
^menu
I use this in a subclass of StsInspector and I love it!
Jürgen