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 c3c4d1e73..f99552a03 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java @@ -103,6 +103,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; * * @author jrichard * @author o_sukhodolsky + * @author Maikel Steneker */ public class IndentationCheck extends Check { @@ -118,6 +119,9 @@ public class IndentationCheck extends Check /** how far brace should be indented when on next line */ private int mBraceAdjustment; + /** how far throws should be indented when on next line */ + private int mThrowsIndentationAmount = DEFAULT_INDENTATION; + /** handlers currently in use */ private final FastStack mHandlers = FastStack.newInstance(); @@ -190,6 +194,26 @@ public class IndentationCheck extends Check return mCaseIndentationAmount; } + /** + * Set the throws indentation level. + * + * @param aThrowsIndent the throws indentation level + */ + public void setThrowsIndent(int aThrowsIndent) + { + mThrowsIndentationAmount = aThrowsIndent; + } + + /** + * Get the throws indentation level. + * + * @return the throws indentation level + */ + public int getThrowsIndent() + { + return this.mThrowsIndentationAmount; + } + /** * Log an error message. * diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/MethodDefHandler.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/MethodDefHandler.java index 6aebd0f93..eda1a93d6 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/MethodDefHandler.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/MethodDefHandler.java @@ -25,6 +25,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; * Handler for method definitions. * * @author jrichard + * @author Maikel Steneker */ public class MethodDefHandler extends BlockParentHandler { @@ -75,7 +76,7 @@ public class MethodDefHandler extends BlockParentHandler final int columnNo = expandedTabsColumnNo(throwsAst); final IndentLevel expectedColumnNo = - new IndentLevel(getLevel(), getBasicOffset()); + new IndentLevel(getLevel(), getIndentCheck().getThrowsIndent()); if (startsLine(throwsAst) && !expectedColumnNo.accept(columnNo)) diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InvalidInputThrowsIndent.java b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InvalidInputThrowsIndent.java new file mode 100644 index 000000000..a38be4a1d --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InvalidInputThrowsIndent.java @@ -0,0 +1,21 @@ +package com.puppycrawl.tools.checkstyle.checks.indentation; + +public class InvalidInputThrowsIndent { + + public InvalidInputThrowsIndent() + { + } + + // This should pass for our reconfigured throwsIndent test. + private void myFunc() + throws Exception + { + } + + // This is the out of the box default configuration, but should fail + // for our reconfigured test. + private void myFunc() + throws Exception + { + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java index 58b6d5a61..87bf8c3db 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java @@ -680,6 +680,17 @@ public class IndentationCheckTest extends BaseCheckTestSupport verify(checkConfig, getPath("indentation/InputUseTwoSpaces.java"), expected); } + @Test + public void testThrowsIndentationLevel() throws Exception + { + final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class); + checkConfig.addAttribute("throwsIndent", Integer.valueOf(8).toString()); + final String[] expected = { + "18: method def throws at indentation level 8 not at correct indentation, 12", + }; + verify(checkConfig, getPath("indentation/InvalidInputThrowsIndent.java"), expected); + } + @Test public void testCaseLevel() throws Exception { diff --git a/src/xdocs/config_misc.xml b/src/xdocs/config_misc.xml index 0ed8dd0d5..4d6a4f478 100755 --- a/src/xdocs/config_misc.xml +++ b/src/xdocs/config_misc.xml @@ -803,6 +803,12 @@ messages.properties: Key 'ok' missing. Integer 4 + + throwsIndent + how far throws should be indented when on next line + Integer + 4 +