Enable array initialisation indentation settings
- created new 'arrayInitIndent' property to set different indentation than basic offset
This commit is contained in:
parent
cc2d12bbd4
commit
c3f856aba5
|
|
@ -105,7 +105,8 @@ public class ArrayInitHandler extends BlockParentHandler
|
|||
// new int[] {1, 2,
|
||||
// 3};
|
||||
|
||||
final IndentLevel expectedIndent = super.getChildrenExpectedLevel();
|
||||
final IndentLevel expectedIndent =
|
||||
new IndentLevel(getLevel(), getIndentCheck().getArrayInitIndent());
|
||||
|
||||
final int firstLine = getFirstLine(Integer.MAX_VALUE, getListChild());
|
||||
if (hasCurlys() && (firstLine == getLCurly().getLineNo())) {
|
||||
|
|
|
|||
|
|
@ -122,6 +122,9 @@ public class IndentationCheck extends Check
|
|||
/** how far throws should be indented when on next line */
|
||||
private int mThrowsIndentationAmount = DEFAULT_INDENTATION;
|
||||
|
||||
/** how much to indent an array initialisation when on next line */
|
||||
private int mArrayInitIndentationAmount = DEFAULT_INDENTATION;
|
||||
|
||||
/** handlers currently in use */
|
||||
private final FastStack<ExpressionHandler> mHandlers =
|
||||
FastStack.newInstance();
|
||||
|
|
@ -214,6 +217,26 @@ public class IndentationCheck extends Check
|
|||
return this.mThrowsIndentationAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the array initialisation indentation level.
|
||||
*
|
||||
* @param aArrayInitIndent the array initialisation indentation level
|
||||
*/
|
||||
public void setArrayInitIndent(int aArrayInitIndent)
|
||||
{
|
||||
mArrayInitIndentationAmount = aArrayInitIndent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array initialisation indentation level.
|
||||
*
|
||||
* @return the array initialisation indentation level
|
||||
*/
|
||||
public int getArrayInitIndent()
|
||||
{
|
||||
return this.mArrayInitIndentationAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an error message.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -188,11 +188,25 @@ public class IndentationCheckTest extends BaseCheckTestSupport
|
|||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidArrayInitDefaultIndentWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("indentation/InputValidArrayInitDefaultIndent.java");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(c, fname, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidArrayInitWithChecker()
|
||||
throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
|
||||
checkConfig.addAttribute("arrayInitIndent", Integer.valueOf(8).toString());
|
||||
|
||||
final Checker c = createChecker(checkConfig);
|
||||
final String fname = getPath("indentation/InputValidArrayInitIndent.java");
|
||||
final String[] expected = {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* InputValidArrayInitIndent.java
|
||||
*
|
||||
* Created on December 9, 2002, 9:57 PM
|
||||
*/
|
||||
|
||||
package com.puppycrawl.tools.checkstyle.indentation;
|
||||
|
||||
public class InputValidArrayInitIndent {
|
||||
|
||||
private static char[] sHexChars = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
int[] array = new int[] {1, 2, 3};
|
||||
|
||||
int[] array2 = new int[] {
|
||||
1, 2, 3
|
||||
};
|
||||
|
||||
int[] array3 = new int[] {
|
||||
1,
|
||||
2,
|
||||
3
|
||||
};
|
||||
|
||||
int[] array4 = new int[]
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3
|
||||
};
|
||||
|
||||
int[] array5 = new int[]
|
||||
{1, 2, 3};
|
||||
|
||||
// check nesting on first line
|
||||
int[] array6 = new int[] { 1, 2,
|
||||
3
|
||||
};
|
||||
|
||||
int[] array6a = new int[] { 1, 2,
|
||||
3, 4};
|
||||
|
||||
// nesting
|
||||
int[] array7 = new int[] {
|
||||
1, 2,
|
||||
3
|
||||
};
|
||||
|
||||
String[][] mStuff = new String[][] {
|
||||
{ "key", "value" }
|
||||
};
|
||||
|
||||
String[][] mStuff1 = new String[][]
|
||||
{
|
||||
{ "key", "value" }
|
||||
};
|
||||
|
||||
int[] array8 = new int[] { };
|
||||
|
||||
int[] array9 = new int[] {
|
||||
};
|
||||
|
||||
int[][] array10 = new int[][] {
|
||||
new int[] { 1, 2, 3},
|
||||
new int[] { 1, 2, 3},
|
||||
};
|
||||
|
||||
int[][] array10b
|
||||
= new int[][] {
|
||||
new int[] { 1, 2, 3},
|
||||
new int[] { 1, 2, 3},
|
||||
};
|
||||
|
||||
private void func1(int[] arg) {
|
||||
|
||||
char[] sHexChars2 = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
char[] sHexChars3 = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
char[] sHexChars4 =
|
||||
{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/** Creates a new instance of InputValidArrayInitIndent */
|
||||
public InputValidArrayInitIndent() {
|
||||
|
||||
func1(new int[] {1, 2});
|
||||
func1(new int[] {});
|
||||
func1(new int[] {
|
||||
1, 2, 3
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -13,27 +13,27 @@ package com.puppycrawl.tools.checkstyle.indentation;
|
|||
public class InputValidArrayInitIndent {
|
||||
|
||||
private static char[] sHexChars = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
int[] array = new int[] {1, 2, 3};
|
||||
|
||||
int[] array2 = new int[] {
|
||||
1, 2, 3
|
||||
1, 2, 3
|
||||
};
|
||||
|
||||
int[] array3 = new int[] {
|
||||
1,
|
||||
2,
|
||||
3
|
||||
1,
|
||||
2,
|
||||
3
|
||||
};
|
||||
|
||||
|
||||
int[] array4 = new int[]
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3
|
||||
1,
|
||||
2,
|
||||
3
|
||||
};
|
||||
|
||||
int[] array5 = new int[]
|
||||
|
|
@ -42,7 +42,7 @@ public class InputValidArrayInitIndent {
|
|||
|
||||
// check nesting on first line
|
||||
int[] array6 = new int[] { 1, 2,
|
||||
3
|
||||
3
|
||||
};
|
||||
|
||||
int[] array6a = new int[] { 1, 2,
|
||||
|
|
@ -50,17 +50,17 @@ public class InputValidArrayInitIndent {
|
|||
|
||||
// nesting
|
||||
int[] array7 = new int[] {
|
||||
1, 2,
|
||||
3
|
||||
1, 2,
|
||||
3
|
||||
};
|
||||
|
||||
String[][] mStuff = new String[][] {
|
||||
{ "key", "value" }
|
||||
{ "key", "value" }
|
||||
};
|
||||
|
||||
String[][] mStuff1 = new String[][]
|
||||
{
|
||||
{ "key", "value" }
|
||||
{ "key", "value" }
|
||||
};
|
||||
|
||||
int[] array8 = new int[] { };
|
||||
|
|
@ -69,32 +69,32 @@ public class InputValidArrayInitIndent {
|
|||
};
|
||||
|
||||
int[][] array10 = new int[][] {
|
||||
new int[] { 1, 2, 3},
|
||||
new int[] { 1, 2, 3},
|
||||
new int[] { 1, 2, 3},
|
||||
new int[] { 1, 2, 3},
|
||||
};
|
||||
|
||||
|
||||
int[][] array10b
|
||||
= new int[][] {
|
||||
new int[] { 1, 2, 3},
|
||||
new int[] { 1, 2, 3},
|
||||
new int[] { 1, 2, 3},
|
||||
new int[] { 1, 2, 3},
|
||||
};
|
||||
|
||||
private void func1(int[] arg) {
|
||||
|
||||
char[] sHexChars2 = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
char[] sHexChars3 = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
char[] sHexChars4 =
|
||||
{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ public class InputValidArrayInitIndent {
|
|||
func1(new int[] {1, 2});
|
||||
func1(new int[] {});
|
||||
func1(new int[] {
|
||||
1, 2, 3
|
||||
1, 2, 3
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -809,6 +809,12 @@ messages.properties: Key 'ok' missing.
|
|||
<td><a href="property_types.html#integer">Integer</a></td>
|
||||
<td>4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>arrayInitIndent</td>
|
||||
<td>how much to indent an array initialisation 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