jdorosz jdorosz - 1 year ago 60
Java Question

checkstyle regex is not working

This regex should find java classes witch no '@Configuration' word and more than one '@Inject' word. In java Matcher it works, but not in checkstyle.

<module name="RegexpMultiline">
<property name="format" value="(?s)((?!@Configuration).)*@Inject.*@Inject.*"/>

In this example result is false, but if u delete
from target text then result is true - good. Checkstyle always produces true.

example regex test

Answer Source

RegexpMulitiline check is based on find(), see checks/regexp/MultilineDetector.java#L95.

And indeed your example shows that there is Find result (there is no Match though). You need to accommodate your pattern to return nothing also for Find.