Skip to content

feat: add Java writer and Gradle support, fix parser stability issues#164

Open
thunguo wants to merge 2 commits intocloudwego:mainfrom
thunguo:feat/java-writer
Open

feat: add Java writer and Gradle support, fix parser stability issues#164
thunguo wants to merge 2 commits intocloudwego:mainfrom
thunguo:feat/java-writer

Conversation

@thunguo
Copy link

@thunguo thunguo commented Mar 6, 2026

What type of PR is this?

feat

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:

  1. Add Java Writer
  • Created lang/java/writer/write.go and lang/java/writer/ast.go, implementing a Java code generator (uniast.Writer interface) that supports generating Java source code and pom.xml from UniAST
  • Created lang/java/writer/write_test.go with comprehensive unit tests
  • Modified lang/write.go and lang/patch/lib.go to register the Java Writer into the framework
  1. Add Gradle Project Support (Is there any plan to support java gradle project ? #146)
  • Created lang/java/parser/gradle_parser.go, using regex to extract project structure from settings.gradle(.kts) / build.gradle(.kts) and outputting ModuleInfo in the same format as the Maven parser
  • Created lang/java/parser/gradle_parser_test.go and testdata/java/5_gradle_project/ test data
  • Modified NewJavaSpec in lang/java/spec.go: three-level detection — Maven → Gradle → empty fallback
  • Modified lang/collect/collect.go: added Gradle fallback to both ScannerByTreeSitter and ScannerByJavaIPC
  1. Fix Non-Deterministic Output (parser/java: output instability #95)
  • lang/collect/export.go: receivers map entries are now sorted by source position after collection, ensuring stable method ordering
  • lang/collect/collect.go: fallback file traversal changed to iterate over a sorted list, eliminating map random ordering
  1. Fix FileImports Panic
  • lang/java/spec.go: replaced panic("Java import parsing by tree-setting") with a regex-based import parsing implementation
  1. Fix Writer Import Lookup Failure
  • lang/java/writer/write.go: keys in mod.Files are relative paths — fixed by matching on basename instead
  1. Improve extractPackageFromPath
  • lang/java/ipc/converter.go: added recognition for src/test/java/, src/main/kotlin/, and src/test/kotlin/ path prefixes

zh(optional):

(Optional) Which issue(s) this PR fixes:

Fixes #95 #146

(optional) The PR that updates user documentation:

@CLAassistant
Copy link

CLAassistant commented Mar 6, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

parser/java: output instability

2 participants