Issue #1293: Refactoring of ParameterAssignmentCheck

This commit is contained in:
Baratali Izmailov 2015-08-01 03:30:56 -07:00 committed by Roman Ivanov
parent 2c41aaf844
commit 5fa34fa1b2
4 changed files with 28 additions and 3 deletions

View File

@ -1099,7 +1099,6 @@
<regex><pattern>.*.checks.coding.ExplicitInitializationCheck</pattern><branchRate>91</branchRate><lineRate>97</lineRate></regex>
<regex><pattern>.*.checks.coding.FinalLocalVariableCheck</pattern><branchRate>83</branchRate><lineRate>100</lineRate></regex>
<regex><pattern>.*.checks.coding.IllegalInstantiationCheck</pattern><branchRate>81</branchRate><lineRate>97</lineRate></regex>
<regex><pattern>.*.checks.coding.ParameterAssignmentCheck</pattern><branchRate>80</branchRate><lineRate>96</lineRate></regex>
<regex><pattern>.*.checks.coding.ReturnCountCheck</pattern><branchRate>55</branchRate><lineRate>74</lineRate></regex>
<regex><pattern>.*.checks.coding.SimplifyBooleanReturnCheck</pattern><branchRate>83</branchRate><lineRate>100</lineRate></regex>
<regex><pattern>.*.checks.coding.VariableDeclarationUsageDistanceCheck</pattern><branchRate>90</branchRate><lineRate>98</lineRate></regex>

View File

@ -199,7 +199,7 @@ public final class ParameterAssignmentCheck extends Check {
* @param ast ident to check.
*/
private void checkIdent(DetailAST ast) {
if (parameterNames != null && !parameterNames.isEmpty()) {
if (!parameterNames.isEmpty()) {
final DetailAST identAST = ast.getFirstChild();
if (identAST != null

View File

@ -28,6 +28,8 @@ import org.junit.Test;
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class ParameterAssignmentCheckTest extends BaseCheckTestSupport {
@Test
@ -52,4 +54,28 @@ public class ParameterAssignmentCheckTest extends BaseCheckTestSupport {
Assert.assertNotNull(check.getDefaultTokens());
Assert.assertNotNull(check.getRequiredTokens());
}
@Test
public void testImproperToken() throws Exception {
ParameterAssignmentCheck check = new ParameterAssignmentCheck();
DetailAST classDefAst = new DetailAST();
classDefAst.setType(TokenTypes.CLASS_DEF);
try {
check.visitToken(classDefAst);
Assert.fail();
}
catch (IllegalStateException e) {
// it is OK
}
try {
check.leaveToken(classDefAst);
Assert.fail();
}
catch (IllegalStateException e) {
// it is OK
}
}
}

View File

@ -15,7 +15,7 @@ public class InputParameterAssignment {
void foo2() {
field = 0;
}
@SuppressWarnings(value = "unchecked")
void foo3(String field, int field1) {
this.field = (field1 += field.length());
}