forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#14092: fix UnusedLocalVariableCheck to support local…
… classes
- Loading branch information
Showing
6 changed files
with
192 additions
and
5 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
25 changes: 25 additions & 0 deletions
25
...pycrawl/tools/checkstyle/checks/coding/unusedlocalvariable/InputUnusedLocalVariable3.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,25 @@ | ||
/* | ||
UnusedLocalVariable | ||
*/ | ||
|
||
package com.puppycrawl.tools.checkstyle.checks.coding.unusedlocalvariable; | ||
|
||
public class InputUnusedLocalVariable3 { | ||
class Parent { | ||
protected int a = 0; | ||
public Parent(Child d) { | ||
a = 1; | ||
} | ||
} | ||
|
||
class Child extends InputUnusedLocalVariable3.Parent { | ||
protected int b = 0; | ||
public Child(Child d) { | ||
InputUnusedLocalVariable3.this.super(d); | ||
int a = 0; // violation, unused variable 'a' | ||
System.out.println(super.a); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../checkstyle/checks/coding/unusedlocalvariable/InputUnusedLocalVariableNestedClasses4.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,23 @@ | ||
/* | ||
UnusedLocalVariable | ||
*/ | ||
package com.puppycrawl.tools.checkstyle.checks.coding.unusedlocalvariable; | ||
|
||
public class InputUnusedLocalVariableNestedClasses4 { | ||
int a = 12; | ||
|
||
void foo() { | ||
int a = 12; // violation, unused variable 'a' | ||
int ab = 12; // violation, unused variable 'ab' | ||
|
||
class asd { | ||
Test a = new Test() { | ||
void asd() { | ||
System.out.println(a); | ||
} | ||
}; | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../checkstyle/checks/coding/unusedlocalvariable/InputUnusedLocalVariableNestedClasses5.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,47 @@ | ||
/* | ||
UnusedLocalVariable | ||
*/ | ||
package com.puppycrawl.tools.checkstyle.checks.coding.unusedlocalvariable; | ||
|
||
public class InputUnusedLocalVariableNestedClasses5 { | ||
int a = 12; | ||
|
||
void foo() { | ||
int a = 12; // violation, unused variable 'a' | ||
int ab = 12; // violation, unused variable 'ab' | ||
|
||
class abc { | ||
Test a = new Test() { | ||
void abc() { | ||
System.out.println(a); | ||
int abc = 10; // violation, unused variable 'abc' | ||
|
||
class def { | ||
Test abc = new Test() { | ||
void def() { | ||
System.out.println(abc); | ||
} | ||
}; | ||
} | ||
} | ||
}; | ||
|
||
Test ab = new Test() { | ||
void abc() { | ||
System.out.println(ab); | ||
int abc = 10; // violation, unused variable 'abc' | ||
|
||
class def { | ||
Test abc = new Test() { | ||
void def() { | ||
System.out.println(abc); | ||
} | ||
}; | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.../checkstyle/checks/coding/unusedlocalvariable/InputUnusedLocalVariableNestedClasses6.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,36 @@ | ||
/* | ||
UnusedLocalVariable | ||
*/ | ||
package com.puppycrawl.tools.checkstyle.checks.coding.unusedlocalvariable; | ||
|
||
public class InputUnusedLocalVariableNestedClasses6 { | ||
void foo() { | ||
int a = 12; // violation, unused variable 'a' | ||
int ab = 12; // violation, unused variable 'ab' | ||
|
||
class Ghi { | ||
void foo() { | ||
int a = 12; | ||
int ab = 12; // violation, unused variable 'ab' | ||
System.out.println(a); | ||
} | ||
} | ||
|
||
class Def { | ||
void foo() { | ||
int a = 12; // violation, unused variable 'a' | ||
int ab = 12; // violation, unused variable 'ab' | ||
|
||
class InnerDef { | ||
void foo() { | ||
int a = 12; // violation, unused variable 'a' | ||
int ab = 12; | ||
System.out.println(ab); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |