Skip to content

Commit

Permalink
Issue checkstyle#12809: Improve performance of lambda processing
Browse files Browse the repository at this point in the history
  • Loading branch information
nrmancuso committed Mar 10, 2023
1 parent 0cba05e commit 229e827
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,11 @@ public DetailAstImpl visitSimpleMethodCall(JavaLanguageParser.SimpleMethodCallCo

@Override
public DetailAstImpl visitLambdaExp(JavaLanguageParser.LambdaExpContext ctx) {
return flattenedTree(ctx);
final DetailAstImpl lambda = create(ctx.LAMBDA());
processChildren(lambda, ctx.children.stream()
.filter(child -> !child.equals(ctx.LAMBDA()))
.collect(Collectors.toList()));
return lambda;
}

@Override
Expand Down Expand Up @@ -1627,14 +1631,6 @@ public DetailAstImpl visitTypeCastParameters(
return typeType;
}

@Override
public DetailAstImpl visitLambdaExpression(JavaLanguageParser.LambdaExpressionContext ctx) {
final DetailAstImpl lambda = create(ctx.LAMBDA());
lambda.addChild(visit(ctx.lambdaParameters()));
lambda.addChild(visit(ctx.lambdaBody()));
return lambda;
}

@Override
public DetailAstImpl visitSingleLambdaParam(JavaLanguageParser.SingleLambdaParamContext ctx) {
return flattenedTree(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,18 +720,13 @@ expr
| BAND_ASSIGN | BOR_ASSIGN | BXOR_ASSIGN | SR_ASSIGN | BSR_ASSIGN
| SL_ASSIGN | MOD_ASSIGN)
expr #binOp
| lambdaExpression #lambdaExp
| lambdaParameters LAMBDA (expression | block) #lambdaExp
;

typeCastParameters
: typeType[true] (BAND typeType[true])*
;

// Java8
lambdaExpression
: lambdaParameters LAMBDA lambdaBody
;

// Java8
lambdaParameters
: id #singleLambdaParam
Expand All @@ -743,12 +738,6 @@ multiLambdaParams
: id (COMMA id)*
;

// Java8
lambdaBody
: expression
| block
;

primary
: switchExpressionOrStatement #switchPrimary
| LPAREN expr RPAREN #parenPrimary
Expand Down

0 comments on commit 229e827

Please sign in to comment.