Checkstyle / Module / Imports



import文のチェック。

AvoidStarImport

親モジュールTreeWalker
実装クラスcom.puppycrawl.tools.checkstyle.checks.AvoidStarImportCheck(≦3.1)
com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck(3.2)

ワイルドカードを使ったimport文がないことをチェックします。

プロパティ名デフォルト概要
excludesString Setなし(Since 3.2)チェックを除外するパッケージ

記述サンプル

  • Standard Checkstyle
    <module name = "AvoidStarImport" />
  • Plug-in Checkstyle
    <rule-configuration
        classname = "com.puppycrawl.tools.checkstyle.checks.AvoidStarImportCheck"
        severity = "warning">
        <config-properties />
    </rule-configuration>

IllegalImport

親モジュールTreeWalker
実装クラスcom.puppycrawl.tools.checkstyle.checks.IllegalImportCheck(≦3.1)
com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck(3.2)

不正なパッケージからのインポートをチェックします。不正なパッケージは、プロパティで指定。

プロパティ名デフォルト概要
illegalPkgsString Setsun不正と見なすパッケージのプレフィックス

記述サンプル

  • Standard Checkstyle
    <module name = "IllegalImport">
        <property name = "illegalPkgs" value = "java.io, java.text" />
    </module>
  • Plug-in Checkstyle
    <rule-configuration
        classname = "com.puppycrawl.tools.checkstyle.checks.IllegalImportCheck"
        severity = "warning">
        <config-properties>
            <config-property name = "illegalPkgs" value = "java.io, java.text" />
        </config-properties>
    </rule-configuration>

RedundantImport

親モジュールTreeWalker
実装クラスcom.puppycrawl.tools.checkstyle.checks.RedundantImportCheck(≦3.1)
com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck(3.2)

冗長なインポートのチェックをします。

  • インポート文が重複して、存在している。
  • 暗黙的に利用できるjava.langパッケージのクラスを、明示的にインポートしている。
  • 同一パッケージのクラスをインポートしている。

記述サンプル

  • Standard Checkstyle
    <module name = "RedundantImport" />
  • Plug-in Checkstyle
    <rule-configuration
        classname = "com.puppycrawl.tools.checkstyle.checks.RedundantImportCheck"
        severity = "warning">
        <config-properties />
    </rule-configuration>

UnusedImport

親モジュールTreeWalker
実装クラスcom.puppycrawl.tools.checkstyle.checks.UnusedImportCheck(≦3.1)
com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportCheck(3.2)

使われていないクラスをインポートしているかをチェックします。

記述サンプル

  • Standard Checkstyle
    <module name = "UnusedImport" />
  • Plug-in Checkstyle
    <rule-configuration
        classname = "com.puppycrawl.tools.checkstyle.checks.UnusedImportCheck"
        severity = "warning">
        <config-properties />
    </rule-configuration>

ImportOrder

親モジュールTreeWalker
実装クラスcom.puppycrawl.tools.checkstyle.checks.imports.UnusedImportCheck
Since3.2

import 文の順番/まとめ方をチェックします。

まとめ方とは、パッケージ名がある同じ文字列で始まっているものを、同じグループであると考えることから始まります。例えば、"java" というグループを考える場合、java.lang.Boolean と java.util.Arrays は同じグループであるとなります。そして、このグループ内で、辞書順に並んでいるかをチェックすることになります。

プロパティ名デフォルト概要
groupsString Setなしimport グループのリスト
orderedBooleantrueグループ内で辞書順になっているか?
separatedBooleanfalseグループ間が少なくとも 1行以上間があるか?
caseSensitiveBooleantrue(Since 3.3)順番を比較するときに大文字/小文字を区別するか?

記述サンプル

  • Standard Checkstyle
    <module name = "ImportOrder">
       <property name = "groups" value = "java.util, java.io, java.text" />
       <property name = "ordered" value = "true" />
       <property name = "separated" value = "true" />
       <property name = "caseSensitive" value = "false" />
    </module>