parent
325e57feb8
commit
40a0b5dcf7
|
|
@ -176,7 +176,8 @@ public class FinalParametersCheck extends AbstractCheck {
|
|||
* @param param parameter to check.
|
||||
*/
|
||||
private void checkParam(final DetailAST param) {
|
||||
if (!param.branchContains(TokenTypes.FINAL) && !isIgnoredParam(param)) {
|
||||
if (!param.branchContains(TokenTypes.FINAL) && !isIgnoredParam(param)
|
||||
&& !CheckUtils.isReceiverParameter(param)) {
|
||||
final DetailAST paramName = param.findFirstToken(TokenTypes.IDENT);
|
||||
final DetailAST firstNode = CheckUtils.getFirstNode(param);
|
||||
log(firstNode.getLineNo(), firstNode.getColumnNo(),
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
|
|||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.Scope;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CheckUtils;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
|
||||
import com.puppycrawl.tools.checkstyle.utils.ScopeUtils;
|
||||
|
||||
|
|
@ -299,6 +300,7 @@ public class HiddenFieldCheck
|
|||
*/
|
||||
private void processVariable(DetailAST ast) {
|
||||
if (!ScopeUtils.isInInterfaceOrAnnotationBlock(ast)
|
||||
&& !CheckUtils.isReceiverParameter(ast)
|
||||
&& (ScopeUtils.isLocalVariableDef(ast)
|
||||
|| ast.getType() == TokenTypes.PARAMETER_DEF)) {
|
||||
// local variable or parameter. Does it shadow a field?
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.google.common.collect.Sets;
|
|||
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CheckUtils;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -236,7 +237,8 @@ public final class ParameterAssignmentCheck extends AbstractCheck {
|
|||
ast.findFirstToken(TokenTypes.PARAMETER_DEF);
|
||||
|
||||
while (parameterDefAST != null) {
|
||||
if (parameterDefAST.getType() == TokenTypes.PARAMETER_DEF) {
|
||||
if (parameterDefAST.getType() == TokenTypes.PARAMETER_DEF
|
||||
&& !CheckUtils.isReceiverParameter(parameterDefAST)) {
|
||||
final DetailAST param =
|
||||
parameterDefAST.findFirstToken(TokenTypes.IDENT);
|
||||
parameterNames.add(param.getText());
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import com.google.common.collect.Sets;
|
|||
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CheckUtils;
|
||||
import com.puppycrawl.tools.checkstyle.utils.ScopeUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -321,8 +322,10 @@ public class RequireThisCheck extends AbstractCheck {
|
|||
collectVariableDeclarations(ast, frame);
|
||||
break;
|
||||
case TokenTypes.PARAMETER_DEF :
|
||||
final DetailAST parameterIdent = ast.findFirstToken(TokenTypes.IDENT);
|
||||
frame.addIdent(parameterIdent);
|
||||
if (!CheckUtils.isReceiverParameter(ast)) {
|
||||
final DetailAST parameterIdent = ast.findFirstToken(TokenTypes.IDENT);
|
||||
frame.addIdent(parameterIdent);
|
||||
}
|
||||
break;
|
||||
case TokenTypes.CLASS_DEF :
|
||||
case TokenTypes.INTERFACE_DEF :
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.google.common.collect.Sets;
|
|||
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CheckUtils;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -220,7 +221,7 @@ public class AbbreviationAsWordInNameCheck extends AbstractCheck {
|
|||
private boolean isIgnoreSituation(DetailAST ast) {
|
||||
final DetailAST modifiers = ast.getFirstChild();
|
||||
|
||||
boolean result = false;
|
||||
final boolean result;
|
||||
if (ast.getType() == TokenTypes.VARIABLE_DEF) {
|
||||
if ((ignoreFinal || ignoreStatic)
|
||||
&& isInterfaceDeclaration(ast)) {
|
||||
|
|
@ -238,6 +239,9 @@ public class AbbreviationAsWordInNameCheck extends AbstractCheck {
|
|||
result = ignoreOverriddenMethods
|
||||
&& hasOverrideAnnotation(modifiers);
|
||||
}
|
||||
else {
|
||||
result = CheckUtils.isReceiverParameter(ast);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package com.puppycrawl.tools.checkstyle.checks.naming;
|
|||
import com.google.common.base.Optional;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CheckUtils;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -105,7 +106,8 @@ public class ParameterNameCheck
|
|||
protected boolean mustCheckName(DetailAST ast) {
|
||||
boolean checkName = true;
|
||||
if (ignoreOverridden && isOverriddenMethod(ast)
|
||||
|| ast.getParent().getType() == TokenTypes.LITERAL_CATCH) {
|
||||
|| ast.getParent().getType() == TokenTypes.LITERAL_CATCH
|
||||
|| CheckUtils.isReceiverParameter(ast)) {
|
||||
checkName = false;
|
||||
}
|
||||
return checkName;
|
||||
|
|
|
|||
|
|
@ -410,4 +410,19 @@ public final class CheckUtils {
|
|||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a parameter is a receiver.
|
||||
*
|
||||
* @param parameterDefAst the parameter node.
|
||||
* @return true if the parameter is a receiver.
|
||||
*/
|
||||
public static boolean isReceiverParameter(DetailAST parameterDefAst) {
|
||||
boolean returnValue = false;
|
||||
if (parameterDefAst.getType() == TokenTypes.PARAMETER_DEF
|
||||
&& parameterDefAst.findFirstToken(TokenTypes.IDENT) == null) {
|
||||
returnValue = parameterDefAst.branchContains(TokenTypes.LITERAL_THIS);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import org.junit.Test;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
|
||||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
|
||||
|
||||
public class FinalParametersCheckTest extends BaseCheckTestSupport {
|
||||
@Override
|
||||
|
|
@ -127,4 +128,12 @@ public class FinalParametersCheckTest extends BaseCheckTestSupport {
|
|||
};
|
||||
verify(checkConfig, getPath("InputFinalParametersPrimitiveTypes.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecieverParameters() throws Exception {
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(FinalParametersCheck.class);
|
||||
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
|
||||
verify(checkConfig, getPath("InputFinalParametersReceiver.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import org.junit.Test;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
|
||||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
|
||||
|
||||
public class HiddenFieldCheckTest
|
||||
extends BaseCheckTestSupport {
|
||||
|
|
@ -402,4 +403,11 @@ public class HiddenFieldCheckTest
|
|||
};
|
||||
verify(checkConfig, getPath("InputHiddenField.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiverParameter() throws Exception {
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);
|
||||
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
|
||||
verify(checkConfig, getPath("InputHiddenFieldReceiver.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ 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;
|
||||
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
|
||||
|
||||
public class ParameterAssignmentCheckTest extends BaseCheckTestSupport {
|
||||
@Override
|
||||
|
|
@ -54,6 +55,13 @@ public class ParameterAssignmentCheckTest extends BaseCheckTestSupport {
|
|||
expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiverParameter() throws Exception {
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(ParameterAssignmentCheck.class);
|
||||
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
|
||||
verify(checkConfig, getPath("InputParameterAssignmentReceiver.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTokensNotNull() {
|
||||
final ParameterAssignmentCheck check = new ParameterAssignmentCheck();
|
||||
|
|
|
|||
|
|
@ -240,4 +240,11 @@ public class RequireThisCheckTest extends BaseCheckTestSupport {
|
|||
};
|
||||
verify(checkConfig, getPath("InputValidateOnlyOverlappingTrue.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiverParameter() throws Exception {
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(RequireThisCheck.class);
|
||||
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
|
||||
verify(checkConfig, getPath("InputRequireThisReceiver.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -319,4 +319,13 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
|
|||
private String getWarningMessage(String typeName, int expectedCapitalCount) {
|
||||
return getCheckMessage(MSG_KEY, typeName, expectedCapitalCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiver() throws Exception {
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(AbbreviationAsWordInNameCheck.class);
|
||||
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
|
||||
|
||||
verify(checkConfig, getPath("InputAbbreviationAsWordReceiver.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,4 +147,11 @@ public class ParameterNameCheckTest
|
|||
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
|
||||
verify(checkConfig, getPath("InputOverrideAnnotationNoNPE.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiverParameter() throws Exception {
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(ParameterNameCheck.class);
|
||||
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
|
||||
verify(checkConfig, getPath("InputParameterNameReceiver.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks;
|
||||
|
||||
public class InputFinalParametersReceiver {
|
||||
public void foo4(InputFinalParametersReceiver this) {}
|
||||
|
||||
private class Inner {
|
||||
public Inner(InputFinalParametersReceiver InputFinalParametersReceiver.this) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.coding;
|
||||
|
||||
public class InputHiddenFieldReceiver {
|
||||
public void foo4(InputHiddenFieldReceiver this) {}
|
||||
|
||||
private class Inner {
|
||||
public Inner(InputHiddenFieldReceiver InputHiddenFieldReceiver.this) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.coding;
|
||||
|
||||
public class InputParameterAssignmentReceiver {
|
||||
public void foo4(InputParameterAssignmentReceiver this) {}
|
||||
|
||||
private class Inner {
|
||||
public Inner(InputParameterAssignmentReceiver InputParameterAssignmentReceiver.this) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.coding;
|
||||
|
||||
public class InputRequireThisReceiver {
|
||||
public void foo4(InputRequireThisReceiver this) {}
|
||||
|
||||
private class Inner {
|
||||
public Inner(InputRequireThisReceiver InputRequireThisReceiver.this) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.naming;
|
||||
|
||||
public class InputAbbreviationAsWordReceiver {
|
||||
public void foo4(InputAbbreviationAsWordReceiver this) {}
|
||||
|
||||
private class Inner {
|
||||
public Inner(InputAbbreviationAsWordReceiver InputAbbreviationAsWordReceiver.this) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.naming;
|
||||
|
||||
public class InputParameterNameReceiver {
|
||||
public void foo4(InputParameterNameReceiver this) {}
|
||||
|
||||
private class Inner {
|
||||
public Inner(InputParameterNameReceiver InputParameterNameReceiver.this) {}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue