Checks for imports |
![]() |
AvoidStarImportDescriptionChecks that there are no import statements that use the * notation. Rationale: Importing all classes from a package leads to tight coupling between packages and might lead to problems when a new version of a library introduces name clashes. Properties
ExampleAn example how to configure the check so that star imports from java.io and java.net are allowed: <module name="AvoidStarImport"> <property name="excludes" value="java.io,java.net"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks.imports Parent ModuleIllegalImportDescriptionChecks for imports from a set of illegal packages. By default, the check rejects all sun.* packages since programs that contain direct calls to the sun.* packages are not 100% Pure Java. To reject other packages, set property illegalPkgs to a list of the illegal packages. Properties
ExamplesTo configure the check: <module name="IllegalImport"/> To configure the check so that it rejects packages java.io.* and java.sql.*: <module name="IllegalImport"> <property name="illegalPkgs" value="java.io, java.sql"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks.imports Parent ModuleRedundantImportDescriptionChecks for redundant import statements. An import statement is considered redundant if:
ExampleTo configure the check: <module name="RedundantImport"/> Packagecom.puppycrawl.tools.checkstyle.checks.imports Parent ModuleUnusedImportsDescriptionChecks for unused import statements. Checkstyle uses a simple but very reliable algorithm to report on unused import statements. An import statement is considered unused if:
ExampleTo configure the check: <module name="UnusedImports"/> Packagecom.puppycrawl.tools.checkstyle.checks.imports Parent ModuleImportOrderDescriptionChecks the ordering/grouping of imports. Ensures that groups of imports come in a specific order (e.g., java. comes first, javax. comes first, then everything else) and imports within each group are in lexicographic order. Properties
ExampleTo configure the check so that it requires "java" packages first, than "javax" and than all other imports, imports will be sorted in the groups and groups are separated by, at least, on blank line: <module name="ImportOrder"> <property name="groups" value="java,javax"/> <property name="ordered" value="true"/> <property name="separated" value="true"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks.imports Parent Module |
Copyright © 2002-2003 Oliver Burn. All rights Reserved.