From bef34e4f88e04b1c2171ef969f1d4b0c5050e3da Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Thu, 1 Jun 2006 22:39:54 +0000 Subject: [PATCH] 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 --- pmd/etc/changelog.txt | 1 + .../rules/imports/DontImportJavaLangRuleTest.java | 14 +++++++++++++- pmd/rulesets/imports.xml | 1 + .../sourceforge/pmd/ast/ASTImportDeclaration.java | 9 +++++++++ pmd/xdocs/credits.xml | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 779e73d4fb..1ef91273e1 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -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: diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/imports/DontImportJavaLangRuleTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/imports/DontImportJavaLangRuleTest.java index cfcf64bd06..a52825a582 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/imports/DontImportJavaLangRuleTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/imports/DontImportJavaLangRuleTest.java @@ -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 {}"; + + } diff --git a/pmd/rulesets/imports.xml b/pmd/rulesets/imports.xml index d9f69c803c..49505c6f34 100644 --- a/pmd/rulesets/imports.xml +++ b/pmd/rulesets/imports.xml @@ -39,6 +39,7 @@ Avoid importing anything from the package 'java.lang'. These classes are automa
    +
  • Paul Field - Reported a bug in DontImportJavaLang
  • Neil Cafferkey - Reported a typo in AssignmentInOperand
  • Noel Grandin - bug report for ImmutableField, bug report for MissingStaticMethodInNonInstantiatableClass, bug report for MissingBreakInSwitch, EqualsNull rule, bug report for IfElseStmtsMustUseBracesRule
  • Olaf Heimburger - wrote the UseProperClassLoader rule, code changes to get JDeveloper plugin working under JDev 10.1.3 EA, reported a possible NPE in ReportTree