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#3423: Allow local vars without any unnecessary viola…
…tions from RequireThisCheck. Added UT. Fixed related UT
- Loading branch information
Showing
5 changed files
with
95 additions
and
26 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
49 changes: 49 additions & 0 deletions
49
src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/InputAllowLocalVars.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,49 @@ | ||
/* | ||
Input test file for RequireThisCheck. | ||
Created: 2017 | ||
*/ | ||
|
||
package com.puppycrawl.tools.checkstyle.checks.coding; | ||
|
||
class InputAllowLocalVars { | ||
|
||
private String s1 = "foo1"; | ||
String s2 = "foo2"; | ||
|
||
InputAllowLocalVars() { | ||
s1 = "bar1"; // Violation. Requires "this". | ||
String s2; | ||
s2 = "bar2"; // No violation. Local var allowed. | ||
} | ||
|
||
public int getS1() { | ||
String s1 = null; | ||
s1 = "bar"; // No violation | ||
s1 = s1; // Violation. "this" required here to resolve any confusion due to overlapping. | ||
return 1; | ||
} | ||
|
||
public String getS1(String param) { | ||
String s1 = null; | ||
s1 = param; // No violation | ||
s1 += s1; // No violation. s1 is being returned. | ||
return s1; // No violation | ||
} | ||
|
||
String getS2() { | ||
String s2 = null; | ||
s2+=s2; // Violation. "this" required here to resolve any confusion due to overlapping. | ||
return "return"; | ||
} | ||
|
||
String getS2(String s2) { | ||
s2 = null; // Violation. Requires "this". s2 is a param not a local var. | ||
return s2; // No violation. param is returned. | ||
} | ||
|
||
String getS2(int a) { | ||
String s2 = " "; | ||
s2 += s2; // Violation. "this" required here to resolve any confusion due to overlapping. | ||
return s1; // Violation. Requires "this". | ||
} | ||
} |
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