Issue #3735: added lambdas to NeedBraces for checkstyle config

This commit is contained in:
rnveach 2017-02-13 16:35:13 -05:00 committed by Roman Ivanov
parent 2b645405ac
commit 34ef127bdc
9 changed files with 31 additions and 19 deletions

View File

@ -168,6 +168,10 @@
<property name="maxLineLength" value="100"/>
</module>
<module name="NeedBraces"/>
<module name="NeedBraces">
<property name="tokens" value="LAMBDA"/>
<property name="allowSingleLineStatement" value="true"/>
</module>
<module name="RightCurly">
<property name="tokens" value="METHOD_DEF"/>
<property name="tokens" value="CTOR_DEF"/>

View File

@ -344,7 +344,7 @@
<inspection_tool class="CloneableImplementsClone" enabled="false" level="ERROR" enabled_by_default="false">
<option name="m_ignoreCloneableDueToInheritance" value="false" />
</inspection_tool>
<inspection_tool class="CodeBlock2Expr" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="CodeBlock2Expr" enabled="false" level="ERROR" enabled_by_default="true" />
<inspection_tool class="CoffeeScriptArgumentsOutsideFunction" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="CoffeeScriptFunctionSignatures" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="CoffeeScriptInfiniteLoop" enabled="true" level="ERROR" enabled_by_default="true" />

View File

@ -158,9 +158,9 @@ public class EqualsHashCodeCheck
@Override
public void finishTree(DetailAST rootAST) {
objBlockWithEquals
.entrySet().stream().filter(detailASTDetailASTEntry ->
objBlockWithHashCode.remove(detailASTDetailASTEntry.getKey()) == null)
.forEach(detailASTDetailASTEntry -> {
.entrySet().stream().filter(detailASTDetailASTEntry -> {
return objBlockWithHashCode.remove(detailASTDetailASTEntry.getKey()) == null;
}).forEach(detailASTDetailASTEntry -> {
final DetailAST equalsAST = detailASTDetailASTEntry.getValue();
log(equalsAST.getLineNo(), equalsAST.getColumnNo(), MSG_KEY_HASHCODE);
});

View File

@ -377,9 +377,9 @@ public final class ModifiedControlVariableCheck extends AbstractCheck {
final DetailAST forUpdateListAST = forIteratorAST.findFirstToken(TokenTypes.ELIST);
findChildrenOfExpressionType(forUpdateListAST).stream()
.filter(iteratingExpressionAST ->
MUTATION_OPERATIONS.contains(iteratingExpressionAST.getType()))
.forEach(iteratingExpressionAST -> {
.filter(iteratingExpressionAST -> {
return MUTATION_OPERATIONS.contains(iteratingExpressionAST.getType());
}).forEach(iteratingExpressionAST -> {
final DetailAST oneVariableOperatorChild = iteratingExpressionAST.getFirstChild();
if (oneVariableOperatorChild.getType() == TokenTypes.IDENT) {
iteratorVariables.add(oneVariableOperatorChild.getText());

View File

@ -184,11 +184,12 @@ public class DesignForExtensionCheck extends AbstractCheck {
final DetailAST methodImplOpenBrace = ast.findFirstToken(TokenTypes.SLIST);
if (methodImplOpenBrace != null) {
final DetailAST methodImplCloseBrace = methodImplOpenBrace.getLastChild();
final Predicate<DetailAST> predicate = currentNode ->
currentNode != null
final Predicate<DetailAST> predicate = currentNode -> {
return currentNode != null
&& currentNode != methodImplCloseBrace
&& currentNode.getLineNo() <= methodImplCloseBrace.getLineNo()
&& !TokenUtils.isCommentType(currentNode.getType());
};
final Optional<DetailAST> methodBody =
TokenUtils.findFirstTokenByPredicate(methodImplOpenBrace, predicate);
if (methodBody.isPresent()) {
@ -237,9 +238,11 @@ public class DesignForExtensionCheck extends AbstractCheck {
boolean containsAnnotation = false;
if (modifiers.branchContains(TokenTypes.ANNOTATION)) {
final Optional<DetailAST> annotation = TokenUtils.findFirstTokenByPredicate(modifiers,
currentToken -> currentToken != null
&& currentToken.getType() == TokenTypes.ANNOTATION
&& annotationName.equals(getAnnotationName(currentToken)));
currentToken -> {
return currentToken != null
&& currentToken.getType() == TokenTypes.ANNOTATION
&& annotationName.equals(getAnnotationName(currentToken));
});
if (annotation.isPresent()) {
containsAnnotation = true;
}

View File

@ -724,8 +724,10 @@ public class VisibilityModifierCheck
*/
private boolean areImmutableTypeArguments(List<String> typeArgsClassNames) {
return !typeArgsClassNames.stream().filter(
typeName -> !immutableClassShortNames.contains(typeName)
&& !immutableClassCanonicalNames.contains(typeName)).findFirst().isPresent();
typeName -> {
return !immutableClassShortNames.contains(typeName)
&& !immutableClassCanonicalNames.contains(typeName);
}).findFirst().isPresent();
}
/**

View File

@ -43,8 +43,9 @@ class ListToTreeSelectionModelWrapper extends DefaultTreeSelectionModel {
*/
ListToTreeSelectionModelWrapper(JTreeTable jTreeTable) {
treeTable = jTreeTable;
getListSelectionModel().addListSelectionListener(event ->
updateSelectedPathsFromSelectedRows());
getListSelectionModel().addListSelectionListener(event -> {
updateSelectedPathsFromSelectedRows();
});
}
/**

View File

@ -122,9 +122,11 @@ public class DetailASTTest {
}
private static void checkDir(File dir) throws Exception {
final File[] files = dir.listFiles(file -> (file.getName().endsWith(".java")
final File[] files = dir.listFiles(file -> {
return (file.getName().endsWith(".java")
|| file.isDirectory())
&& !file.getName().endsWith("InputGrammar.java"));
&& !file.getName().endsWith("InputGrammar.java");
});
for (File file : files) {
if (file.isFile()) {
checkFile(file.getCanonicalPath());

View File

@ -183,7 +183,7 @@ public class AllChecksTest extends BaseCheckTestSupport {
CHECKSTYLE_TOKENS_IN_CONFIG_TO_IGNORE.put("NeedBraces", Stream.of(
// we prefer no braces here as it looks unusual even though they help avoid sharing
// scope of variables
"LITERAL_DEFAULT", "LITERAL_CASE", "LAMBDA").collect(Collectors.toSet()));
"LITERAL_DEFAULT", "LITERAL_CASE").collect(Collectors.toSet()));
CHECKSTYLE_TOKENS_IN_CONFIG_TO_IGNORE.put("FinalParameters", Stream.of(
// we prefer these to be effectively final as to not damage readability
"FOR_EACH_CLAUSE", "LITERAL_CATCH").collect(Collectors.toSet()));