forked from checkstyle/checkstyle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#11807: fixes exception on records and fields in Requ…
…ireThis
- Loading branch information
Showing
4 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...wl/tools/checkstyle/checks/coding/requirethis/InputRequireThisRecordsWithCheckFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
RequireThis | ||
checkFields = true | ||
checkMethods = (default)true | ||
validateOnlyOverlapping = (default)true | ||
*/ | ||
|
||
//non-compiled with javac: Compilable with Java14 | ||
package com.puppycrawl.tools.checkstyle.checks.coding.requirethis; | ||
|
||
public record InputRequireThisRecordsWithCheckFields(String a) { | ||
void method() { | ||
String a = "BUG"; | ||
a = a.substring(0, 1); // ok, field 'a' is final and cannot be changed | ||
} | ||
|
||
void method2() { | ||
String x = a; // ok, not overlapping | ||
String y = this.a; // ok, uses 'this' | ||
String a = this.a; // ok, local variable assigned from field | ||
a += a; // ok, local variable | ||
} | ||
} | ||
class InputRequireThisRecordsWithCheckFieldsClass { | ||
public final int a; | ||
|
||
public InputRequireThisRecordsWithCheckFieldsClass(String a) { | ||
this.a = a; | ||
} | ||
|
||
void method() { | ||
String a = "BUG"; | ||
a = a.substring(0, 1); // ok, field 'a' is final and cannot be changed | ||
} | ||
|
||
void method2() { | ||
String x = a; // ok, not overlapping | ||
String y = this.a; // ok, uses 'this' | ||
String a = this.a; // ok, local variable assigned from field | ||
a += a; // ok, local variable | ||
} | ||
|
||
public int a() { | ||
return a; // ok | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...s/checkstyle/checks/coding/requirethis/InputRequireThisRecordsWithCheckFieldsOverlap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
RequireThis | ||
checkFields = true | ||
checkMethods = (default)true | ||
validateOnlyOverlapping = false | ||
*/ | ||
|
||
//non-compiled with javac: Compilable with Java14 | ||
package com.puppycrawl.tools.checkstyle.checks.coding.requirethis; | ||
|
||
public record InputRequireThisRecordsWithCheckFieldsOverlap(String a) { | ||
void method() { | ||
String a = "BUG"; | ||
a = a.substring(0, 1); // ok, field 'a' is final and cannot be changed | ||
} | ||
|
||
void method2() { | ||
String x = a; // violation | ||
String y = this.a; // ok, uses 'this' | ||
String a = this.a; // ok, local variable assigned from field | ||
a += a; // ok, local variable | ||
} | ||
} | ||
class InputRequireThisRecordsWithCheckFieldsClass { | ||
public final int a; | ||
|
||
public InputRequireThisRecordsWithCheckFieldsClass(String a) { | ||
this.a = a; | ||
} | ||
|
||
void method() { | ||
String a = "BUG"; | ||
a = a.substring(0, 1); // ok, field 'a' is final and cannot be changed | ||
} | ||
|
||
void method2() { | ||
String x = a; // violation | ||
String y = this.a; // ok, uses 'this' | ||
String a = this.a; // ok, local variable assigned from field | ||
a += a; // ok, local variable | ||
} | ||
|
||
public int a() { | ||
return a; // violation | ||
} | ||
} |