问题
I'm trying to use IntelliJ 10.5's "structural search" feature to find classes that implement an interface, A but do not implement another interface, B.
By searching first for classes that implement A, and then limiting the search scope to 'previous search results,' it's easy to reduce this to just searching for classes that do not implement B, which is conceptually pretty simple. Unfortunately, I haven't yet managed to pull it off.
If I search for
class $clazz$ implements $B$ {}
and then tick 'invert condition' in the text constraints for variable B, it seems to find 'all classes that implement something other than B' even if they also implement B. I've also tried ticking 'invert condition' on the 'complete match' variable, and its effect is not immediately obvious, but definitely not what I'm looking for.
Inicidentaly, someone else asked a similar question on the IntelliJ forums, but got no love. Help me out, stackoverflow!
回答1:
To find classes that implement InterfaceA, but don't implement InterfaceB, I did the following:
- Search > Search Structurally
- Click Copy existing template
- Select implementors of an interface (within hierarcy) and click OK
- Click Edit Variables
- Select Interface in the Variables list
- Enter InterfaceA in Text / regular expression and click OK
- Click Find
- Search > Search Structurally
- Click Edit Variables
- Select Interface in the Variables list
- Enter InterfaceB in Text / regular expression, 0 in Minimum Count and 0 in Maximum Count and click OK
- Select Previous Search Results in the Scope dropdown
- Click Find
Note I had problems when I tried to use the Edit Query button at step 8. I didn't research/retry, but going back to the menu and selecting Search > Search Structurally definitely worked.
来源:https://stackoverflow.com/questions/6254930/intellij-structural-search-to-find-classes-that-implement-a-but-not-b