Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/jsoref-spellchecker/whitelist.words
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Arial
arity
Arquillian
arraycopy
arraysquarebracketsattype
arraytrailingcomma
arraytypestyle
ASF
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
// Copyright (C) 2001-2026 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
///////////////////////////////////////////////////////////////////////////////////////////////

package com.openjdk.checkstyle.test.chapter3formatting.rule310variabledeclarations;

import org.junit.jupiter.api.Test;

import com.openjdk.checkstyle.test.base.AbstractOpenJdkModuleTestSupport;

public class ArraySquareBracketsAtTypeTest extends AbstractOpenJdkModuleTestSupport {

@Override
public String getPackageLocation() {
return "com/openjdk/checkstyle/test/chapter3formatting/"
+ "rule310variabledeclarations/arraysquarebracketsattype";
}

@Test
public void testArraySquareBracketsAtType() throws Exception {
verifyWithWholeConfig(getPath("InputArraySquareBracketsAtType.java"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.openjdk.checkstyle.test.chapter3formatting.rule310variabledeclarations.arraysquarebracketsattype;

/** Test case for ArrayTypeStyle (Java vs C). */
public class InputArraySquareBracketsAtType {
private int[] javastyle = new int[0];
private int cstyle[] = new int[0]; // violation 'Array brackets at illegal position.'

/** Some javadoc. */
public static void mainJava(String[] javastyle) {}

/** Some javadoc. */
public static void mainC(String cstyle[]) { // violation 'Array brackets at illegal position.'
final int[] blah = new int[0];
final boolean isok1 = cstyle instanceof String[];
final boolean isok2 = cstyle instanceof String[];
final boolean isok3 = blah instanceof int[];
int[] array[] = new int[2][2]; // violation 'Array brackets at illegal position.'
int array2[][][] = new int[3][3][3];
// 3 violations above:
// 'Array brackets at illegal position.'
// 'Array brackets at illegal position.'
// 'Array brackets at illegal position.'
}

/** Some javadoc. */
public class Test {
public Test[] variable;

public Test[] getTests() {
return null;
}

public Test[] getNewTest() {
return null;
}

public Test getOldTest()[] { // violation 'Array brackets at illegal position.'
return null;
}

// 2 violations 3 lines below:
// 'Array brackets at illegal position.'
// 'Array brackets at illegal position.'
public Test getOldTests()[][] {
return null;
}

public Test[] getMoreTests()[] { // violation 'Array brackets at illegal position.'
return null;
}

public Test[][] getTests2() {
return null;
}
}

int[] array[] = new int[2][2]; // violation 'Array brackets at illegal position.'
int array2[][][] = new int[3][3][3];
// 3 violations above:
// 'Array brackets at illegal position.'
// 'Array brackets at illegal position.'
// 'Array brackets at illegal position.'
}
1 change: 1 addition & 0 deletions src/main/resources/openjdk_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<module name="NumericalPrefixesInfixesSuffixesCharacterCase"/>

<module name="MultipleVariableDeclarations"/>
<module name="ArrayTypeStyle"/>

<!-- https://checkstyle.org/filters/suppressionxpathfilter.html -->
<module name="SuppressionXpathFilter">
Expand Down
4 changes: 4 additions & 0 deletions src/site/xdoc/checks/misc/arraytypestyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public class Example2 {
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fsun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ArrayTypeStyle">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fopenjdk_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ArrayTypeStyle">
OpenJDK Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig%20path%3A**%2Fcheckstyle-checks.xml+repo%3Acheckstyle%2Fcheckstyle+ArrayTypeStyle">
Checkstyle Style</a>
Expand Down
4 changes: 4 additions & 0 deletions src/site/xdoc/checks/misc/arraytypestyle.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fsun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ArrayTypeStyle">
Sun Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fopenjdk_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ArrayTypeStyle">
OpenJDK Style</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Aconfig%20path%3A**%2Fcheckstyle-checks.xml+repo%3Acheckstyle%2Fcheckstyle+ArrayTypeStyle">
Checkstyle Style</a>
Expand Down
11 changes: 10 additions & 1 deletion src/site/xdoc/openjdk_style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,18 @@
MultipleVariableDeclarations</a>
(<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fopenjdk_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MultipleVariableDeclarations">
config</a>)
<br />
<br />
<span class="wrapper inline">
<img src="images/ok_green.png" alt="" />
</span>
<a href="checks/misc/arraytypestyle.html#ArrayTypeStyle">
ArrayTypeStyle</a>
(<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fopenjdk_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ArrayTypeStyle">
config</a>)
</td>
<td>
<a href="https://github.com/checkstyle/checkstyle/tree/master/src/it/resources/com/openjdk/checkstyle/test/chapter3formatting/rule310variabledeclarations/onevariableperline">
<a href="https://github.com/checkstyle/checkstyle/tree/master/src/it/resources/com/openjdk/checkstyle/test/chapter3formatting/rule310variabledeclarations">
samples</a>
</td>
</tr>
Expand Down
Loading