diff --git a/docs/config_misc.html b/docs/config_misc.html index 1ccd8ae34..878c650d5 100644 --- a/docs/config_misc.html +++ b/docs/config_misc.html @@ -34,6 +34,9 @@
  • GenericIllegalRegexp
  • +
  • + Indentation +
  • NewlineAtEndOfFile
  • @@ -679,6 +682,7 @@ like 1. <property name="maximumDepth" value="2"/> <property name="maximumNumber" value="10"/> </module> +

    Package

    com.puppycrawl.tools.checkstyle.checks @@ -688,6 +692,78 @@ like 1. TreeWalker

    + Indentation +

    Indentation

    Description

    +

    + Checks correct indentation of Java Code. +

    +

    + The basic idea behind this is that while + pretty printers are sometimes convienent for bulk reformats of + legacy code, they often either aren't configurable enough or + just can't anticipate how format should be done. Sometimes this is + personal preference, other times it is practical experience. In any + case, this check should just ensure that a minimal set of indentation + rules are followed. +

    + +

    Properties

    + + + + + + + + + + + + + + + + + + + + + + + + + +
    namedescriptiontypedefault value
    basicOffsethow many spaces to use for new indentation levelString"4"
    braceAdjustmenthow far brace should be indented when on next lineString"0"
    caseIndenthow much to indent a case labelString"4"
    + NOTE: although all properties have a String type + currently they must be a string representation of ineger + numbers. This were made to be able enhance these properties in + next releases in compatible manner. + +

    Examples

    +

    + To configure the check: +

    +<module name="Indentation"/>
    +      
    +

    +

    + To configure the check to enforce indentation style recommended + by Sun: +

    +<module name="Indentation">
    +    <property name="braceAdjustment" value="0"/>
    +</module>
    +      
    +

    +

    Package

    +

    + com.puppycrawl.tools.checkstyle.checks.indentation +

    +

    Parent Module

    +

    + TreeWalker +

    + diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/CaseHandler.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/CaseHandler.java index 72c938d6b..e8165060e 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/CaseHandler.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/CaseHandler.java @@ -57,8 +57,8 @@ public class CaseHandler extends ExpressionHandler */ public IndentLevel getLevelImpl() { - return new IndentLevel(getParent().getLevel(), - getIndentCheck().getCaseIndent()); + int caseIndent = Integer.parseInt(getIndentCheck().getCaseIndent()); + return new IndentLevel(getParent().getLevel(), caseIndent); } /** diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ExpressionHandler.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ExpressionHandler.java index 985741cae..86c6171fc 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ExpressionHandler.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/ExpressionHandler.java @@ -568,7 +568,7 @@ public abstract class ExpressionHandler */ protected final int getBasicOffset() { - return getIndentCheck().getBasicOffset(); + return Integer.parseInt(getIndentCheck().getBasicOffset()); } /** @@ -578,6 +578,6 @@ public abstract class ExpressionHandler */ protected final int getBraceAdjustement() { - return getIndentCheck().getBraceAdjustement(); + return Integer.parseInt(getIndentCheck().getBraceAdjustement()); } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java index 5463e3e35..912c85059 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java @@ -103,10 +103,10 @@ import org.apache.commons.collections.ArrayStack; * * * @author jrichard + * @author o_sukhodolsky */ -public class IndentationCheck - extends Check +public class IndentationCheck extends Check { /** Default indentation amount - based on Sun */ private static final int DEFAULT_INDENTATION = 4; @@ -115,7 +115,7 @@ public class IndentationCheck private int mBasicOffset = DEFAULT_INDENTATION; /** how much to indent a case label */ - private int mCaseIndentationAmount = mBasicOffset; + private int mCaseIndentationAmount = DEFAULT_INDENTATION; /** how far brace should be indented when on next line */ private int mBraceAdjustment = 0; @@ -136,9 +136,9 @@ public class IndentationCheck * * @param aBasicOffset the number of tabs or spaces to indent */ - public void setBasicOffset(int aBasicOffset) + public void setBasicOffset(String aBasicOffset) { - mBasicOffset = aBasicOffset; + mBasicOffset = Integer.parseInt(aBasicOffset); } /** @@ -146,9 +146,9 @@ public class IndentationCheck * * @return the number of tabs or spaces to indent */ - public int getBasicOffset() + public String getBasicOffset() { - return mBasicOffset; + return String.valueOf(mBasicOffset); } /** @@ -156,9 +156,9 @@ public class IndentationCheck * * @param aAdjustmentAmount the brace offset */ - public void setBraceAdjustment(int aAdjustmentAmount) + public void setBraceAdjustment(String aAdjustmentAmount) { - mBraceAdjustment = aAdjustmentAmount; + mBraceAdjustment = Integer.parseInt(aAdjustmentAmount); } /** @@ -166,9 +166,9 @@ public class IndentationCheck * * @return the positive offset to adjust braces */ - public int getBraceAdjustement() + public String getBraceAdjustement() { - return mBraceAdjustment; + return String.valueOf(mBraceAdjustment); } /** @@ -176,9 +176,9 @@ public class IndentationCheck * * @param aAmount the case indentation level */ - public void setCaseIndent(int aAmount) + public void setCaseIndent(String aAmount) { - mCaseIndentationAmount = aAmount; + mCaseIndentationAmount = Integer.parseInt(aAmount); } /** @@ -186,9 +186,9 @@ public class IndentationCheck * * @return the case indentation level */ - public int getCaseIndent() + public String getCaseIndent() { - return mCaseIndentationAmount; + return String.valueOf(mCaseIndentationAmount); } /**