Skip to content
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

Improve discovery of parentheses level for MethodCallExpression #4834

Conversation

jevanlingen
Copy link
Contributor

@jevanlingen jevanlingen commented Jan 2, 2025

What's changed?

Parentheses discovery for method calls did not always work properly.

What's your motivation?

Failing parts:

Micronaut.build(args)
    .packages('com.edalex')
    .mainClass(Application)
    .start()

Any additional context

The discovery of parentheses is quite hard to grasp. This is the concept behind it. We defined two variables called parent and child. The parent and child are nodes, which could be visualised like: <<child> parent>. Notice in source code, the nodes could span multiple lines.

To support this, we loop through all the lines of code of the parent and child element:

for (int i = 0; i < (childLineNumber - parentLineNumber); i++)
  // move `untilCursor` past next line break every time

// move `untilCursor` after childColumn of last line

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@jevanlingen jevanlingen added bug Something isn't working parser-groovy labels Jan 2, 2025
@jevanlingen jevanlingen self-assigned this Jan 2, 2025
@jevanlingen jevanlingen requested a review from timtebeek January 2, 2025 16:10
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Nice! Really hammering out those fixes today.

@jevanlingen jevanlingen merged commit 2bf57b9 into main Jan 2, 2025
2 checks passed
@jevanlingen jevanlingen deleted the improve-getInsideParenthesesLevel-for-method-call-expression branch January 2, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-groovy
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants