RequireThisCheck.java
com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck
diff --git a/.ci/pitest-survival-check-html.sh b/.ci/pitest-survival-check-html.sh
index 7322b3c4fcb..e24be8c5b0a 100755
--- a/.ci/pitest-survival-check-html.sh
+++ b/.ci/pitest-survival-check-html.sh
@@ -199,7 +199,6 @@ pitest-coding-2)
pitest-coding-require-this-check)
declare -a ignoredItems=(
"RequireThisCheck.java.html: && ast.getParent().getType() != TokenTypes.LITERAL_CATCH) { | "
- "RequireThisCheck.java.html: if (isAnonymousClassDef(ast)) { | "
"RequireThisCheck.java.html: && parent.getType() != TokenTypes.CTOR_DEF | "
"RequireThisCheck.java.html: && lastChild.getType() == TokenTypes.OBJBLOCK; | "
"RequireThisCheck.java.html: if (definitionToken.getType() == TokenTypes.STATIC_INIT) { | "
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheckTest.java
index 43379a9deb5..630f1f16767 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheckTest.java
@@ -175,9 +175,9 @@ public void testTokensNotNull() {
@Test
public void testWithAnonymousClass() throws Exception {
final String[] expected = {
- "28:25: " + getCheckMessage(MSG_METHOD, "doSideEffect", ""),
- "32:24: " + getCheckMessage(MSG_VARIABLE, "bar", "InputRequireThisAnonymousEmpty."),
- "55:17: " + getCheckMessage(MSG_VARIABLE, "foobar", ""),
+ "29:25: " + getCheckMessage(MSG_METHOD, "doSideEffect", ""),
+ "33:24: " + getCheckMessage(MSG_VARIABLE, "bar", "InputRequireThisAnonymousEmpty."),
+ "56:17: " + getCheckMessage(MSG_VARIABLE, "foobar", ""),
};
verifyWithInlineConfigParser(
getPath("InputRequireThisAnonymousEmpty.java"),
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnonymousEmpty.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnonymousEmpty.java
index 5183f94345e..34565cb452f 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnonymousEmpty.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnonymousEmpty.java
@@ -12,6 +12,7 @@
public class InputRequireThisAnonymousEmpty {
private int bar;
+ int a;
interface AnonWithEmpty {
public void fooEmpty();
@@ -56,4 +57,36 @@ public void fooEmpty() {
}
};
}
+
+ void method2() {
+ int a = 1;
+ InputRequireThisAnonymousEmpty obj =
+ new InputRequireThisAnonymousEmpty() {
+ void method() {
+ a += 1;
+ }
+ };
+ }
+
+ void anotherMethod() {
+ int var1 = 12;
+ int var2 = 13;
+ Foo obj = new Foo() {
+ void method() {
+ var2 += var1;
+ }
+ };
+ obj.getClass();
+ }
+}
+
+class SharkFoo {
+ int var1 = 12;
+}
+
+class Foo {
+ int var2 = 13;
+
+ class SharkFoo {
+ }
}