jdorosz jdorosz - 4 months ago 12
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.*"/>
</module>


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

example regex test

Answer

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.