For a while, we had some problems in setting Cmd+i keybindings for triggering the inspection in GTInspector. As a result we used in several places Cmd+t. However, after the problem got fixed, we wanted all inspect keybindings to be uniformly set to Cmd+i, and Cmd+t was supposed to be used for other purposes like spawning the pointers to for an object.
Thus, I wanted to find all occurrences where Cmd+t was used and ensure that it was used for the right thing. The only way to do it effectively is to write a query over the abstract syntax tree.
To figure the query out, I first found a method where the shortcut was defined, and given that the GTInspector offers a simple interface to browse the AST, I could simply inspect the method to identify what the query should look for:
Essentially, I needed to look for all occurrences of RBLiveralValueNode
that had as value $t
. Armed with this knowledge, the query was straightforward:
(RPackageOrganizer default packageNamed: 'GT-Inspector’) methodReferences select: [ :each | each method parseTree allChildren anySatisfy: [ :node | node value = $t ] ]
Simply inspecting the result offered the right tool for the job.
The whole process took a couple of minutes. Querying source code is actually not hard at all, if you have a structured approach to it and appropriate tool support.