1

Using structural search in Intellij IDEA, how should the search template be if i want to find all the classes that implement an interface but do not extend another class? The templates separately are:

class $Class$ implements $Interface$ {}

and

class $Class$ extends $Parent$ {}

setting minimum and maximum 1,1 and 0,0 respectively.

I tried something similar to this question without success:

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

gibarsin
  • 151
  • 4
  • 13

1 Answers1

3

You can combine the two templates:

class $Class$ extends $Parent$ implements $Interface$ {}

With the following variable settings

$Parent$:
Text/regexp Excluded and enable Apply constrains in type hierarchy, min/max 0,0
$Interface$:
Text/regexp Included and enable Apply constrains in type hierarchy, min/max 1,1

When I search with these settings on the following test code, classes B and E are found.

class Excluded {}
interface Included {}
class A extends Excluded implements Included {}
class B implements Included {}
class C extends Excluded {}
class D extends A {}
class E extends B {}
class F {}

You of course need to use your own class and interface name instead of Included and Excluded.

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
  • This doesn't work, even when assigning the min and max count to 1,1 and 0,0 respectively in your snippet. – gibarsin Aug 19 '17 at 19:30
  • I have added some more explanation. If this does not work for you, which version of IntelliJ IDEA are you using? Maybe you're running into a bug. – Bas Leijdekkers Aug 20 '17 at 10:23