Structural Search Help: Method Invocation inside Method Implementation?

Answered

Hey,

I'm trying to find a case in a codebase where the implementation of an interface method invokes another method.

So I have an interface, "WizardSectionSwitchHandler" with a method "onWizardSectionSwitch( Integer section )".  I want to find an implementation of that that invokes another method, "setEnabled" on an object that implements "HasEnabled", although that method will likely include other code.  Is that something I can search for using Structural Search?

It's easy for me to find calls of "setEnabled" and methods that implement the interface method "onWizardSectionSwitch", but combining the two is hard, and I still struggle to make Structural Search do what I want.  I often feel like Structural Search could help me find things, and yet when I try, I usually fail. ;)

2 comments
Comment actions Permalink

The interfaces may not even be important -- I'm ok with starting with a structural search that finds a method declaration named "onWizardSectionSwitch" that includes an invocation to a method "setEnabled" without the interfaces necessarily being involved for now.

Although, come to think of it, it might also be that the `onWizardSectionSwitch` method invokes a method that invokes `setEnabled`, I'd ideally be able to find that as well. :/

0
Comment actions Permalink

What you can do is first Find Usages on the `onWizardSectionSwitch()` method in `WizardSectionSwitchHandler`. Change the settings so only the `Implementing methods` are found. After you have the search results, you can invoke `Edit | Find | Search Structurally` and perform a search in the scope named `Previous Search Results`. Then use a query like: 

 

$qualifier$.setEnabled($argument$)

With a count modifier `[0,∞]` on $argument$ and a type modifier `type=HasEnabled` with `Within type hierarchy` enabled. By searching in the scope named `Previous Search Results` you will find only calls inside the methods previously found by Find Usages.

 

Hope this helps,

Bas

0

Please sign in to leave a comment.