Added new rule: DontImportSunRule
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2510 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
????, 2004 - 1.5:
|
||||
New rules: DontImportSunRule
|
||||
TODO - fix it so tests and rules don't duplicate the xpath expressions
|
||||
Added isTrue() to ASTBooleanLiteral.
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
package test.net.sourceforge.pmd.rules;
|
||||
|
||||
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
import test.net.sourceforge.pmd.testframework.TestDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.rules.XPathRule;
|
||||
|
||||
public class DontImportSunRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//ImportDeclaration[starts-with(Name/@Image, 'sun.')][not(starts-with(Name/@Image, 'sun.misc.Signal'))]");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[] {
|
||||
new TestDescriptor(TEST1, "bad, import from sun.", 1, rule),
|
||||
new TestDescriptor(TEST2, "ok, signal is ok", 0, rule),
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"import sun.Foo;" + PMD.EOL +
|
||||
"public class Bar {}";
|
||||
|
||||
private static final String TEST2 =
|
||||
"import sun.misc.Signal;" + PMD.EOL +
|
||||
"public class Bar {}";
|
||||
}
|
@ -5,6 +5,33 @@
|
||||
These are new rules for the next release
|
||||
</description>
|
||||
|
||||
<rule name="DontImportSunRule"
|
||||
message="Avoid importing anything from the 'sun.*' packages"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ImportDeclaration
|
||||
[starts-with(Name/@Image, 'sun.')]
|
||||
[not(starts-with(Name/@Image, 'sun.misc.Signal'))]
|
||||
]]>
|
||||
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>4</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
import sun.misc.foo;
|
||||
public class Foo {}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li>Chad Loder - improvements to ASTBooleanLiteral</li>
|
||||
<li>Chad Loder - DontImportSunRule, improvements to ASTBooleanLiteral</li>
|
||||
<li>Lokesh Gupta - improvements to the AST viewer</li>
|
||||
<li>Jesse Glick - improvements to VariableNamingConventionsRule, patch for UnusedModifierRule, bug fix for VariableNameDeclarations rule, an excellent discussion on the UnnecessaryConstructorRule</li>
|
||||
<li>Nicolas Liochon - CloneShouldCallSuperCloneRule implementation</li>
|
||||
|
Reference in New Issue
Block a user