Skip to content

Commit

Permalink
Issue checkstyle#3735: added lambdas to NeedBraces for checkstyle config
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Feb 13, 2017
1 parent e307efd commit 8985108
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 19 deletions.
4 changes: 4 additions & 0 deletions config/checkstyle_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
2 changes: 1 addition & 1 deletion config/intellij-idea-inspections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ private static boolean isObjectParam(DetailAST paramNode) {
@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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ private static Set<String> getForIteratorVariables(DetailAST ast) {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ private static boolean hasEmptyImplementation(DetailAST ast) {
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()) {
Expand Down Expand Up @@ -237,9 +238,11 @@ private static boolean hasAnnotation(DetailAST methodDef, String annotationName)
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,10 @@ private static List<String> getTypeArgsClassNames(DetailAST typeArgs) {
*/
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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class ListToTreeSelectionModelWrapper extends DefaultTreeSelectionModel {
*/
ListToTreeSelectionModelWrapper(JTreeTable jTreeTable) {
treeTable = jTreeTable;
getListSelectionModel().addListSelectionListener(event ->
updateSelectedPathsFromSelectedRows());
getListSelectionModel().addListSelectionListener(event -> {
updateSelectedPathsFromSelectedRows();
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ public void testTreeStructure() throws Exception {
}

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down

0 comments on commit 8985108

Please sign in to comment.