开发者

IntelliJ Structural Search to find classes that implement A but not B

开发者 https://www.devze.com 2023-03-10 14:03 出处:网络
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.

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 开发者_StackOverflow社区for.

Inicidentaly, someone else asked a similar question on the IntelliJ forums, but got no love. Help me out, stackoverflow!


To find classes that implement InterfaceA, but don't implement InterfaceB, I did the following:

  1. Search > Search Structurally
  2. Click Copy existing template
  3. Select implementors of an interface (within hierarcy) and click OK
  4. Click Edit Variables
  5. Select Interface in the Variables list
  6. Enter InterfaceA in Text / regular expression and click OK
  7. Click Find
  8. Search > Search Structurally
  9. Click Edit Variables
  10. Select Interface in the Variables list
  11. Enter InterfaceB in Text / regular expression, 0 in Minimum Count and 0 in Maximum Count and click OK
  12. Select Previous Search Results in the Scope dropdown
  13. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消