Java - 忽略目录/包级别上的警告

7

我们的部分代码是自动生成的(由Apache Axis生成),并且会报告大量警告。例如:

private java.util.HashMap faultExceptionNameMap = new java.util.HashMap();

这里的警告是:

HashMap 是一个原始类型。应该将对泛型类型 HashMap 的引用参数化。

当然,实际上解决这些警告毫无意义,因为我们必须信任 Apache Axis,并且它会简单地再次按原样重新创建代码。

由于我们团队使用不同的 IDE,从 VSCode 到 IntelliJ IDEA 到 Eclipse,我正在寻找一种与 IDE 无关的方法来排除自动生成的包/目录中出现的警告。最好是可以通过版本控制在工作区设置此选项。

在 TypeScript 中,我会在 tsconfig.json 中设置一个 exclude 数组。

例如 Java 是否有相应的方法呢?

2个回答

4
我现在只找到这种解决问题的方法:
在您的方法或变量中添加@SuppressWarnings("rawtypes"),例如:
@SuppressWarnings("rawtypes")
private java.util.HashMap faultExceptionNameMap = new java.util.HashMap();

2
我建议在自动生成的代码生成后添加@SuppressWarnings注解:

我建议在自动生成的代码生成后添加@SuppressWarnings注解:

<plugin>
   <groupId>com.google.code.maven-replacer-plugin</groupId>
   <artifactId>maven-replacer-plugin</artifactId>
    <version>1.3.2</version>
   <executions>
    <execution>
     <phase>prepare-package</phase>
     <goals>
     <goal>replace</goal>
     </goals>
     </execution>
    </executions>
    <configuration>
    <includes>
      <include>target/generated-sources/apache/blahblah//*.java</include>
    </includes>

   <regex>true</regex>
   <regexFlags>
    <regexFlag>MULTILINE</regexFlag>
   </regexFlags>

  <replacements>
   <replacement>
     <token>^(@SuppressWarnings\(.*?\)\s+)?public class</token>
   <value>@SuppressWarnings("all") public class</value>
    </replacement>
   </replacements>
  </configuration>
</plugin>

以上配置基本上是通过maven完成的。如果您有其他构建工具,则可以采取类似的方法。"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接