##### Overview

- Download PMD 4.2.5
- What's new in PMD 4.2.5
- PMD in the news
- PMD-related products and books
- Best practices
- Future directions
- Similar projects
- Credits
- License
- What does 'PMD' mean?

##### Usage

- Installation
- Command line usage
- Ant task usage
- Maven plugin usage
- Mvn plugin usage
- IDE plugin usage
- Suppressing warnings
- Finding duplicated code
- JSP support

##### Customizing PMD

- Compiling PMD
- How to write a rule
- Writing XPath rules
- How to make a rule set
- How it works
- Rule guidelines

##### For example

- Run PMD on a Sourceforge project

##### Rule Sets

- Index
- Android
- Basic
- Braces
- Code Size
- Clone
- Controversial
- Coupling
- Design
- Finalizers
- Import Statements
- J2EE
- Javabeans
- JUnit Tests
- Logging (Java)
- Logging (Jakarta)
- Migrating
- Naming
- Optimizations
- Strict Exceptions
- Strings
- Sun Security
- Unused Code
- Java Server Pages
- Java Server Faces

##### Project Documentation

- About
- Project Info
- Project Reports
- Development Process

##### Legend

- External Link
- Opens in a new window

## Import Statement Rules

These rules deal with different problems that can occur with a class' import statements.

### DuplicateImports

Since: PMD 0.5

Avoid duplicate import statements.

This rule is defined by the following Java class: net.sourceforge.pmd.rules.imports.DuplicateImportsRule

Example:

    import java.lang.String;
    import java.lang.*;
    public class Foo {}

### DontImportJavaLang

Since: PMD 0.5

Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).

This rule is defined by the following Java class: net.sourceforge.pmd.rules.imports.DontImportJavaLang

Example:

    // this is bad
    import java.lang.String;
    public class Foo {}

    // --- in another source code file...

    // this is bad
    import java.lang.*;

    public class Foo {}

### UnusedImports

Since: PMD 1.0

Avoid unused import statements.

This rule is defined by the following Java class: net.sourceforge.pmd.rules.imports.UnusedImportsRule

Example:

    // this is bad
    import java.io.File;
    public class Foo {}

### ImportFromSamePackage

Since: PMD 1.02

No need to import a type that lives in the same package.

This rule is defined by the following Java class: net.sourceforge.pmd.rules.imports.ImportFromSamePackageRule

Example:

     package foo;
     import foo.Buz; // no need for this
     import foo.*; // or this
     public class Bar{}

### TooManyStaticImports

Since: PMD 4.1

If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import. Readers of your code (including you, a few months after you wrote it) will not know which class a static member comes from (Sun 1.5 Language Guide).

This rule is defined by the following XPath expression:

    .[count(ImportDeclaration[@Static = 'true']) &gt; $maximumStaticImports]

Example:

    import static Lennon;
    import static Ringo;
    import static George;
    import static Paul;
    import static Yoko; // Too much !

This rule has the following properties:

Name | Default value | Description
maximumStaticImports |  | All static imports can be disallowed by setting this to 0