Skip to content

Support Groovy destructuring assignment parsing#6636

Merged
timtebeek merged 9 commits intomainfrom
groovy-destructuring-assignment
Mar 23, 2026
Merged

Support Groovy destructuring assignment parsing#6636
timtebeek merged 9 commits intomainfrom
groovy-destructuring-assignment

Conversation

@MBoegers
Copy link
Copy Markdown
Contributor

@MBoegers MBoegers commented Jan 29, 2026

Summary

  • Support parsing Groovy multiple/destructuring assignment syntax (def (a, b, c) = expr)
  • Add DestructuringVariables marker to track parenthesized variable lists
  • Update printer to correctly round-trip destructuring assignments

Problem

The Groovy parser throws UnsupportedOperationException when encountering destructuring assignments like def (major, minor, patch) = tag.tokenize('.'). This syntax is commonly used in Jenkinsfiles and causes GroovyParsingException for customers.

Solution

  • Created DestructuringVariables marker that signals the printer to wrap variables in (...) and place the initializer after )
  • Replaced the throw UnsupportedOperationException in visitDeclarationExpression with parsing logic that handles TupleExpression on the left side of a DeclarationExpression
  • Updated GroovyPrinter.visitVariableDeclarations to handle the new marker

Test plan

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jan 29, 2026
@MBoegers MBoegers force-pushed the groovy-destructuring-assignment branch 2 times, most recently from b727805 to 8f5b902 Compare January 29, 2026 15:12
Add support for parsing Groovy destructuring assignments like
`def (a, b, c) = [1, 2, 3]` which previously threw an
UnsupportedOperationException.

Introduces G.TupleExpression, a new LST element implementing
VariableDeclarator, placed in NamedVariable#name following the
same pattern as JavaScript's ArrayBindingPattern.
@MBoegers MBoegers force-pushed the groovy-destructuring-assignment branch from 8f5b902 to d710b1e Compare January 29, 2026 15:52
@knutwannheden knutwannheden linked an issue Jan 30, 2026 that may be closed by this pull request
@MBoegers MBoegers marked this pull request as ready for review February 16, 2026 09:19
@MBoegers
Copy link
Copy Markdown
Contributor Author

@knutwannheden added a test to show we also fix the issue you linked. Happy to have a review here.

@greg-at-moderne
Copy link
Copy Markdown
Contributor

greg-at-moderne commented Feb 16, 2026

@MBoegers
Copy link
Copy Markdown
Contributor Author

@greg-at-moderne checked, yes this PR resolves these issues as well and also covers the linked PR.

@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class TupleExpression implements G, Expression, TypedTree, VariableDeclarator {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Linking the VariableDeclarator here:

* A variable declarator is a variable name(s). As used in {@link NamedVariable} it forms a name and its initializer.
* In the most common case, a variable declarator is a single name, but in the case of destructuring
* assignments, it can be multiple names that are each assigned by the single {@link NamedVariable#getInitializer()}.
* <p>
* A fun note on the name: the word VariableDeclarator comes from the Typescript compiler's definition
* of this concept, and it fits the concept well for all languages in the {@link J} grammar island.
*/
public interface VariableDeclarator extends TypedTree {
List<J.Identifier> getNames();

This was suggested as the replacement in

Tim te Beek added 2 commits March 12, 2026 15:39
…alues

visit() returns void while doVisit() returns the visited element.
Lines 1733 and 1762 in GroovyParserVisitor need the return value.
@timtebeek
Copy link
Copy Markdown
Member

@knutwannheden any final thoughts here before a merge? The approach had already been signed off on earlier.

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Mar 23, 2026
@timtebeek timtebeek merged commit 8694ebc into main Mar 23, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Mar 23, 2026
@timtebeek timtebeek deleted the groovy-destructuring-assignment branch March 23, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Groovy parser does not support multiple assignments

4 participants