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/fallthrough/InputFallThrough.java13
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalType.java2
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableBothForLoops.java10
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations/InputMultipleVariableDeclarations.java4
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/nestedfordepth/InputNestedForDepth.java3
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/onestatementperline/InputOneStatementPerLineSingleLine.java7
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/parameterassignment/InputParameterAssignmentWithUnchecked.java13
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnnotationInterface.java9
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisCatchVariables.java40
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumConstant.java13
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs.java40
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFor.java23
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisMethodReferences.java (renamed from src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisMetodReferences.java)6
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/returncount/InputReturnCountVoid.java8
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesOperatorsAndCasts.java8
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistance.java11
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceAnonymous.java22
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceLabels.java22
18 files changed, 251 insertions, 3 deletions
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 a3c745e55..384499fb3 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
@@ -547,4 +547,17 @@ public class InputFallThrough
break;
}
}
+
+ void multipleCasesOnOneLine() {
+ int i = 0;
+ switch (i) {
+ case 0: case 1: i *= i; // fall through
+ case 2: case 3: i *= i; // fall through
+ case 4: case 5: i *= i; // fall through
+ case 6: case 7: i *= i;
+ break;
+ default:
+ throw new RuntimeException();
+ }
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalType.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalType.java
index dfce5fddc..2efc892ca 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalType.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalType.java
@@ -21,4 +21,6 @@ public class InputIllegalType {
InputIllegalType(Integer i) {}
private void table2(Integer i) {}
+
+ private void getInitialContext(java.util.TreeSet v) {} // ignore method by default
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableBothForLoops.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableBothForLoops.java
index d3f57c7be..01c24149c 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableBothForLoops.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableBothForLoops.java
@@ -70,6 +70,13 @@ class InputModifiedControlVariableBothForLoops
for (int i = 0,j = 0 ; i <10; i++) {
j++;
}
+
+ for (String v : sa) {
+ new NestedClass() {
+ public void method() {}
+ };
+ v = "bad";
+ }
}
private int i;
}
@@ -83,3 +90,6 @@ class VariableDeclaredBeforeTheFirstBlockBegins {
}
}
}
+abstract class NestedClass {
+ public abstract void method();
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations/InputMultipleVariableDeclarations.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations/InputMultipleVariableDeclarations.java
index 16487fb9c..d178fbfa0 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations/InputMultipleVariableDeclarations.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations/InputMultipleVariableDeclarations.java
@@ -30,4 +30,8 @@ public class InputMultipleVariableDeclarations
int k = 7;
}
}
+
+ void method3() {
+ java.lang.Object obj; Object obj1; Object obj2; Object obj3;
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/nestedfordepth/InputNestedForDepth.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/nestedfordepth/InputNestedForDepth.java
index dfa0eb6c2..cfa8356e7 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/nestedfordepth/InputNestedForDepth.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/nestedfordepth/InputNestedForDepth.java
@@ -44,6 +44,9 @@ public class InputNestedForDepth {
for (i5 = 0; i5 < 10; i5++) {
i += 1;
}
+ for (int i5a = 0; i5a < 10; i5a++) {
+ i += 1;
+ }
}
}
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/onestatementperline/InputOneStatementPerLineSingleLine.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/onestatementperline/InputOneStatementPerLineSingleLine.java
index 185b7b74f..4a20cb731 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/onestatementperline/InputOneStatementPerLineSingleLine.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/onestatementperline/InputOneStatementPerLineSingleLine.java
@@ -238,4 +238,11 @@ public class InputOneStatementPerLineSingleLine {
*/
for (;;) { one = 5; }
}
+
+ public void foo6() {
+ bar(() -> {
+ return;}, () -> {return;});
+ }
+
+ void bar(Runnable r1, Runnable r2) { }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/parameterassignment/InputParameterAssignmentWithUnchecked.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/parameterassignment/InputParameterAssignmentWithUnchecked.java
index 60f8eed0b..fbfc6e786 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/parameterassignment/InputParameterAssignmentWithUnchecked.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/parameterassignment/InputParameterAssignmentWithUnchecked.java
@@ -19,4 +19,17 @@ public class InputParameterAssignmentWithUnchecked {
void foo3(String field, int field1) {
this.field = (field1 += field.length());
}
+
+ void foo4() {
+ String hidden = "";
+ new NestedClass() {
+ public void test(String hidden) {
+ }
+ };
+ hidden += "test";
+ }
+
+ public static abstract class NestedClass {
+ public abstract void test(String hidden);
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnnotationInterface.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnnotationInterface.java
new file mode 100644
index 000000000..b7b35495c
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnnotationInterface.java
@@ -0,0 +1,9 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
+
+public @interface InputRequireThisAnnotationInterface {
+ String DEFAULT_VALUE = "DEFAULT_VALUE";
+
+ String value() default DEFAULT_VALUE;
+
+ String[] results() default {};
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisCatchVariables.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisCatchVariables.java
new file mode 100644
index 000000000..920dd6369
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisCatchVariables.java
@@ -0,0 +1,40 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
+
+public class InputRequireThisCatchVariables extends Thread {
+ private Throwable ex;
+
+ public InputRequireThisCatchVariables(Throwable ex) {
+ this.ex = ex;
+ }
+
+ @Override
+ public void run() {
+ if (this.ex != null) {
+ try {
+ exceptional(this.ex);
+ }
+ catch (RuntimeException ex) {
+ if (ex == this.ex) {
+ debug("Expected exception thrown", ex);
+ }
+ else {
+ ex.printStackTrace();
+ }
+ }
+ catch (Error err) {
+ if (err == this.ex) {
+ debug("Expected exception thrown", err);
+ }
+ else {
+ ex.printStackTrace();
+ }
+ }
+ catch (Throwable ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private static void exceptional(Throwable ex) {}
+ private static void debug(String message, Throwable err) {}
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumConstant.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumConstant.java
new file mode 100644
index 000000000..4cfc3b3de
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumConstant.java
@@ -0,0 +1,13 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
+
+public class InputRequireThisEnumConstant {
+ private final String TEST = "";
+
+ public enum TestEnum {
+ TEST;
+
+ public TestEnum method() {
+ return TEST;
+ }
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs.java
index a0bd74681..77beca3a7 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs.java
@@ -134,3 +134,43 @@ class Issue2539{
foo();
}
}
+class NestedRechange {
+ final String s = "";
+
+ NestedRechange() {
+ String s = "t";
+ s = s.substring(0);
+ }
+
+ private static class NestedStatic {
+ static final String s = "";
+
+ public void method() {
+ s.substring(0);
+ }
+ }
+}
+class NestedFrames {
+ int a = 0;
+ int b = 0;
+
+ public int oneReturnInMethod2() {
+ for (int i = 0; i < 10; i++) {
+ int a = 1;
+ if (a != 2 && true) {
+ if (true | false) {
+ if (a - a != 0) {
+ a += 1;
+ }
+ }
+ }
+ }
+ return a + a * a;
+ }
+
+ public int oneReturnInMethod3() {
+ for (int b = 0; b < 10; b++) {
+ }
+ return b + b * b;
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFor.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFor.java
new file mode 100644
index 000000000..9ad0e9f5c
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFor.java
@@ -0,0 +1,23 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class InputRequireThisFor {
+ private String name;
+ int bottom;
+
+ public void method1() {
+ for (int i = 0; i < 10; i++) {
+ int bottom = i - 4;
+ bottom = bottom > 0 ? bottom - 1 : bottom;
+ }
+ }
+
+ public void method2() {
+ for (String name : new String[]{}) {
+ }
+
+ Path jarfile = Paths.get(name + ".jar");
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisMetodReferences.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisMethodReferences.java
index 516b85aed..b0b528e81 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisMetodReferences.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisMethodReferences.java
@@ -6,16 +6,16 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
-public class InputRequireThisMetodReferences {
+public class InputRequireThisMethodReferences {
private Set<String> tags = Collections.unmodifiableSortedSet(
Arrays.stream(new String[] {"br", "li", "dt", "dd", "hr", "img", "p", "td", "tr", "th",})
.collect(Collectors.toCollection(TreeSet::new)));
- public InputRequireThisMetodReferences(Set<String> tags) {
+ public InputRequireThisMethodReferences(Set<String> tags) {
tags = tags; // violation
}
- public InputRequireThisMetodReferences() {
+ public InputRequireThisMethodReferences() {
this.tags = Arrays.stream(
new String[] {"br", "li", "dt", "dd", "hr", "img", "p", "td", "tr", "th",})
.collect(Collectors.toCollection(TreeSet::new));
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/returncount/InputReturnCountVoid.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/returncount/InputReturnCountVoid.java
index 9a2d48faa..a1beceeae 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/returncount/InputReturnCountVoid.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/returncount/InputReturnCountVoid.java
@@ -37,4 +37,12 @@ class InputReturnCountVoid {
return 0;
}
+
+ void method5() {
+ if (true) {
+ return;
+ }
+
+ return;
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesOperatorsAndCasts.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesOperatorsAndCasts.java
index 777f4b15e..33246c199 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesOperatorsAndCasts.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/unnecessaryparentheses/InputUnnecessaryParenthesesOperatorsAndCasts.java
@@ -87,6 +87,14 @@ public class InputUnnecessaryParenthesesOperatorsAndCasts {
System.identityHashCode("arg = " + arg);
}
+ private int f7() {
+ String f;
+
+ f = ("12345678901234567890123");
+
+ return 0;
+ }
+
static class TypeParameterized<T> {}
static class TypeA extends TypeParameterized<String> {}
static class TypeB extends TypeA {}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistance.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistance.java
index 57ca5e725..330abb819 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistance.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistance.java
@@ -973,5 +973,16 @@ class New {
}
catch(Exception e){}
}
+
+ void m() {
+ final int a = 1;
+ int b = 0;
+
+ if (b == 1) {
+ System.lineSeparator();
+ }
+
+ final int c = a + 1;
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceAnonymous.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceAnonymous.java
new file mode 100644
index 000000000..969aa801f
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceAnonymous.java
@@ -0,0 +1,22 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.variabledeclarationusagedistance;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import javax.swing.JMenuItem;
+
+public class InputVariableDeclarationUsageDistanceAnonymous {
+ public void method() {
+ JMenuItem prefs = new JMenuItem("Preferences...");
+
+ nothing();
+ nothing();
+ nothing();
+ prefs.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ }
+ });
+ }
+
+ public void nothing() {
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceLabels.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceLabels.java
new file mode 100644
index 000000000..e9e0e3ff4
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceLabels.java
@@ -0,0 +1,22 @@
+package com.puppycrawl.tools.checkstyle.checks.coding.variabledeclarationusagedistance;
+
+public class InputVariableDeclarationUsageDistanceLabels {
+ public void method() {
+ boolean eol = false;
+
+ nothing();
+ nothing();
+ nothing();
+ nothing();
+ myLoop:
+ for (int i = 0; i < 5; i++) {
+ if (i == 5) {
+ eol = true;
+ break myLoop;
+ }
+ }
+ }
+
+ public void nothing() {
+ }
+}