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 @@
com.puppycrawl.tools.checkstyle.checks @@ -688,6 +692,78 @@ like 1. TreeWalker
+ Indentation ++ 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. +
+ +| name | +description | +type | +default value | +
|---|---|---|---|
| basicOffset | +how many spaces to use for new indentation level | +String | +"4" | +
| braceAdjustment | +how far brace should be indented when on next line | +String | +"0" | +
| caseIndent | +how much to indent a case label | +String | +"4" | +
+ 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> ++ +
+ com.puppycrawl.tools.checkstyle.checks.indentation +
++ 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); } /**