aboutsummaryrefslogtreecommitdiff
path: root/src/test/resources/com/puppycrawl/tools/checkstyle/checks
diff options
context:
space:
mode:
authorrnveach <rveach02@gmail.com>2015-10-15 22:53:56 -0400
committerrnveach <rveach02@gmail.com>2015-10-16 18:13:31 -0400
commitbf529ef600fa9ef2034d0412c198b2121f2b94f2 (patch)
tree67c91bbe5623976acc64b8ae64351130171c37f7 /src/test/resources/com/puppycrawl/tools/checkstyle/checks
parent61f8aaca7bcb8750909bcc95eb5c27c72c7d824d (diff)
downloadcheckstyle-bf529ef600fa9ef2034d0412c198b2121f2b94f2.tar.gz
Issue #2161: unify test input locations for blocks package
Diffstat (limited to 'src/test/resources/com/puppycrawl/tools/checkstyle/checks')
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBraces.java119
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBracesSingleLineStatements.java111
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAllInOneLine.java4
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAnnotations.java67
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyEnums.java16
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyLineBreakAfter.java74
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyMethod.java89
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyOther.java170
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputNeedBracesCheckTest.java61
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurly.java24
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAloneOrSingleline.java179
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAnnotations.java219
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyEmptyAbstractMethod.java9
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyLineBreakBefore.java68
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyNameForOneLiners.java18
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces.java52
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces2.java74
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic.java87
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic2.java38
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchOnly.java34
20 files changed, 1513 insertions, 0 deletions
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBraces.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBraces.java
new file mode 100644
index 000000000..702d68d27
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBraces.java
@@ -0,0 +1,119 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2001
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+/**
+ * Test case for correct use of braces.
+ * @author Oliver Burn
+ **/
+class InputBraces
+{
+ /** @return helper func **/
+ boolean condition()
+ {
+ return false;
+ }
+
+ /** Test do/while loops **/
+ void testDoWhile()
+ {
+ // Valid
+ do {
+ testDoWhile();
+ }
+ while (condition());
+
+ // Invalid
+ do testDoWhile(); while (condition());
+ }
+
+ /** Test while loops **/
+ void testWhile()
+ {
+ // Valid
+ while (condition()) {
+ testWhile();
+ }
+
+ // Invalid
+ while(condition());
+ while (condition())
+ testWhile();
+ while (condition())
+ if (condition())
+ testWhile();
+ }
+
+ /** Test for loops **/
+ void testFor()
+ {
+ // Valid
+ for (int i = 1; i < 5; i++) {
+ testFor();
+ }
+
+ // Invalid
+ for(int i = 1;i < 5;i++);
+ for (int i = 1; i < 5; i++)
+ testFor();
+ for (int i = 1; i < 5;
+ i++)
+ if (i > 2)
+ testFor();
+ }
+
+ /** Test if constructs **/
+ public void testIf()
+ {
+ // Valid
+ if (condition()) {
+ testIf();
+ }
+ else if (condition()) {
+ testIf();
+ }
+ else {
+ testIf();
+ }
+
+ // Invalid
+ if (condition());
+ if (condition())
+ testIf();
+ if (condition())
+ testIf();
+ else
+ testIf();
+ if (condition())
+ testIf();
+ else {
+ testIf();
+ }
+ if (condition()) {
+ testIf();
+ }
+ else
+ testIf();
+ if (condition())
+ if (condition())
+ testIf();
+ }
+
+ void whitespaceAfterSemi()
+ {
+ //reject
+ int i = 1;int j = 2;
+
+ //accept
+ for (;;) {
+ }
+ }
+
+ /** Empty constructor block. **/
+ public InputBraces() {}
+
+ /** Empty method block. **/
+ public void emptyImplementation() {}
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBracesSingleLineStatements.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBracesSingleLineStatements.java
new file mode 100644
index 000000000..6260ddd82
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputBracesSingleLineStatements.java
@@ -0,0 +1,111 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+public class InputBracesSingleLineStatements
+{
+ private static class SomeClass {
+ boolean flag = true;
+ private static boolean test(boolean k) {
+ return k;
+ }
+ }
+
+ private int foo() {
+ if (SomeClass.test(true) == true) return 4; //No warning if 'mAllowSingleLineIf' is true
+ return 0;
+ }
+
+ private int foo1() {
+ if (SomeClass.test(true) == true) return 4; int k = 3; //No warning if 'mAllowSingleLineIf' is true
+ return 0;
+ }
+
+ private int foo2() {
+ if (SomeClass.test(true) == true) //Warning, not single-line if-statement
+ return 4;
+ return 0;
+ }
+
+ private int foo3() {
+ if (SomeClass.test(true) == true) if (true) return 4; //Warning, complex block
+ return 0;
+ }
+
+ private void foo(Object o) {
+ if (o != null) this.notify();
+ }
+
+ private void foo2(Object o) {
+ if (o != null)
+ this.notify();
+ }
+
+ private void loopTest(Object o) {
+ while (o != null) {
+ this.notify();
+ }
+ while (o != null)
+ this.notify();
+ while (o != null) this.notify();
+ do {
+ this.notify();
+ } while (o != null);
+ do this.notify(); while (o != null);
+ do
+ this.notify();
+ while (o != null);
+ for (;;)
+ break;
+ for (;;) break;
+ for (int i = 0; i < 10; i++) {
+ this.notify();
+ }
+ for (int i = 0; i < 10; i++)
+ this.notify();
+ for (int i = 0; ; ) this.notify();
+ }
+
+ private int getSmth(int num)
+ {
+ int counter = 0;
+ switch (num) {
+ case 1: counter++; break;
+ case 2:
+ counter += 2;
+ break;
+ case 3:
+ counter += 3;
+ break;
+ case 6: counter += 10; break;
+ default: counter = 100; break;
+ }
+ return counter;
+ }
+
+ private void testElse(int k) {
+ if (k == 4) System.out.println("yes");
+ else System.out.println("no");
+ for (;;);
+ }
+
+ private int testMissingWarnings() {
+ if (true)
+ throw new RuntimeException();
+ if (true) {
+ return 1;
+ } else
+ return 2;
+ }
+
+ void enhancedForLoop(int[] array) {
+ for (int value: array) return;
+ }
+
+ int[] sourceLocators;
+
+ private class StateInfo {
+ public boolean isInitial() {
+ for (int locator: sourceLocators) if (locator != 0) return false;
+ return true;
+ }
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAllInOneLine.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAllInOneLine.java
new file mode 100644
index 000000000..b6e33b174
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAllInOneLine.java
@@ -0,0 +1,4 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;import java.lang.annotation.ElementType;import java.lang.annotation.Target;import java.util.ArrayList;import java.util.List;class InputLeftCurlyAllInOneLine{
+
+
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAnnotations.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAnnotations.java
new file mode 100644
index 000000000..5b5f94ba5
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyAnnotations.java
@@ -0,0 +1,67 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
+import java.util.List;
+
+@TestClassAnnotation
+class InputLeftCurlyAnnotations
+{
+ private static final int X = 10;
+ @Override
+ public boolean equals(Object other)
+ {
+ return false;
+ }
+
+ @Override
+ @SuppressWarnings("unused")
+ public int hashCode()
+ {
+ int a = 10;
+ return 1;
+ }
+
+ @Override @SuppressWarnings({"unused", "unchecked", "static-access"}) public String toString()
+ {
+ Integer i = this.X;
+ List<String> l = new ArrayList();
+ return "SomeString";
+ }
+}
+
+@TestClassAnnotation
+class InputLeftCurlyAnnotations2 {
+ private static final int X = 10;
+ @Override
+ public boolean equals(Object other) {
+ return false;
+ }
+
+ @Override
+ @SuppressWarnings("unused")
+ public int hashCode() {
+ int a = 10;
+ return 1;
+ }
+
+ @Override @SuppressWarnings({"unused", "unchecked", "static-access"}) public String toString()
+ {
+ Integer i = this.X;
+ List<String> l = new ArrayList();
+ return "SomeString";
+ }
+
+ @Deprecated
+ @SuppressWarnings({"unused", "unchecked", "static-access"}) public String toString2()
+ {
+ Integer i = this.X;
+ List<String> l = new ArrayList();
+ return "SomeString";
+ }
+}
+
+@Target(ElementType.TYPE)
+@interface TestClassAnnotation {
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyEnums.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyEnums.java
new file mode 100644
index 000000000..5406cb528
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyEnums.java
@@ -0,0 +1,16 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+public class InputLeftCurlyEnums {
+ enum Colors {RED,
+ BLUE,
+ GREEN
+ }
+
+ enum Languages {
+ JAVA,
+ PHP,
+ SCALA,
+ C,
+ PASCAL
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyLineBreakAfter.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyLineBreakAfter.java
new file mode 100644
index 000000000..a25324491
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyLineBreakAfter.java
@@ -0,0 +1,74 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
+import java.util.List;
+
+class InputLeftCurlyLineBreakAfter
+{
+ /** @see test method **/
+ int foo() throws InterruptedException
+ {
+ int x = 1;
+ int a = 2;
+ while (true)
+ {
+ try
+ {
+ if (x > 0)
+ {
+ break;
+ }
+ else if (x < 0) {
+ ;
+ }
+ else { break; }
+ switch (a)
+ {
+ case 0:
+ break;
+ default:
+ break;
+ }
+ }
+ catch (Exception e) { break; }
+ finally { break; }
+ }
+
+ synchronized (this) { do { x = 2; } while (x == 2); }
+
+ synchronized (this) {
+ do {} while (x == 2);
+ }
+
+ for (int k = 0; k < 1; k++) { String innerBlockVariable = ""; }
+
+ for (int k = 0; k < 1; k++) {}
+ return a;
+ }
+
+ static { int x = 1; }
+
+ void method2()
+ {
+ boolean flag = false;
+ if (flag) { System.err.println("foo"); }
+ }
+}
+
+class Absent_CustomFieldSerializer1 {
+
+ public static void serialize() {}
+}
+
+class Absent_CustomFieldSerializer2
+{
+ public Absent_CustomFieldSerializer2() {}
+}
+
+class EmptyClass1 {}
+
+interface EmptyInterface1 {}
+
+enum KnownOrder { KNOWN_ORDER, UNKNOWN_ORDER } \ No newline at end of file
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyMethod.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyMethod.java
new file mode 100644
index 000000000..bcfc7384f
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyMethod.java
@@ -0,0 +1,89 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2001
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+/**
+ * Test case for correct use of braces.
+ * @author Oliver Burn
+ **/
+class InputLeftCurlyMethod
+{
+ InputLeftCurlyMethod() {}
+ InputLeftCurlyMethod(String aOne) {
+ }
+ InputLeftCurlyMethod(int aOne)
+ {
+ }
+
+ void method1() {}
+ void method2() {
+ }
+ void method3()
+ {
+ }
+ void method4()
+ {
+ }
+ void method5(String aOne,
+ String aTwo)
+ {
+ }
+ void method6(String aOne,
+ String aTwo) {
+ }
+}
+
+enum InputLeftCurlyMethodEnum
+{
+ CONSTANT1("hello")
+ {
+ void method1() {}
+ void method2() {
+ }
+ void method3()
+ {
+ }
+ void method4()
+ {
+ }
+ void method5(String aOne,
+ String aTwo)
+ {
+ }
+ void method6(String aOne,
+ String aTwo) {
+ }
+ },
+
+ CONSTANT2("hello") {
+
+ },
+
+ CONSTANT3("hellohellohellohellohellohellohellohellohellohellohellohellohellohello")
+ {
+ };
+
+ private InputLeftCurlyMethodEnum(String value)
+ {
+
+ }
+
+ void method1() {}
+ void method2() {
+ }
+ void method3()
+ {
+ }
+ void method4()
+ {
+ }
+ void method5(String aOne,
+ String aTwo)
+ {
+ }
+ void method6(String aOne,
+ String aTwo) {
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyOther.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyOther.java
new file mode 100644
index 000000000..42c51c7dd
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputLeftCurlyOther.java
@@ -0,0 +1,170 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2001
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+/**
+ * Test case for correct use of braces.
+ * @author Oliver Burn
+ **/
+class InputLeftCurlyOther
+{
+ /** @see test method **/
+ int foo() throws InterruptedException
+ {
+ int x = 1;
+ int a = 2;
+ while (true)
+ {
+ try
+ {
+ if (x > 0)
+ {
+ break;
+ }
+ else if (x < 0) {
+ ;
+ }
+ else
+ {
+ break;
+ }
+ switch (a)
+ {
+ case 0:
+ break;
+ default:
+ break;
+ }
+ }
+ catch (Exception e)
+ {
+ break;
+ }
+ finally
+ {
+ break;
+ }
+ }
+
+ synchronized (this)
+ {
+ do
+ {
+ x = 2;
+ } while (x == 2);
+ }
+
+ this.wait(666
+ ); // Bizarre, but legal
+
+ for (int k = 0; k < 1; k++)
+ {
+ String innerBlockVariable = "";
+ }
+
+ // test input for bug reported by Joe Comuzzi
+ if (System.currentTimeMillis() > 1000)
+ return 1;
+ else
+ return 2;
+ }
+
+ // Test static initialiser
+ static
+ {
+ int x = 1; // should not require any javadoc
+ }
+
+
+
+ public enum GreetingsEnum
+ {
+ HELLO,
+ GOODBYE
+ };
+
+ void method2()
+ {
+ boolean flag = true;
+ if (flag) {
+ System.out.println("heh");
+ flag = !flag; } System.err.
+ println("Xe-xe");
+ // it is ok to have rcurly on the same line as previous
+ // statement if lcurly on the same line.
+ if (flag) { System.err.println("it is ok."); }
+ }
+}
+
+/**
+ * Test input for closing brace if that brace terminates
+ * a statement or the body of a constructor.
+ */
+class FooCtor
+{
+ int i;
+ public FooCtor()
+ {
+ i = 1;
+ }}
+
+/**
+* Test input for closing brace if that brace terminates
+* a statement or the body of a method.
+*/
+class FooMethod
+{
+ public void fooMethod()
+ {
+ int i = 1;
+ }}
+
+/**
+* Test input for closing brace if that brace terminates
+* a statement or the body of a named class.
+*/
+class FooInner
+{
+ class InnerFoo
+ {
+ public void fooInnerMethod ()
+ {
+
+ }
+ }}
+
+/**
+ * False positive
+ *
+ */
+class Absent_CustomFieldSerializer3 {
+
+ public static void serialize() {} //false positive. Expected nothing but was "'}' should be alone on a line."
+}
+
+class Absent_CustomFieldSerializer4
+{
+ public Absent_CustomFieldSerializer4() {}
+}
+
+class EmptyClass2 {}
+
+interface EmptyInterface3 {}
+
+class ClassWithStaticInitializers
+{
+ static {
+ }
+ static
+ {}
+
+ static class Inner
+ {
+ static {
+ int i = 1;
+ }
+ }
+
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputNeedBracesCheckTest.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputNeedBracesCheckTest.java
new file mode 100644
index 000000000..6f0f40ec9
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputNeedBracesCheckTest.java
@@ -0,0 +1,61 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+public class InputNeedBracesCheckTest
+{
+ public void method() {
+ if (false)
+ while(true)
+ {
+
+ }
+
+ if (true)
+ do {
+ int a = 1;
+ }
+ while(true);
+
+ if (true)
+ for(;;){
+ assert true;}
+
+ if (true){
+
+ }else {
+
+ }
+
+ switch(1) {
+ case 1: {
+ break;
+ }
+ }
+
+ switch(1) {
+ case 1: System.out.println();
+ case 2: { break;}
+
+ case 3: {
+ break;}
+
+ case 4:
+ break;
+
+ case 5: System.out.println();
+ break;
+ }
+
+ switch(1) {
+ default:
+ {
+
+ }
+ }
+
+ switch(1) {
+ default:
+ break;
+ }
+
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurly.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurly.java
new file mode 100644
index 000000000..9b8562845
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurly.java
@@ -0,0 +1,24 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2001
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+class InputRightCurly
+{
+ void foo() throws InterruptedException
+ {
+
+ try
+ {
+
+ }
+ catch (Exception e)
+ {
+ return;
+ }
+
+ }
+
+ }
+class UniqEmptyClass {private int a;} \ No newline at end of file
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAloneOrSingleline.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAloneOrSingleline.java
new file mode 100644
index 000000000..de27350d3
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAloneOrSingleline.java
@@ -0,0 +1,179 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+public class InputRightCurlyAloneOrSingleline {
+
+ public boolean equals(Object other) { boolean flag = true; return flag; }
+
+ public int hashCode()
+ {
+ int a = 10;
+ return 1;
+ }
+
+ private void foo()
+ { int var1 = 5; var2 = 6; }
+
+ private void foo1() { return; }
+
+ private String foo2() { return toString();
+ }
+
+ private void foo3() { ; return; }
+
+ private int var1;
+ private int var2;
+ public InputRightCurlyAloneOrSingleline() { this.var1 = 1; }
+ public InputRightCurlyAloneOrSingleline(int var1, int var2) { this.var1 = var1; this.var2 = var2; }
+
+ private void foo4() { ;; }
+
+ private void foo5() { ; }
+
+ private void foo6() { }
+
+ private void foo12() {
+ try { int i = 5; int b = 10; }
+ catch (Exception e) { }
+ }
+
+ private void foo13() {
+ for (int i = 0; i < 10; i++) { int a = 5; int b = 6; }
+
+ do
+ {
+ var1 = 2;
+ }
+ while (var2 == 2);
+ }
+
+ static { int a; int b; }
+
+ { int c; int d;}
+
+ private void foo14() {
+ if (var1 > 0) {
+ return;
+ }
+ }
+
+ private void foo15() {
+ class A { int a; } var1++; //violation
+ class B { }
+ if(true) {
+
+ }
+ else;
+ }
+
+ private void foo16() {
+ if (true) { return; } else { } //violation
+ if (false) {
+ }
+ }
+
+ private void foo17() { int var1 = 5; var2 = 6; } private void foo18() {int var1 = 5; var2 = 6; } //violation
+
+ private void foo19() {int var1 = 5;
+ var2 = 6;} //violation
+
+ private String foo20() {
+ do { var2 ++; }
+ while (var2 < 15);
+
+ while (var1 < 10) { var1++; }
+
+ do { var2++; var1++; } while (var2 < 15); return ""+0xCAFEBABE; //violation
+ }
+
+ private void foo21() {
+ new Object() { @Override protected void finalize() { "".toString(); }};
+ }
+
+ void foo22() {
+ long startTime = System.nanoTime();
+ try {
+ int a = 5;
+ toString();
+ } catch (Exception e) { //violation
+ throw new RuntimeException(e);
+ } finally { toString(); } //violation
+ }
+
+ void doDoubleBraceInitialization() {
+ java.util.Map<String, String> map = new java.util.LinkedHashMap<String, String>() {{
+ put("Hello", "World");
+ put("first", "second");
+ put("polygene", "lubricants");
+ put("alpha", "betical");
+ }}; // it's ok
+
+ Thread t = new Thread() {@Override public void run() {super.run();}};
+ new Object() { @Override protected void finalize() { "".toString(); } { int a = 5; }};
+ new Object() { @Override protected void finalize() { "".toString(); } int b = 10; };
+ new Object() { @Override protected void finalize() { "".toString(); } { int c = 5; } int d = 8; };
+
+ java.util.Map<String, String> map2 = new java.util.LinkedHashMap<String, String>() {{
+ put("Hello", "World");
+ put("first", "second");
+ put("polygene", "lubricants");
+ put("alpha", "betical");} //violation
+ };
+
+ java.util.Map<String, String> map3 = new java.util.LinkedHashMap<String, String>() {{
+ put("Hello", "World");
+ put("first", "second");
+ put("polygene", "lubricants");
+ put("alpha", "betical");}}; //violation
+
+ java.util.Map<String, String> map4 = new java.util.LinkedHashMap<String, String>() {{
+ put("Hello", "World");
+ put("first", "second");
+ put("polygene", "lubricants");
+ put("alpha", "betical");
+ }
+ };
+
+ foo23(new java.util.HashSet<String>() {{
+ add("XZ13s");
+ add("AB21/X");
+ add("YYLEX");
+ add("AR5E");
+ }}); //it's ok, can't be formatted better
+
+ foo23(new java.util.HashSet<String>() {{
+ add("XZ13s");
+ add("AB21/X");
+ add("YYLEX");
+ add("AR5E");
+ }});} //violation
+
+
+ void foo23(java.util.HashSet<String> set) {
+ }
+
+ void foo25() {
+ for (int i = 0; i < 10; i++) {
+ System.out.println("Hello, world!");
+ }} //violation
+
+ void foo26() {
+ for (int i = 0; i < 10; i++) {
+ System.out.println("Hello, world!");}} //violation
+
+ void foo27() {
+ for (int i = 0; i < 10; i++) {for (int j = 0; j < 15; j++) {int a;}}} //violation
+
+ private java.util.ArrayList<Integer> foo28(int delta) {
+ return new java.util.ArrayList<Integer>() {
+ @Override public int size() { return Math.max(0, super.size() + 1);};
+ };
+ }
+
+ private void foo29() {
+ boolean flag = true;
+ if (flag) {
+ System.out.println("heh");
+ flag = !flag; } System.err. //violation
+ println("Xe-xe");
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAnnotations.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAnnotations.java
new file mode 100644
index 000000000..7802a0274
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyAnnotations.java
@@ -0,0 +1,219 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+class InputRightCurlyAnnotations
+{
+
+ @Deprecated
+ @Override
+ public boolean equals(Object other) { boolean flag = true; return flag; } //violation
+
+ @Override
+ public String toString() { String s = "toString"; return s; } //violation
+
+ @Override
+ @SuppressWarnings("unused")
+ public int hashCode()
+ {
+ int a = 10;
+ return 1;
+ }
+
+ @SuppressWarnings("unused")
+ private void foo2() { int a = 9; return; } //violation
+
+ @SuppressWarnings("unused")
+ private void foo3()
+ { int var1 = 5; var2 = 6; } //violation
+
+ @Deprecated
+ private void foo4() { return; } //violation
+
+ @SuppressWarnings("unused")
+ private int foo5() { return 1; } //violation
+
+ @SuppressWarnings("unused")
+ private String foo6() { return toString();
+ }
+
+ private String foo7() { String s = toString(); return s.toString(); } //violation
+
+ private void foo8() { ; return; } //violation
+
+ private int var1;
+ private int var2;
+ @SuppressWarnings("unused")
+ public InputRightCurlyAnnotations() { this.var1 = 1; } //violation
+ @SuppressWarnings("unused")
+ public InputRightCurlyAnnotations(int var1, int var2) { this.var1 = var1; this.var2 = var2; } //violation
+
+ @SuppressWarnings("unused")
+ private void foo9() { ;; } //violation
+
+ @SuppressWarnings("unused")
+ private void foo10() { ; } //violation
+
+ @SuppressWarnings("unused")
+ private void foo11() { } //it's ok - empty block
+
+ @SuppressWarnings("unused")
+ private void foo12() {
+ try { int i = 5; int b = 10; } //violation
+ catch (Exception e) { } //it's ok - empty block
+ }
+
+ @Deprecated
+ @SuppressWarnings("unused")
+ private void foo13() {
+ for (int i = 0; i < 10; i++) { int a = 5; int b = 6; } //violation
+
+ do
+ {
+ var1 = 2;
+ }
+ while (var2 == 2);
+ }
+
+ static { int a; int b; } //violation
+
+ static { int a; } //violation
+
+ { int c; int d;} //violation
+
+ { int c; } //violation
+
+ @Deprecated
+ private void foo14() {
+ if (var1 > 0) {
+ return;
+ }
+ }
+
+ @Deprecated
+ private void foo15() {
+ class A { int a; } var1++; //violation
+ class B { }
+ if(true) {
+
+ }
+ else;
+ }
+
+ @Deprecated
+ private void foo16() {
+ if (true) { return; } else { } //violation
+ if (false) {
+ }
+
+ if (true) { return; } else { } //violation
+ }
+
+ @Deprecated
+ private void foo17() { int var1 = 5; var2 = 6; } @Deprecated private void foo18() {int var1 = 5; var2 = 6; } //violation
+
+ private void foo19() {int var1 = 5;
+ var2 = 6;} //violation
+
+ @SuppressWarnings("Hello, world!")
+ private String foo20() {
+ do { var2 ++; } //violation
+ while (var2 < 15);
+
+ while (var1 < 10) { var1++; } //violation
+
+ do { var2++; var1++; } while (var2 < 15); return ""+0xCAFEBABE; //violation
+ }
+
+ private void foo21() {
+ new Object() { @Override protected void finalize() { "".toString(); }}; //violation
+ }
+
+ @SuppressWarnings("All")
+ void foo22() {
+ long startTime = System.nanoTime();
+ try {
+ int a = 5;
+ toString();
+ } catch (Exception e) { //violation
+ throw new RuntimeException(e);
+ } finally { toString(); } //violation
+ }
+
+ @SuppressWarnings("")
+ void doDoubleBraceInitialization() {
+ java.util.Map<String, String> map = new java.util.LinkedHashMap<String, String>() {{
+ put("Hello", "World");
+ put("first", "second");
+ put("polygene", "lubricants");
+ put("alpha", "betical");
+ }}; //violation
+
+ Thread t = new Thread() {@Override public void run() {super.run();}}; //violation
+ new Object() { @Override protected void finalize() { "".toString(); } { int a = 5; }}; //violation
+ new Object() { @Override protected void finalize() { "".toString(); } int b = 10; }; //violation
+ new Object() { @Override protected void finalize() { "".toString(); } { int c = 5; } int d = 8; }; //violation
+
+ java.util.Map<String, String> map2 = new java.util.LinkedHashMap<String, String>() {{
+ put("Hello", "World");
+ put("first", "second");
+ put("polygene", "lubricants");
+ put("alpha", "betical");} //violation
+ };
+
+ java.util.Map<String, String> map3 = new java.util.LinkedHashMap<String, String>() {{
+ put("Hello", "World");
+ put("first", "second");
+ put("polygene", "lubricants");
+ put("alpha", "betical");}}; //violation
+
+ java.util.Map<String, String> map4 = new java.util.LinkedHashMap<String, String>() {{
+ put("Hello", "World");
+ put("first", "second");
+ put("polygene", "lubricants");
+ put("alpha", "betical");
+ }
+ };
+
+ foo23(new java.util.HashSet<String>() {{
+ add("XZ13s");
+ add("AB21/X");
+ add("YYLEX");
+ add("AR5E");
+ }}); //violation
+
+ foo23(new java.util.HashSet<String>() {{
+ add("XZ13s");
+ add("AB21/X");
+ add("YYLEX");
+ add("AR5E");
+ }});} //violation
+
+
+ void foo23(java.util.HashSet<String> set) {
+ }
+
+ void foo25() {
+ for (int i = 0; i < 10; i++) {
+ System.out.println("Hello, world!");
+ }} //violation
+
+ void foo26() {
+ for (int i = 0; i < 10; i++) {
+ System.out.println("Hello, world!");}} //violation
+
+ void foo27() {
+ for (int i = 0; i < 10; i++) {for (int j = 0; j < 15; j++) {int a;}}} //violation
+
+ private java.util.ArrayList<Integer> foo28(int delta) {
+ return new java.util.ArrayList<Integer>() {
+ @Override public int size() { return Math.max(0, super.size() + 1);}; //violation
+ };
+ }
+
+ private void foo29() {
+ boolean flag = true;
+ if (flag) {
+ System.out.println("heh");
+ flag = !flag; } System.err. //violation
+ println("Xe-xe");
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyEmptyAbstractMethod.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyEmptyAbstractMethod.java
new file mode 100644
index 000000000..c142bd0fb
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyEmptyAbstractMethod.java
@@ -0,0 +1,9 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+abstract class CharSequenceReader{
+
+ abstract void moveTo(double deltaX, double deltaY);
+
+ void foo() {
+ while (true);
+ }
+} \ No newline at end of file
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyLineBreakBefore.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyLineBreakBefore.java
new file mode 100644
index 000000000..15e953162
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyLineBreakBefore.java
@@ -0,0 +1,68 @@
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
+import java.util.List;
+
+class InputRightCurlyLineBreakBefore
+{
+ /** @see test method **/
+ int foo() throws InterruptedException
+ {
+ int x = 1;
+ int a = 2;
+ while (true)
+ {
+ try
+ {
+ if (x > 0)
+ {
+ break;
+ } else if (x < 0) {
+ ;
+ } else { break; }
+ switch (a)
+ {
+ case 0:
+ break;
+ default:
+ break;
+ }
+ } catch (Exception e) { break; } finally { break; }
+ }
+
+ synchronized (this) { do { x = 2; } while (x == 2); }
+
+ synchronized (this) {
+ do {} while (x == 2);
+ }
+
+ for (int k = 0; k < 1; k++) { String innerBlockVariable = ""; }
+
+ for (int k = 0; k < 1; k++) {}
+ return a;
+ }
+
+ static { int x = 1; }
+
+ void method2()
+ {
+ boolean flag = false;
+ if (flag) { System.err.println("foo"); }
+ }
+}
+
+class Absent_CustomFieldSerializer {
+
+ public static void serialize() {}
+}
+
+class Absent_CustomFieldSerializer10
+{
+ public Absent_CustomFieldSerializer10() {}
+}
+
+class EmptyClass {}
+
+interface EmptyInterface {} \ No newline at end of file
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyNameForOneLiners.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyNameForOneLiners.java
new file mode 100644
index 000000000..6f7ecc23f
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputRightCurlyNameForOneLiners.java
@@ -0,0 +1,18 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2015
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+/**
+ * Test case for RightCurly with option SAME to omit oneliners
+ * @see https://github.com/checkstyle/checkstyle/issues/1416
+ * @author <a href="mailto:piotr.listkiewicz@gmail.com">liscju</a>
+ */
+public class InputRightCurlyNameForOneLiners {
+ public static void main(String[] args) {
+ boolean after = false;
+ try {
+ } finally { after = true; }
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces.java
new file mode 100644
index 000000000..ecabce5da
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces.java
@@ -0,0 +1,52 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2001
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+public class InputScopeInnerInterfaces
+{
+ private interface PrivateInterface
+ {
+ }
+
+ interface PackageInnerInterface
+ {
+ }
+
+ protected interface ProtectedInnerInterface
+ {
+ }
+
+ public interface PublicInnerInterface
+ {
+ }
+
+ private
+ class
+ MyClass1 {
+ }
+
+ class
+ MyClass2 {
+ }
+
+ private
+ interface
+ MyInterface1 {
+ }
+
+ interface
+ MyInterface2 {
+ }
+
+ protected
+ enum
+ MyEnum {
+ }
+
+ private
+ @interface
+ MyAnnotation {
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces2.java
new file mode 100644
index 000000000..2540fc540
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputScopeInnerInterfaces2.java
@@ -0,0 +1,74 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2001
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+public class InputScopeInnerInterfaces2{
+ // inner interfaces with different scopes
+
+
+ private interface PrivateInterface
+ {
+ public String CA = "CONST A";
+ String CB = "CONST b";
+
+ public void ma();
+ void mb();
+ }
+
+ interface PackageInnerInterface
+ {
+ public String CA = "CONST A";
+ String CB = "CONST b";
+
+ public void ma();
+ void mb();
+ }
+
+ protected interface ProtectedInnerInterface
+ {
+ public String CA = "CONST A";
+ String CB = "CONST b";
+
+ public void ma();
+ void mb();
+ }
+
+ public interface PublicInnerInterface
+ {
+ public String CA = "CONST A";
+ String CB = "CONST b";
+
+ public void ma();
+ void mb();
+ }
+
+ private
+ class
+ MyClass1
+ {
+ }
+ class
+ MyClass2 {
+ }
+
+ private
+ interface
+ MyInterface1 {
+ }
+
+ interface
+ MyInterface2 {
+ }
+
+ protected
+ enum
+ MyEnum {
+ }
+
+ private
+ @interface
+ MyAnnotation {
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic.java
new file mode 100644
index 000000000..94cda5d53
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic.java
@@ -0,0 +1,87 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2001
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+import java.io.*; // star import for instantiation tests
+import java.awt.Dimension; // explicit import for instantiation tests
+import java.awt.Color;
+
+/**
+ * Test case for detecting empty block statements.
+ * @author Lars Kühne
+ **/
+class InputSemantic
+{
+ static {
+ Boolean x = new Boolean(true);
+ }
+
+ {
+ Boolean x = new Boolean(true);
+ Boolean[] y = new Boolean[]{Boolean.TRUE, Boolean.FALSE};
+ }
+
+ Boolean getBoolean()
+ {
+ return new java.lang.Boolean(true);
+ }
+
+ void exHandlerTest()
+ {
+ try {
+ }
+ finally {
+ }
+ try {
+ // something
+ }
+ finally {
+ // something
+ }
+ try {
+ ; // something
+ }
+ finally {
+ ; // statement
+ }
+ }
+
+ /** test **/
+ private static final long IGNORE = 666l + 666L;
+
+ public class EqualsVsHashCode1
+ {
+ public boolean equals(int a)
+ {
+ return a == 1;
+ }
+ }
+
+ // empty instance initializer
+ {
+ }
+
+ private class InputBraces {
+
+ }
+
+ synchronized void foo() {
+ synchronized (this) {} // not OK
+ synchronized (Class.class) { // OK
+ synchronized (new Object()) {
+ // not OK if checking statements
+ }
+ }
+ }
+
+
+ static {
+
+ int a = 0;}
+
+ static {
+
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic2.java
new file mode 100644
index 000000000..a85c38998
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/InputSemantic2.java
@@ -0,0 +1,38 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2001
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks.blocks;
+
+import java.io.*; // star import for instantiation tests
+import java.awt.Dimension; // explicit import for instantiation tests
+import java.awt.Color;
+
+class UpdateClass
+{
+ public void fooMethod()
+ {
+ int a = 1;
+ if (a == 1) {} //is not OK
+ char[] s = {'1', '2'};
+ int index = 2;
+ if (doSideEffect() == 1) {} //is not OK,
+ while ((a = index - 1) != 0) {} // is OK
+ for (; index < s.length && s[index] != 'x'; index++) {} // is OK
+ if (a == 1) {} else {System.out.println("a");} // is not OK
+ switch (a) {} //warn
+ switch (a) { //ok
+ case 1:
+ a = 2;
+ case 2:
+ a = 3;
+ default:
+ a = 0;
+ }
+ }
+
+ public int doSideEffect()
+ {
+ return 1;
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchOnly.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchOnly.java
new file mode 100644
index 000000000..ac1a01a11
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputCatchOnly.java
@@ -0,0 +1,34 @@
+package com.puppycrawl.tools.checkstyle.checks.naming;
+
+/**
+ * Test case for skipping over catch names.
+ **/
+public class InputCatchOnly {
+ int foo() {
+ if (System.currentTimeMillis() > 1000)
+ return 1;
+
+ int test = 0;
+
+ try
+ {
+ return 1;
+ }
+ catch (Exception e)
+ {
+ return 0;
+ }
+ }
+
+ public InputCatchOnly()
+ {
+ return;
+ }
+
+ class InnerFoo
+ {
+ public void fooInnerMethod ()
+ {
+ }
+ }
+}