Artem Krosheninnikov
Artem Krosheninnikov

Reputation: 156

IntelliJ Structural Search to find all classes without given declarations

Consider we have a class

public class MyTest() {
    @Inject private Class1 class1;
    @Inject private Class2 class2;

}

and a class

public class MyTest2() {
    @Inject private Class1 class1;
    @Inject private Class2 class2;
    @Inject private Class3 class3;

}

I want to find all classes that inject class1 and class2 and DO NOT inject class3. I've tried to use Structural search from IntelliJ but got stuck. Is it doable with structural search?

Upvotes: 1

Views: 406

Answers (2)

Bas Leijdekkers
Bas Leijdekkers

Reputation: 26482

I am (still) not sure I understand the problem correctly, but you could try something like this:

class $X$ {
    @Inject private Class1 $a$;
    @Inject private Class2 $b$;
    @Inject private Class3 $c$;
}

And add a count filter [0,0] on $c$.

This will find classes that have Class1 and Class2 fields, but do not have a Class3 field.

Upvotes: 0

Sergey Afinogenov
Sergey Afinogenov

Reputation: 2212

Maybe by using search template:

class $a$ {
  @Inject private Class1 $_1$;
  @Inject private Class1 $_2$;
  $3$;
}

and search text filters for $_1$ $_2$ and $_3$: respectively

text=class1
text=class2
text=!@Inject private Class1 class3;

Upvotes: 2

Related Questions