Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

IntelliJ IDEA provides tools designed for static code analysis (so called code instectionsinspections) that help you maintain and clean up your code without actually executing it. In IntelliJ IDEA you will find a set of built-in inspections that are grouped by their goals and sense. For more information about code inspections, see Inspecting Source Code in IntelliJ IDEA Web Help.
You can create custom inspections through the IntelliJ IDEA interface (see Creating Own Inspections ). Alternatively, you can develop a plugin to implement a custom inspection.

...

Configuring the Plugin

Once the plugin is launcedlaunched, you can set the plugin options. You can specify the Java classes to be participated in the code inspection and the severity level of the found probable bugs.

To configure the sample plugin

  1. In On the IDEA main menu, choose File | Settings, and then under Project Settings, click Inspections.
  2. In the list of the IntelliJ IDEA inspections, expand the Probable bugs node, and then click '==' or '!=' instead of 'equals()'.
    Image Removed Image Added
  3. Under Options, you can specify the following plugin settings:
    • 1
    • 2
    • From the Severity list, select the severity level of probable bugs the plugin will find (such as Warning, Info, etc.)
    • In the text box under Severity, specify the semicolon separated list of Java classes to be participated in this code inspection.
  4. When finished, click OK.

How It Works?

The plugin inspects your code opened in the IntelliJ IDEA editor or the code you are typing. The plugin highlights the code fragments where two variables of the reference type are separated by == or != and proposes to replace this code fragment with * .equals():

In this example, the s1 and s2 are variables of the String type. Clicking Use equals() replaces

...

Code Block
return (s1.equals(s2));

Testing the Plugin

The sample plugin contains the TestThisPlugin Java class in the testSource/testPlugin package and the test data in the <plugin directory>/testData directory.
The This test program covers adds two test cases to this plugin project. To perform the plugin run test cases, run the YourTest.test() or YourTest.test1() method, respectively.

For detailed information about testing and all related procedures, refer to Testing and Testing Support in the IntelliJ IDEA Web Help.