added support for a separate throws indentation configuration
This commit is contained in:
parent
503d6babef
commit
1ff166e1b6
|
|
@ -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<ExpressionHandler> 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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -803,6 +803,12 @@ messages.properties: Key 'ok' missing.
|
|||
<td><a href="property_types.html#integer">Integer</a></td>
|
||||
<td>4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>throwsIndent</td>
|
||||
<td>how far throws should be indented when on next line</td>
|
||||
<td><a href="property_types.html#integer">Integer</a></td>
|
||||
<td>4</td>
|
||||
</tr>
|
||||
</table>
|
||||
</subsection>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue