是否有任何PMD或there风格的规则可以帮助我禁止在Java代码中使用某些类?
就我的情况而言,我想在所有可能的情况下禁止下列所有行为:
org.apache.commons.lang3.CharEncodingorg.apache.commons.lang.CharEncodingorg.apache.commons.codec.CharEncoding我已经找到了IllegalImport检查,但是它是关于包的,而不是特定的类。
发布于 2020-12-21 16:04:59
对于PMD,您可以编写如下规则:
<rule name="Prohibited classes"
language="java"
message="Avoid using these classes."
class="net.sourceforge.pmd.lang.rule.XPathRule" >
<description>
Avoid using these classes, there are better alternatives.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//Name[pmd-java:typeIs('org.apache.commons.lang3.CharEncoding')] |
//Name[pmd-java:typeIs('org.apache.commons.lang.CharEncoding')] |
//Name[pmd-java:typeIs('org.apache.commons.codec.CharEncoding')]
]]>
</value>
</property>
</properties>
</rule>或//Name[starts-with(@Image, 'com.sun.')]禁止包导入。
发布于 2018-11-21 05:10:58
您可以尝试将这些pmd扩展用于黑名单类和方法:扩展
https://stackoverflow.com/questions/35184640
复制相似问题