How to suppress Java warnings for specific directories or files such as generated code

后端 未结 13 1551
太阳男子
太阳男子 2020-12-02 07:13

I\'m using a parser generator that creates somewhat ugly code. As a result my Eclipse project has several dozen warnings emanating from generated source files. I know I can

相关标签:
13条回答
  • 2020-12-02 07:57

    User @Jorn hinted at Ant code to do this. Here's what I have

    <echo>Adding @SuppressWarnings("all") to ANTLR generated parser/lexer *.java</echo>
    <echo> in ${project.build.directory}/generated-sources/antlr/</echo>
    <replace dir="${project.build.directory}/generated-sources/antlr/" 
             summary="true" 
             includes="**/*.java" 
             token="public class" 
             value='@SuppressWarnings("all") public class' />
    

    Note that Ant's <replace> does text replacement, not regular expression replacement, so it cannot use the ^ meta-character in the token to match beginning of line as the maven regexp replace plugin does.

    I'm doing this at the same time that I run Antlr from maven-antrun-plugin in my Maven pom, because the ANTLR maven plugin did not play well with the Cobertura maven plugin.

    (I realize this is not an answer to the original question, but I can't format Ant code in a comment/reply to another answer, only in an answer)

    0 讨论(0)
提交回复
热议问题