When it comes to checking and improving code quality, JDeveloper provides the View Status facility. Factoring in its ability to support third party tools through extensions, some already exist - PMD for example - others are left to the imagination of the able programmer, the possibility of producing good quality code now rests on utilizing these tools among others. In this FAQ will take a look at the View Status facility and at the PMD extension.
Main Theme
JDeveloper native support for code checking
Code checking is supported natively in JDeveloper via the View Status facility. You can activate it by selecting Status from the View menu.
Selecting it will open a Status window, which will display any issues related to the file currently active in the editor. The issues could be errors, warnings, incompletes or advisory issues.
Double-clicking on an issue in the Status window, will take you to the line in the code that produces the problem. Right-clicking on an issue, produces in many cases a possible problem resolution.
Resolving all issues associated with a particular file will produce a No Issues indicator in the Status window, which is what you want to see in most cases.
In some cases, you will find the need to adjust the behavior of the Status facility to accommodate certain standards that you establish for your project. Consider the following issue for example:
In this case, the Status window displays a warning related to an unused parameter in a backing bean function. In certain cases when the parameter cannot be removed - i.e. the method implements a superclass method, you won't be able to make this warning disappear unless you either use the parameter or adjust the properties of the Status facility. These properties are accessible through the Tools | Preferences menu under the Audit | Profiles section.
For this case, select the specific Profile, then the Rules tab and then under the Usages section the Unused Parameter rule. Change the Severity from Warning to Assist and Style from Unused to Warning. This will produce a No Issues indicator in the Status window but it will still highlight the issue as a warning in the editor. In some cases you may want to adjust the Default Fix setting as well.
In closing, notice that the same issues identified by the View | Status feature are displayed in the right gutter of the editor window as well.
PMD Extension
PMD (http://pmd.sourceforge.net/) can be installed as a JDeveloper extension via the Help | Check for Updates... feature. Select the Open Source and Partners Extensions Update Center in step 2 of the Check for Updates wizard and in step 3 PMD JDeveloper Extension 4.2.5.3.0.
JDeveloper will download the extension and it will ask you to re-start upon clicking Finish in step 5 of the Check for Updates wizard. Upon re-starting JDeveloper, PMD is available by right-clicking anywhere in the editor window and selecting PMD from the context menu. This will check the file currently open in the editor. You can also right-click anywhere in the Application Navigation window to check multiple or all files in your project(s).
Before running PMD for the first time, ensure that all rules are enabled by clicking Select all in the PMD Preferences page (accessible through the Tools | Preferences menu) as it shown below. Later on, you can adjust these settings according to your project's standards.
When running PMD it will open a PMD - Log window with a list of code improvement recommendations.
Double-clicking on any of the recommendations in the PMD - Log window, will take you directly to the specific line in the code that produces it. Resolving all issues reported by PMD will produce a No problems found dialog, which is again what you want to see in most cases.
Conclusion
Through native support and support via third party extensions, the tools exist within the JDeveloper IDE to help you as a developer produce better quality code for your projects. Their usage will spot problem areas in your code and help you learn and improve.
Until the next time, keep on JDeveloping!