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

馋奶兔 提交于 2019-12-06 02:20:24

问题


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:

  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.



来源:https://stackoverflow.com/questions/6254930/intellij-structural-search-to-find-classes-that-implement-a-but-not-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!