##### Overview

- Download PMD 5.0.5
- What's new in PMD 5.0.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
- PMD developers information
- PMD Release Process

##### For example

- Run PMD on a Sourceforge project

##### Misc.

- XPath tutorial (Gregorian)

##### Rule Sets

- ecmascript
  - Basic Ecmascript
  - Braces
  - Unnecessary
- java
  - Android
  - Basic
  - Braces
  - Clone Implementation
  - Code Size
  - Comments
  - Controversial
  - Coupling
  - Design
  - Empty Code
  - Finalizer
  - Import Statements
  - J2EE
  - JavaBeans
  - JUnit
  - Jakarta Commons Logging
  - Java Logging
  - Migration
  - Naming
  - Optimization
  - Strict Exceptions
  - String and StringBuffer
  - Security Code Guidelines
  - Type Resolution
  - Unnecessary
  - Unused Code
- jsp
  - Basic JSF
  - Basic JSP
- xml
  - Basic XML
- xsl
  - XPath in XSL

##### Project Documentation

- Project Information
- Project Reports

## Android

These rules deal with the Android SDK, mostly related to best practices. To get better results, make sure that the auxclasspath is defined for type resolution to work.

### CallSuperFirst

Since: PMD 4.2.5

Super should be called at the start of the method

    //MethodDeclaration[MethodDeclarator[
      @Image='onCreate' or
      @Image='onConfigurationChanged' or
      @Image='onPostCreate' or
      @Image='onPostResume' or
      @Image='onRestart' or
      @Image='onRestoreInstanceState' or
      @Image='onResume' or
      @Image='onStart'
      ]]
        /Block[not(
          (BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image]))]
    [ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[
      typeof(@Image, 'android.app.Activity', 'Activity') or
      typeof(@Image, 'android.app.Application', 'Application') or
      typeof(@Image, 'android.app.Service', 'Service')
    ]]]

Example(s):

    public class DummyActivity extends Activity {
    	public void onCreate(Bundle bundle) {
         // missing call to super.onCreate(bundle)
    		foo();
    	}
    }

### CallSuperLast

Since: PMD 4.2.5

Super should be called at the end of the method

    //MethodDeclaration[MethodDeclarator[
      @Image='finish' or
      @Image='onDestroy' or
      @Image='onPause' or
      @Image='onSaveInstanceState' or
      @Image='onStop' or
      @Image='onTerminate'
      ]]
       /Block/BlockStatement[last()]
        [not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image])]
    [ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[
      typeof(@Image, 'android.app.Activity', 'Activity') or
      typeof(@Image, 'android.app.Application', 'Application') or
      typeof(@Image, 'android.app.Service', 'Service')
    ]]]

Example(s):

    public class DummyActivity extends Activity {
    	public void onPause() {
    		foo();
    		// missing call to super.onPause()
    	}
    }

### DoNotHardCodeSDCard

Since: PMD 4.2.6

Use Environment.getExternalStorageDirectory() instead of "/sdcard"

    //Literal[starts-with(@Image,'"/sdcard')]

Example(s):

    public class MyActivity extends Activity {
    	protected void foo() {
    		String storageLocation = "/sdcard/mypackage";	// hard-coded, poor approach

    		storageLocation = Environment.getExternalStorageDirectory() + "/mypackage"; // preferred approach
    	}
    }