Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.puppycrawl.tools.checkstyle.checks.imports
Class ImportOrderCheck  view ImportOrderCheck download ImportOrderCheck.java

java.lang.Object
  extended bycom.puppycrawl.tools.checkstyle.api.AutomaticBean
      extended bycom.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
          extended bycom.puppycrawl.tools.checkstyle.api.Check
              extended bycom.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck
All Implemented Interfaces:
com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable

public class ImportOrderCheck
extends com.puppycrawl.tools.checkstyle.api.Check

Class to check 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.

Example:

  <module name="ImportOrder">
    <property name="groups" value="java,javax"/>
    <property name="ordered" value="true"/>
  </module>
 
There is always an additional, implied "everything else" package group. If no "groups" property is supplied, all imports belong in this "everything else" group.

ordered defaults to true.

separated defaults to false.


Field Summary
private  boolean mBeforeFirstImport
          Whether there was any imports.
private  java.lang.String[] mGroups
          List of import groups specified by the user.
private  int mLastGroup
          Last imported group.
private  java.lang.String mLastImport
          Name of last import.
private  int mLastImportLine
          Line number of last import.
private  boolean mOrdered
          Require imports in group.
private  boolean mSeparated
          Require imports in group be separated.
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.Check
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
 
Constructor Summary
ImportOrderCheck()
          Default constructor.
 
Method Summary
 void beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST)
          null
 int[] getDefaultTokens()
          null
private  int getGroupNumber(java.lang.String aName)
           
 int[] getRequiredTokens()
          null
 void setGroups(java.lang.String[] aGroups)
          sets the list of package groups and the order they should occur in the file.
 void setOrdered(boolean aOrdered)
          Sets whether or not imports should be ordered within any one group of imports.
 void setSeparated(boolean aSeparated)
          Sets whether or not groups of imports must be separated from one another by at least one blank line.
 void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
          null
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check
destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLines, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, setSeverity
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mGroups

private java.lang.String[] mGroups
List of import groups specified by the user.


mOrdered

private boolean mOrdered
Require imports in group.


mSeparated

private boolean mSeparated
Require imports in group be separated.


mLastGroup

private int mLastGroup
Last imported group.


mLastImportLine

private int mLastImportLine
Line number of last import.


mLastImport

private java.lang.String mLastImport
Name of last import.


mBeforeFirstImport

private boolean mBeforeFirstImport
Whether there was any imports.

Constructor Detail

ImportOrderCheck

public ImportOrderCheck()
Default constructor.

Method Detail

setGroups

public void setGroups(java.lang.String[] aGroups)
sets the list of package groups and the order they should occur in the file.


setOrdered

public void setOrdered(boolean aOrdered)
Sets whether or not imports should be ordered within any one group of imports.


setSeparated

public void setSeparated(boolean aSeparated)
Sets whether or not groups of imports must be separated from one another by at least one blank line.


getDefaultTokens

public int[] getDefaultTokens()
null


getRequiredTokens

public int[] getRequiredTokens()
null


getGroupNumber

private int getGroupNumber(java.lang.String aName)

beginTree

public void beginTree(com.puppycrawl.tools.checkstyle.api.DetailAST aRootAST)
null


visitToken

public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
null