IndentationCheck now accepts the follows "if" indenation
if (test
)
This commit is contained in:
parent
a4d63db21d
commit
0eeb5e4fd6
|
|
@ -268,21 +268,29 @@ public class BlockParentHandler extends ExpressionHandler
|
|||
*/
|
||||
protected void checkRParen()
|
||||
{
|
||||
// the rcurly can either be at the correct indentation, or on
|
||||
// the same line as the lcurly
|
||||
final DetailAST rparen = getRParen();
|
||||
|
||||
// TODO: perhaps the handler should allow to place
|
||||
// rparen at indentation of lparen plus 1
|
||||
// if (test1
|
||||
// || test2
|
||||
// )
|
||||
if (rparen == null
|
||||
|| expandedTabsColumnNo(rparen) == getLevel()
|
||||
// no paren - no check :)
|
||||
if (rparen == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// the rcurly can either be at the correct indentation,
|
||||
// or not first on the line ...
|
||||
final int rparenLevel = expandedTabsColumnNo(rparen);
|
||||
if (rparenLevel == getLevel()
|
||||
|| !startsLine(rparen))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// or has <lparen level> + 1 indentation
|
||||
final DetailAST lparen = getLParen();
|
||||
final int lparenLevel = expandedTabsColumnNo(lparen);
|
||||
if (rparenLevel == (lparenLevel + 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
logError(rparen, "rparen", expandedTabsColumnNo(rparen));
|
||||
}
|
||||
|
||||
|
|
@ -318,7 +326,7 @@ public class BlockParentHandler extends ExpressionHandler
|
|||
}
|
||||
DetailAST listChild = getListChild();
|
||||
if (listChild != null) {
|
||||
final int expectedLevel =
|
||||
final int expectedLevel =
|
||||
getLevel() + getIndentCheck().getIndentationAmount();
|
||||
// NOTE: switch statements usually don't have curlys
|
||||
if (!hasCurlys() || !areOnSameLine(getLCurly(), getRCurly())) {
|
||||
|
|
|
|||
|
|
@ -11,59 +11,59 @@ package com.puppycrawl.tools.checkstyle.indentation;
|
|||
* @author jrichard
|
||||
*/
|
||||
public class InputValidIfIndent {
|
||||
|
||||
|
||||
|
||||
// test ifs
|
||||
public void emptyIfTest()
|
||||
{
|
||||
boolean test = true;
|
||||
|
||||
|
||||
// lcurly on same line
|
||||
if (test) {
|
||||
}
|
||||
|
||||
// lcurly on next line
|
||||
if (test)
|
||||
if (test)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// lcurly for if and else on same line
|
||||
if (test) {
|
||||
} else {
|
||||
}
|
||||
|
||||
|
||||
// lcurly for if and else on same line
|
||||
if (test)
|
||||
if (test)
|
||||
{
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
// lcurly for if and else on same line -- mixed braces
|
||||
if (test) {
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
// lcurly for if and else on same line -- mixed braces
|
||||
if (test)
|
||||
if (test)
|
||||
{
|
||||
} else
|
||||
} else
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// lcurly for if and else on same line -- mixed braces
|
||||
if (test)
|
||||
if (test)
|
||||
{
|
||||
} else {
|
||||
}
|
||||
|
||||
|
||||
// lcurly for if and else on same line -- mixed braces, unnested
|
||||
if (test) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
|
@ -82,14 +82,14 @@ public class InputValidIfIndent {
|
|||
else
|
||||
System.getProperty("blah");
|
||||
|
||||
|
||||
|
||||
// lcurly on same line, and stmt
|
||||
if (test) {
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
||||
|
||||
// lcurly on next line and stmt
|
||||
if (test)
|
||||
if (test)
|
||||
{
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
|
@ -100,14 +100,14 @@ public class InputValidIfIndent {
|
|||
System.
|
||||
getProperty("blah");
|
||||
}
|
||||
|
||||
|
||||
// lcurly for if and else on same line
|
||||
if (test)
|
||||
if (test)
|
||||
{
|
||||
System.getProperty("blah");
|
||||
System.getProperty("blah");
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
|
@ -115,117 +115,119 @@ public class InputValidIfIndent {
|
|||
// lcurly for if and else on same line -- mixed braces
|
||||
if (test) {
|
||||
System.getProperty("blah");
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// lcurly for if and else on same line -- mixed braces
|
||||
if (test)
|
||||
if (test)
|
||||
{
|
||||
System.getProperty("blah");
|
||||
} else
|
||||
} else
|
||||
{
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
||||
|
||||
// lcurly for if and else on same line -- mixed braces
|
||||
if (test)
|
||||
if (test)
|
||||
{
|
||||
System.getProperty("blah");
|
||||
} else {
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
||||
|
||||
// lcurly for if and else on same line -- mixed braces, unnested
|
||||
if (test) {
|
||||
System.getProperty("blah");
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
||||
|
||||
if (test) System.getProperty("blah");
|
||||
|
||||
if (test) System.getProperty("blah");
|
||||
else System.getProperty("foo");
|
||||
|
||||
if (test) System.getProperty("blah");
|
||||
else
|
||||
else System.getProperty("foo");
|
||||
|
||||
if (test) System.getProperty("blah");
|
||||
else
|
||||
System.getProperty("foo");
|
||||
|
||||
if (test)
|
||||
System.getProperty("blah");
|
||||
if (test)
|
||||
System.getProperty("blah");
|
||||
else System.getProperty("foo");
|
||||
|
||||
|
||||
if (test
|
||||
&& 7 < 8 && 8 < 9
|
||||
&& 10 < 11) {
|
||||
}
|
||||
|
||||
|
||||
if (test)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
if (test) {
|
||||
} else if (7 < 8) {
|
||||
} else if (8 < 9) {
|
||||
}
|
||||
|
||||
if (test) {
|
||||
System.getProperty("blah");
|
||||
System.getProperty("blah");
|
||||
} else if (7 < 8) {
|
||||
System.getProperty("blah");
|
||||
System.getProperty("blah");
|
||||
} else if (8 < 9) {
|
||||
System.getProperty("blah");
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (test)
|
||||
System.getProperty("blah");
|
||||
System.getProperty("blah");
|
||||
else if (7 < 8)
|
||||
System.getProperty("blah");
|
||||
System.getProperty("blah");
|
||||
else if (8 < 9)
|
||||
System.getProperty("blah");
|
||||
|
||||
|
||||
System.getProperty("blah");
|
||||
|
||||
|
||||
// TODO: bother to support this style?
|
||||
if (test) {
|
||||
System.getProperty("blah");
|
||||
} else
|
||||
System.getProperty("blah");
|
||||
} else
|
||||
if (7 < 8) {
|
||||
System.getProperty("blah");
|
||||
} else
|
||||
System.getProperty("blah");
|
||||
} else
|
||||
if (8 < 9) {
|
||||
System.getProperty("blah");
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// public void parenIfTest() {
|
||||
// boolean test = true;
|
||||
//
|
||||
// if (test
|
||||
// ) {
|
||||
// System.getProperty("blah");
|
||||
// }
|
||||
|
||||
public void parenIfTest() {
|
||||
boolean test = true;
|
||||
|
||||
if (test
|
||||
) {
|
||||
System.getProperty("blah");
|
||||
}
|
||||
//
|
||||
// if (test
|
||||
// )
|
||||
// {
|
||||
// System.getProperty("blah");
|
||||
// }
|
||||
//
|
||||
// if
|
||||
// (
|
||||
// test
|
||||
// ) {
|
||||
// System.getProperty("blah");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
if (test
|
||||
)
|
||||
{
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
test
|
||||
) {
|
||||
System.getProperty("blah");
|
||||
}
|
||||
|
||||
if (test
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue