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

Fix groovy parser parsing package definition #5142

Merged
merged 3 commits into from
Mar 7, 2025

Conversation

Laurens-W
Copy link
Contributor

What's changed?

Regex for parsing package definition in Groovy now correctly handles the optional semicolon

Anyone you would like to review specifically?

@knutwannheden @shanman190

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

@Laurens-W Laurens-W added the bug Something isn't working label Mar 7, 2025
@Laurens-W Laurens-W self-assigned this Mar 7, 2025
@Laurens-W Laurens-W mentioned this pull request Mar 7, 2025
3 tasks
@shanman190 shanman190 merged commit bd9c7df into main Mar 7, 2025
2 checks passed
@shanman190 shanman190 deleted the fix-groovy-package-parsing branch March 7, 2025 20:22
@@ -62,7 +62,7 @@ public class GroovyParser implements Parser {

@Override
public Stream<SourceFile> parse(@Language("groovy") String... sources) {
Pattern packagePattern = Pattern.compile("^package\\s+([^;]+);");
Pattern packagePattern = Pattern.compile("\\bpackage\\s+([.\\w]+)");
Pattern classPattern = Pattern.compile("(class|interface|enum)\\s*(<[^>]*>)?\\s+(\\w+)");
Copy link
Contributor

Choose a reason for hiding this comment

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

This ironically makes me wonder if we don't support Groovy trait types in various capacities.
https://groovy-lang.org/objectorientation.html#_traits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants