Code inspection

更新时间:
复制 MD 格式

Cloud Toolkit includes a Java code inspection feature. This feature performs static analysis on Java code based on the Alibaba Coding Guidelines. It helps you quickly identify code issues and provides suggestions for fixes before compilation.

Prerequisites

You have installed the Cloud Toolkit plugin, version 2019.11.1 or later. For more information about how to install the plugin, see the following topics:

Run a code inspection

  1. Open your project in IntelliJ IDEA.

  2. Right-click your application project name and select Alibaba Cloud > Coding Guidelines Check.

    Note

    If you do not want to check the entire project, you can select a specific directory from the project files, click a blank area in the code editor, and then select Alibaba Cloud > Coding Guidelines Check to start the check.

  3. The Inspection Results panel appears below the project directory. You can view the code inspection progress at the bottom of the panel.

    By default, Cloud Toolkit categorizes detected issues by severity in descending order: Blocker, Critical, and Major.

    Important

    Blocker issues may prevent the code from compiling successfully.

  4. The left pane of the Inspection Results panel displays a directory of the issues. Click an issue to view its details in the right pane.

    The following table describes the features of each area in the Inspection Results panel.

    Area

    Description

    Area 1

    Displays the error code. For some issues, a quick-fix suggestion is provided.

    Area 2

    Displays the line number of the error, such as line XX, for the issue in the directory. Double-click the node to navigate to and highlight the corresponding code in the code editor above the Inspection Results panel.

    Area 3

    Displays the function buttons. The buttons are described below, from left to right and top to bottom:

    • Rerun Inspection: Runs the code inspection again.

    • Group by Severity: Groups the issues by severity.

    • Expand All: Expands all nodes in the issue directory.

    • Group by Directory: Groups the issues by directory.

    • Collapse All: Collapses all nodes in the issue directory.

    • Filter Resolved Items: Filters out the issues that have been resolved.

    • Go Prev Problem: Navigates to the previous issue in the directory.

    • Autoscroll to Source: When this feature is enabled, clicking an issue in the directory automatically scrolls to the corresponding code in the code editor.

    • Go Next Problem: Navigates to the next issue in the directory.

    • Export: Exports the issue report to a local file. You can export the report in HTML or XML format.

    • Edit Settings: Edits the settings file for the code inspection.

    • Apply Quickfix: Applies the quick-fix.

    Area 4

    Displays the code inspection results.

  5. You can use the quick-fix feature to correct the code or modify the code manually.