Skip to content

Commit bbe3b20

Browse files
authored
rewrite-go: ship parity with JS / Python / C# ports (#7557)
Full RPC handler surface, recipe-author primitives, type attribution, test harness, and recipe library brought to parity with the JavaScript, Python, and C# language ports. RPC handler surface - Parse / ParseProject (project-aware: module + goModContent; per-file closest-ancestor go.mod ownership; sibling go.sum populates ResolvedDependencies). - BatchVisit returns {modified, deleted, hasNewMessages, searchResultIds}; searchResultIds walker registered, hasNewMessages snapshot tracked. - Generate drives ScanningRecipe.Generate. - GetMarketplace emits full descriptor (recipeList, dataTables, preconditions, maintainers, contributors, examples, option types). - PrepareRecipe returns per-instance UUID. - TraceGetObject for RPC tracing. - Server CLI flags: --log-file, --trace-rpc-messages, --metrics-csv, --recipe-install-dir, --data-tables-csv-dir. Recipe-author surface - recipe.Recipe + recipe.Base, ScanningRecipe end-to-end. - recipe.DataTable[Row] generic + InMemoryDataTableStore + CsvDataTableStore. - visitor.GoVisitor.Cursor() / SetCursor() for RPC seeding; visitor.BuildChain reconstructs cursors from RPC IDs. - Cursor message map: PutMessage, GetNearestMessage, PollNearestMessage, etc. - recipe.Service[T](sourceFile) registry + GoVisitor.DoAfterVisit composition. - Five services: ImportService, AutoFormatService, AnnotationService, WhitespaceValidationService, NamingService. - Five foundational recipes: AddImport, RemoveImport, RemoveUnusedImports, OrderImports, RenamePackage. Type attribution - Same-package multi-file resolution via parser.ParsePackage. - Third-party module resolution via go.mod requires + vendor walker (parses <projectRoot>/vendor/<modulePath>/*.go for real JavaTypeMethod attribution; honors `replace` directives). - tree.GoResolutionResult marker (Module, Requires, Replaces, Excludes, Retracts, ResolvedDependencies); both Go-side and Java-side RPC codecs. - parser.ProjectImporter 3-tier lazy resolver (sources -> requires -> stdlib). - Build-tag file inclusion: parser.MatchBuildContext recognizes //go:build, // +build, and filename suffixes; default build.Default with recipe-author override. - Cross-package generics across the corpus. RPC sender / receiver visitor-pattern refactor - Senders / receivers on both sides extend the language visitor (visitor.GoVisitor on Go, JavaVisitor<RpcSendQueue/ReceiveQueue> on Java) and override VisitX, mirroring rewrite-java. - Eliminated ~600 LOC of switch boilerplate. - tree.J got polymorphic GetID / GetPrefix / GetMarkers; mutators intentionally NOT on the interface (would break RecipeScheduler identity-based change detection). Annotations - tree.Annotation (J-shaped) + LeadingAnnotations on VariableDeclarations, MethodDeclaration, TypeDecl on both Go and Java sides. - Struct field tags AND //go:/lint: directives uniformly modeled as J.Annotation; printer reassembles backticks for tags and //<name> lines for directives. - AnnotationService surface mirrors rewrite-java (AllAnnotations, IsAnnotatedWith, FindAnnotations, AddAnnotationVisitor, RemoveAnnotationVisitor). Test harness - Java: Assertions.go(...), goMod(...), goProject(name, ...) sibling pattern matching mavenProject(...). - Go: test.RewriteRun + test.Golang(...), test.GoMod(...), test.GoSum(...), test.GoProject(name, ...). - propagateModuleResolution copies the parsed go.mod marker onto every sibling .go CU at project expansion so cross-file recipes read module context per file. - ExpectType / ExpectPrimitiveType / ExpectMethodType helpers on both sides. - GoMod conformance corpus (10 cases) shared across Go + Java tests. - Printer parity corpus (13 fixtures across gofmt/ + generics/), opt-in via `make parity`, never in CI. Recipe-author guide at doc/recipe-authoring.md. PLAN.md removed: contents are now reflected in the codebase, doc, and shipped tests.
1 parent becae3b commit bbe3b20

152 files changed

Lines changed: 14806 additions & 1740 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rewrite-go/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rewrite/test-classpath.txt
1+
test-classpath.txt

rewrite-go/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: test parity
2+
3+
# Default test run — what CI executes. Build-tag-gated tests stay out.
4+
test:
5+
go test ./...
6+
7+
# Printer fidelity audit. Loads every fixture under
8+
# test/printer-corpus/, parses + prints, and asserts byte-equality.
9+
# Gated behind the `parityaudit` build tag so it never runs in CI;
10+
# devs invoke it manually when investigating printer regressions.
11+
#
12+
# Trade-off (per the eng review's P2 decision): corpus regressions ship
13+
# undetected by automation in exchange for fast iteration and simple
14+
# test infra. Re-evaluate if a corpus-detectable bug ever lands.
15+
parity:
16+
go test -tags parityaudit ./pkg/printer/...

rewrite-go/PLAN.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

rewrite-go/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ tasks.withType<Javadoc>().configureEach {
3030
exclude("**/G.java")
3131
}
3232

33+
// Test fixtures for the GoMod conformance corpus are .gomod / .gosum / .json
34+
// files; none of these formats accept a leading license header.
35+
configure<nl.javadude.gradle.plugins.license.LicenseExtension> {
36+
excludePatterns.addAll(listOf("**/*.gomod", "**/*.gosum", "**/*.json"))
37+
}
38+
3339
val goBuild = tasks.register<Exec>("goBuild") {
3440
workingDir = projectDir
3541
// Use relative path to avoid absolute paths in cache key (Exec args are cache inputs)

0 commit comments

Comments
 (0)