Go: add GoTemplate, GoPattern, MethodMatcher, TypeUtils, and rename module#7235
Merged
jkschneider merged 2 commits intomainfrom Apr 1, 2026
Merged
Conversation
…odule Adds comprehensive Go recipe infrastructure to rewrite-go: - **GoTemplate/GoPattern** (`pkg/template/`): Refaster-like template matching and replacement for Go. Supports captures, multiple before patterns (anyOf), scaffold parsing, structural comparison, and a `NewRecipe()` builder for declarative recipes. - **MethodMatcher** (`pkg/matcher/`): AspectJ-style pattern matching for Go method invocations (e.g., `"fmt Sprintf(..)"`) with glob wildcards and type-aware matching. - **TypeUtils** (`pkg/matcher/`): Type checking utilities — `IsAssignableTo()`, `IsOfClassType()`, `IsError()`, `IsString()`, `AsClass()`, `TypeOfExpression()`, `DeclaringTypeFQN()`. - **Markup helpers** (`pkg/tree/markers.go`): `MarkupWarn()`, `MarkupInfo()`, `MarkupError()` convenience functions for attaching severity-level diagnostics to LST nodes. - **GoVisitor completeness**: Fixed 7 visit methods to properly recurse into children (VariableDeclarations, VariableDeclarator, MethodInvocation, Return, If, Assignment, AssignmentOperation). - **Parser fix**: Fixed comma-in-whitespace bug in `mapReturnStmt` — commas between return expressions are now properly consumed and stored in `RightPadded.After`. - **Composite recipe support**: `test.RewriteRun` now handles `RecipeList()` sub-recipes. - **Module rename**: Changed module path from `github.com/openrewrite/rewrite` to `github.com/openrewrite/rewrite/rewrite-go` for proper Go submodule publishing within the monorepo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds comprehensive Go recipe authoring infrastructure to
rewrite-go:GoTemplate/GoPattern (
pkg/template/): Refaster-like template matching and replacement for Go. Supports captures, multiple before patterns (anyOf equivalent), scaffold parsing, structural comparison, and aNewRecipe()declarative builder that reduces recipe authoring from 50+ lines to ~10 lines.MethodMatcher (
pkg/matcher/): AspectJ-style pattern matching for Go method invocations (e.g.,"fmt Sprintf(..)") with glob wildcards and type-aware matching.TypeUtils (
pkg/matcher/): Type checking utilities —IsAssignableTo(),IsOfClassType(),IsError(),IsString(),AsClass(),TypeOfExpression(),DeclaringTypeFQN().Markup helpers (
pkg/tree/markers.go):MarkupWarn(),MarkupInfo(),MarkupError()convenience functions for severity-level diagnostics on LST nodes.GoVisitor completeness: Fixed 7 visit methods to properly recurse into children (VariableDeclarations, VariableDeclarator, MethodInvocation, Return, If, Assignment, AssignmentOperation).
Parser fix: Fixed comma-in-whitespace bug in
mapReturnStmt— commas between return expressions now properly consumed.Composite recipe support:
test.RewriteRunnow handlesRecipeList().Module rename:
github.com/openrewrite/rewrite→github.com/openrewrite/rewrite/rewrite-gofor proper Go submodule publishing within the monorepo.Test plan