Search code examples
javaspringintellij-ideastructural-search

how to negate search in intellij structural search


How can i exclude terms from intellij's structure search? (NOT text or regex seach!)

for example, using the annotated field template, let's say i want to add @Lazy to all occurrences of @Autowired for fields of type X?

That means I want to match:

@Autowired
private X x;

as well as

@Autowired
@Getter
Private X x;

but not

@Lazy
@Autowired
Private X x;

I understood from the manual how to match positively by adding conditional text=... to the elements, but not how to add a negative.

Edit1: the reason a regex is not the answer (as suggested in a comment), is because the Structural search matches things like different annotations between the annotation i'm searching for and the field, also it matches any access prefix on the field, etc.

If I move from structured to regex/text search find/replace, then i will have many other problems.


Solution

  • Add a @$Lazy$ annotation to the search template with a text filter Lazy and a count filter [0,0]. This will only find elements that do not have the @Lazy annotation.