How to find all usages of name() related to specific enum type

260 Views Asked by At

I need to find all usages of name() method called on specific enum type.

Let's say I've got the enum:

enum MyEnum {
    A, B, C;
}

I want to receive all places where the method is called on any of MyEnum element. It could be called on specific elements like A.name(), B.name() and so on, but as well it could be called on a parameter or a iterating variable, for example:

String myMethod(MyEnum myEnum) {
    return myEnum.name();
}

So far I could do it by pressing Alt + F7 on each element of MyEnum and the enum type itself and then look for occurences containing name() call in results. But this require a lot of manual work.

The other approach I've tried was to press Alt + F7 having cursor over method's name in statement like A.name() but it found all occurences of name() called on any enum type.

So is it possible to do this easier and faster?

1

There are 1 best solutions below

0
On BEST ANSWER

In structural search (Edit > Find > Search structurally...), search for:

$e$.name()

then hit "Edit Variables...", select e, and set the "Expression type (regexp)" to be the enum you are interested in.

(Remember that any reference of type Enum<?> could contain a reference to a MyEnum, so you may need to consider looking for those also)