aboutsummaryrefslogtreecommitdiff
path: root/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding')
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/declarationorder/InputDeclarationOrder.java7
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/defaultcomeslast/InputDefaultComesLastSkipIfLastAndSharedWithCase.java (renamed from src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/defaultcomeslast/InputSkipIfLastAndSharedWithCase.java)2
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/equalsavoidnull/InputEqualsAvoidNullNested.java27
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/equalsavoidnull/InputEqualsAvoidNullOnTheSameLine.java9
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/explicitinitialization/InputExplicitInitialization.java1
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/fallthrough/InputFallThrough.java26
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/finallocalvariable/InputFinalLocalVariableAnonymousClass.java14
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSameFileName.java3
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSimilarClassName.java8
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableEnhancedForLoopVariable2.java18
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplestringliterals/InputMultipleStringLiteralsNoWarnings.java5
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/overloadmethodsdeclarationorder/InputOverloadMethodsDeclarationOrder.java (renamed from src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/overloadmethoddeclaration/InputOverloadMethodsDeclarationOrder.java)2
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisCaseGroup.java48
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisExtendedMethod.java10
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/superclone/InputSuperCloneWithoutWarnings.java8
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesLambdas.java79
16 files changed, 265 insertions, 2 deletions
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/declarationorder/InputDeclarationOrder.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/declarationorder/InputDeclarationOrder.java
index 7ddbb89fe..9c0303b80 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/declarationorder/InputDeclarationOrder.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/declarationorder/InputDeclarationOrder.java
@@ -40,6 +40,13 @@ public class InputDeclarationOrder
foo += INNER_FOO3;
}
+ public InnerClass(int start)
+ {
+ int foo = start;
+ foo += INNER_FOO2;
+ foo += INNER_FOO3;
+ }
+
// error member variables should be before methods or ctors
// error public before private
public static final int INNER_FOO3 = 2;
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/defaultcomeslast/InputSkipIfLastAndSharedWithCase.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/defaultcomeslast/InputDefaultComesLastSkipIfLastAndSharedWithCase.java
index aa9435b6e..ccfed68af 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/defaultcomeslast/InputSkipIfLastAndSharedWithCase.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/defaultcomeslast/InputDefaultComesLastSkipIfLastAndSharedWithCase.java
@@ -1,7 +1,7 @@
package com.puppycrawl.tools.checkstyle.checks.coding.defaultcomeslast;
-public class InputSkipIfLastAndSharedWithCase
+public class InputDefaultComesLastSkipIfLastAndSharedWithCase
{
void method(int i) {
switch (i) {
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/equalsavoidnull/InputEqualsAvoidNullNested.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/equalsavoidnull/InputEqualsAvoidNullNested.java
new file mode 100644
index 000000000..2a1a320da
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/equalsavoidnull/InputEqualsAvoidNullNested.java
@@ -0,0 +1,27 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.equalsavoidnull;
+
+import java.io.IOException;
+import java.io.Reader;
+
+public class InputEqualsAvoidNullNested {
+ public void foo(Reader in) throws IOException {
+ int c;
+ while(true) {
+ c = in.read();
+ if (c == -1)
+ break;
+
+ if (c == '<') {
+ c = in.read();
+ if (c == '/') {
+ String nm = in.toString();
+ if (nm.equalsIgnoreCase("applet") ||
+ nm.equalsIgnoreCase("object") ||
+ nm.equalsIgnoreCase("embed")) {
+ break;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/equalsavoidnull/InputEqualsAvoidNullOnTheSameLine.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/equalsavoidnull/InputEqualsAvoidNullOnTheSameLine.java
new file mode 100644
index 000000000..dc4783bbb
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/equalsavoidnull/InputEqualsAvoidNullOnTheSameLine.java
@@ -0,0 +1,9 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.equalsavoidnull;
+
+public class InputEqualsAvoidNullOnTheSameLine {
+
+ static {
+ String b = "onion";
+ String a=b;a.equals("ONION");
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/explicitinitialization/InputExplicitInitialization.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/explicitinitialization/InputExplicitInitialization.java
index d63024d50..111d19f49 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/explicitinitialization/InputExplicitInitialization.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/explicitinitialization/InputExplicitInitialization.java
@@ -79,4 +79,5 @@ class Chars {
char b = a;
byte c = 1;
short d = 1;
+ final long e = 0;
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/fallthrough/InputFallThrough.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/fallthrough/InputFallThrough.java
index 4486bbd03..a3c745e55 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/fallthrough/InputFallThrough.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/fallthrough/InputFallThrough.java
@@ -521,4 +521,30 @@ public class InputFallThrough
public void close() throws Exception {
}
}
+
+ void synchronizedStatement() {
+ switch (hashCode()) {
+ case 1:
+ synchronized (this) {
+ break;
+ }
+ case 2:
+ // synchronized nested in if
+ if (true) {
+ synchronized (this) {
+ break;
+ }
+ } else {
+ synchronized (this) {
+ break;
+ }
+ }
+ case 3:
+ synchronized (this) {
+ }
+ // fallthru
+ default:
+ break;
+ }
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/finallocalvariable/InputFinalLocalVariableAnonymousClass.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/finallocalvariable/InputFinalLocalVariableAnonymousClass.java
new file mode 100644
index 000000000..67177632e
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/finallocalvariable/InputFinalLocalVariableAnonymousClass.java
@@ -0,0 +1,14 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.finallocalvariable;
+
+public class InputFinalLocalVariableAnonymousClass {
+ public void test() {
+ Object testSupport = new Object() {
+ @Override
+ public String toString() {
+ final String dc = new String();
+ return dc;
+ }
+ };
+ testSupport.toString();
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSameFileName.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSameFileName.java
index b39ece624..8735f5392 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSameFileName.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSameFileName.java
@@ -26,4 +26,7 @@ public class InputIllegalTypeSameFileName
}
java.util.List<Integer> list = new ArrayList<>(); //WARNING
private ArrayList<String> values;
+ private Boolean d; //WARNING
+ private Boolean[] d1; //WARNING
+ private Boolean[][] d2; //WARNING
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSimilarClassName.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSimilarClassName.java
new file mode 100644
index 000000000..704a9e92f
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSimilarClassName.java
@@ -0,0 +1,8 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.illegaltype;
+
+public class InputIllegalTypeSimilarClassName {
+ private TreeSet example;
+
+ private static class TreeSet {
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableEnhancedForLoopVariable2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableEnhancedForLoopVariable2.java
new file mode 100644
index 000000000..9c4685397
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableEnhancedForLoopVariable2.java
@@ -0,0 +1,18 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.modifiedcontrolvariable;
+
+public class InputModifiedControlVariableEnhancedForLoopVariable2 {
+ void m(int[] a) {
+ for (int i = 0, j = 1; ; i++, j++) {
+ for (int k : a) {
+ }
+ }
+ }
+
+ void m2(int[] a) {
+ for (int i = 0, j = 1; ; i++, j++) {
+ for (int k : a) {
+ i++;
+ }
+ }
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplestringliterals/InputMultipleStringLiteralsNoWarnings.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplestringliterals/InputMultipleStringLiteralsNoWarnings.java
new file mode 100644
index 000000000..f33d30bb4
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplestringliterals/InputMultipleStringLiteralsNoWarnings.java
@@ -0,0 +1,5 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.multiplestringliterals;
+
+public class InputMultipleStringLiteralsNoWarnings {
+ private final String m4 = "" + "";
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/overloadmethoddeclaration/InputOverloadMethodsDeclarationOrder.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/overloadmethodsdeclarationorder/InputOverloadMethodsDeclarationOrder.java
index b56dd4fcc..2aa3520db 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/overloadmethoddeclaration/InputOverloadMethodsDeclarationOrder.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/overloadmethodsdeclarationorder/InputOverloadMethodsDeclarationOrder.java
@@ -1,4 +1,4 @@
-package com.puppycrawl.tools.checkstyle.checks.coding.overloadmethoddeclaration;
+package com.puppycrawl.tools.checkstyle.checks.coding.overloadmethodsdeclarationorder;
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisCaseGroup.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisCaseGroup.java
new file mode 100644
index 000000000..b32b99c58
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisCaseGroup.java
@@ -0,0 +1,48 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
+
+public class InputRequireThisCaseGroup {
+ private String aVariable;
+
+ public String method1(int val) {
+ switch (val) {
+ case 0:
+ String aVariable = "";
+
+ if (this.aVariable != null) {
+ aVariable = this.aVariable;
+ }
+
+ return aVariable;
+ default:
+ return null;
+ }
+ }
+
+ public String method2(int val) {
+ switch (val) {
+ case 0:
+ String aVariable = "";
+
+ if (this.aVariable != null) {
+ aVariable = this.aVariable;
+ }
+
+ return aVariable;
+ }
+ return null;
+ }
+
+ public String method3(int val) {
+ switch (val) {
+ case 0:
+ String other = "";
+
+ if (aVariable != null) {
+ other = aVariable;
+ }
+
+ return other;
+ }
+ return null;
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisExtendedMethod.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisExtendedMethod.java
new file mode 100644
index 000000000..c7202c645
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisExtendedMethod.java
@@ -0,0 +1,10 @@
+package com.github.sevntu.checkstyle.checks.coding;
+
+import java.util.logging.Logger;
+
+public class InputRequireThisExtendedMethod
+{
+ public class Check {
+ private Logger log1 = Logger.getLogger(getClass().getName());
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/superclone/InputSuperCloneWithoutWarnings.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/superclone/InputSuperCloneWithoutWarnings.java
new file mode 100644
index 000000000..afc0740c3
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/superclone/InputSuperCloneWithoutWarnings.java
@@ -0,0 +1,8 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.superclone;
+
+public class InputSuperCloneWithoutWarnings {
+ @Override
+ protected final Object clone() throws CloneNotSupportedException {
+ return new InputSuperCloneWithoutWarnings();
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesLambdas.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesLambdas.java
new file mode 100644
index 000000000..2d901fae5
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesLambdas.java
@@ -0,0 +1,79 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.unnecessaryparentheses;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.function.Function;
+
+public class InputUnnecessaryParenthesesLambdas {
+ int foo(int y) {
+ MathOperation case1 = (x) -> x + x;
+ MathOperation case2 = (x) -> { return x + x; };
+ MathOperation case3 = (int x) -> x + x;
+ MathOperation case4 = x -> x + x;
+ MathOperation2 case5 = (a, b) -> a + b;
+ MathOperation2 case6 = (int a, int b) -> a + b;
+ MathOperation2 case7 = (int a, int b) -> { return a + b; };
+ Objects.requireNonNull(null, () -> "message");
+ call((x) -> x + x);
+ new HashSet<Integer>().stream().filter((filter) -> filter > 0);
+ return y;
+ }
+
+ static <T> CheckedFunction1<T, T> identitity() {
+ return t -> t;
+ }
+
+ public interface CheckedFunction2<T1, T2, R> extends Lambda<R> {
+ R apply(T1 t1, T2 t2) throws Throwable;
+
+ default CheckedFunction1<T2, R> apply(T1 t1) {
+ return (T2 t2) -> apply(t1, t2);
+ }
+ @Override
+ default Function1<T1, CheckedFunction1<T2, R>> curried() {
+ return t1 -> t2 -> apply(t1, t2);
+ }
+ default Function1<T1, CheckedFunction1<T2, R>> curried2() {
+ return (t1) -> (t2) -> apply(t1, t2);
+ }
+ default Function1<T1, CheckedFunction1<T2, R>> curried3() {
+ return (t1) -> t2 -> apply(t1, t2);
+ }
+ default Function1<T1, CheckedFunction1<T2, R>> curried4() {
+ return t1 -> (t2) -> apply(t1, t2);
+ }
+ }
+
+ private void call(MathOperation o) {
+ o.operation(1);
+ }
+
+ interface MathOperation {
+ int operation(int a);
+ }
+
+ interface MathOperation2 {
+ int operation(int a, int b);
+ }
+
+ interface Lambda<R> extends Serializable {
+ Lambda<?> curried();
+ }
+
+ public interface Function1<T1, R> extends Lambda<R>, Function<T1, R> {
+ @Override
+ default Function1<T1, R> curried() {
+ return this;
+ }
+ }
+
+ public interface CheckedFunction1<T1, R> extends Lambda<R> {
+ R apply(T1 t1) throws Throwable;
+
+ @Override
+ default CheckedFunction1<T1, R> curried() {
+ return this;
+ }
+ }
+}