Fixed bug 1498960 - DontImportJavaLang no longer reports static imports of java.lang members.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4401 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2006-06-01 22:39:54 +00:00
parent fe08efab59
commit bef34e4f88
5 changed files with 25 additions and 1 deletions

View File

@ -1,5 +1,6 @@
????, 2006 - 3.8:
Fixed bug 1498910 - AssignmentInOperand no longer has a typo in the message.
Fixed bug 1498960 - DontImportJavaLang no longer reports static imports of java.lang members.
June 1, 2006 - 3.7:
New rules:

View File

@ -6,6 +6,7 @@ package test.net.sourceforge.pmd.rules.imports;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleSetNotFoundException;
import net.sourceforge.pmd.Report;
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
import test.net.sourceforge.pmd.testframework.TestDescriptor;
@ -21,10 +22,16 @@ public class DontImportJavaLangRuleTest extends SimpleAggregatorTst {
runTests(new TestDescriptor[]{
new TestDescriptor(TEST1, "import java.lang.String", 1, rule),
new TestDescriptor(TEST2, "import java.lang.*", 1, rule),
new TestDescriptor(TEST3, "import java.lang.ref/reflect/annotation/instrument/management", 0, rule),
new TestDescriptor(TEST3, "import java.lang.ref/reflect/annotation/instrument/management", 0, rule)
});
}
public void testStaticImportsAreOK() throws Throwable {
Report rpt = new Report();
runTestFromString15(TEST4, rule, rpt);
assertEquals(0, rpt.size());
}
private static final String TEST1 =
"import java.lang.String;" + PMD.EOL +
"public class Foo {}";
@ -41,4 +48,9 @@ public class DontImportJavaLangRuleTest extends SimpleAggregatorTst {
"import java.lang.management.*;" + PMD.EOL +
"public class Foo {}";
private static final String TEST4 =
"import static java.lang.*;" + PMD.EOL +
"public class Foo {}";
}

View File

@ -39,6 +39,7 @@ Avoid importing anything from the package 'java.lang'. These classes are automa
<value>
<![CDATA[
//ImportDeclaration
[@Static = 'false']
[starts-with(Name/@Image, 'java.lang')]
[not(starts-with(Name/@Image, 'java.lang.ref'))]
[not(starts-with(Name/@Image, 'java.lang.reflect'))]

View File

@ -53,6 +53,15 @@ public class ASTImportDeclaration extends SimpleJavaNode {
}
public void dump(String prefix) {
String out = "";
if (isStatic()) {
out += "(static)";
}
System.out.println(toString(prefix) + out);
dumpChildren(prefix);
}
/**
* Accept the visitor. *
*/

View File

@ -48,6 +48,7 @@
</subsection>
<subsection name="Contributors">
<ul>
<li>Paul Field - Reported a bug in DontImportJavaLang</li>
<li>Neil Cafferkey - Reported a typo in AssignmentInOperand</li>
<li>Noel Grandin - bug report for ImmutableField, bug report for MissingStaticMethodInNonInstantiatableClass, bug report for MissingBreakInSwitch, EqualsNull rule, bug report for IfElseStmtsMustUseBracesRule</li>
<li><a href="http://www.orablogs.com/olaf/">Olaf Heimburger</a> - wrote the UseProperClassLoader rule, code changes to get JDeveloper plugin working under JDev 10.1.3 EA, reported a possible NPE in ReportTree</li>