Skip to content

(DO NOT MERGE) SONARJAVA-4539 Fix FP on S1602 in lambda when curly braces are required to avoid ambiguity #5127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tomasz-tylenda-sonarsource
Copy link
Contributor

@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource commented May 5, 2025

Copy link
Contributor

@romainbrenguier romainbrenguier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good. I just have some style comments.

Comment on lines 93 to 97
Optional<Arguments> argumentList = Optional.ofNullable(argument.parent())
.filter(Arguments.class::isInstance)
.map(Arguments.class::cast);

if(argumentList.isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if (argument.parent() instance of Arguments argumentList) which is more succinct

Comment on lines 99 to 103
return argumentList
.map(Tree::parent)
.filter(MethodInvocationTree.class::isInstance)
.map(MethodInvocationTree.class::cast)
.map(mit -> new InvocationData(mit.methodSymbol(), position));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing: if (argumentList.parent() instance MethodInvocationTree mit)

/**
* Given a collection of method symbols, get the distinct types possible at {@code position}.
*/
private static Stream<Type> getTypesAtPos(Collection<Symbol> symbols, int position) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTypesAtPosition

}

/**
* Given a collection of method symbols, get the distinct types possible at {@code position}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should mention that it's the position among the parameters

@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource changed the title SONARJAVA-4539 Fix FP on S1602 in lambda when curly braces are required to avoid ambiguity (DO NOT MERGE) SONARJAVA-4539 Fix FP on S1602 in lambda when curly braces are required to avoid ambiguity May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants