forked from checkstyle/checkstyle
/
InputRequireThisRecordsWithCheckFields.java
48 lines (39 loc) · 1.21 KB
/
InputRequireThisRecordsWithCheckFields.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 String 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 String a() {
return a; // ok
}
}