0

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.

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
gabriel
  • 147
  • 1
  • 9
  • You could probably do a multiline regex match with something like `/\@AutoWired\nprivate\s.*$/m` and `/@Autowired\n@Getter\nPrivate\s.*$/m` – Joel Dec 28 '21 at 23:41
  • But this lose the ability of being a structural search. (i've updated the question to make this clear) – gabriel Dec 28 '21 at 23:57

1 Answers1

2

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.

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
  • thanks! feel bad that i missed `count` staring at me right there :) but learned that i can use the annotation name directly. – gabriel Jan 03 '22 at 17:32