Skip to content

feat: re-add Javadoc support via source post-processing#240

Open
bouclem wants to merge 1 commit into
MCPHackers:mainfrom
bouclem:feat/javadoc-injection
Open

feat: re-add Javadoc support via source post-processing#240
bouclem wants to merge 1 commit into
MCPHackers:mainfrom
bouclem:feat/javadoc-injection

Conversation

@bouclem
Copy link
Copy Markdown

@bouclem bouclem commented May 25, 2026

Refs #220

Background

TinyJavadocProvider and SimpleJavadocProvider exist in the tree but are entirely commented out, including their package lines. They reference de.fernflower.main.providers.IJavadocProvider. Checking the published io.github.lassebq:fernflower:1.0.0 artifact confirms that interface does not exist in the jar, and BaseDecompiler only has the 4-arg constructor (IBytecodeProvider, IResultSaver, Map, IFernflowerLogger). The Lassebq/Fernflower source likewise has no providers package and no tags or releases beyond master.

So uncommenting was not an option, and bumping the dependency wasn't either.

What this does

Adds Javadoc comments to the decompiled output by post-processing the generated .java files instead of going through Fernflower's provider hook. Two new files in their own tools/javadoc package, plus one wiring line in TaskDecompile.

  • JavadocMappings reads the existing Tiny mapping file (conf/mappings.tiny) using the project's existing mapping-io dependency and collects class and field comments keyed by the named namespace. No new dependencies.
  • JavadocSource extends the existing Source base class. It tracks brace depth with quote and comment skipping so it only documents the top-level type and its direct field members. Locals, inner-class members, anonymous bodies, and anything that looks ambiguous are left alone. Skips re-documenting anything that already has a */ block above it, so re-runs are idempotent.
  • TaskDecompile calls the new Source.modify step in the existing patch stage, after patches and after MCP.SOURCE_ADAPTERS. If the mapping file has no comments the step is a no-op.

Method comments are intentionally not handled. Without a real Java parser, matching overloads from regenerated source is not reliable enough and silent wrong-doc bugs are worse than no doc.

Files

  • new: src/main/java/org/mcphackers/mcp/tools/javadoc/JavadocMappings.java
  • new: src/main/java/org/mcphackers/mcp/tools/javadoc/JavadocSource.java
  • modified: src/main/java/org/mcphackers/mcp/tasks/TaskDecompile.java (3 import lines, 1 call)

The two existing commented-out provider files (SimpleJavadocProvider, TinyJavadocProvider) were left untouched on purpose — they target a Fernflower API that does not currently exist on the classpath, so removing them is a separate decision for the project.

Testing

  • gradlew compileJava - clean.
  • Manually traced behaviour against the existing Source.modify pipeline and the path layout produced by Source.modify callers.

Reads class and field comments from the Tiny mapping file and injects them as Javadoc blocks above the matching declarations after Fernflower decompiles. Implemented as a new Source modification step in TaskDecompile, runs after patches and existing source adapters.

Method comments are intentionally skipped: matching overloads from rewritten source without a real Java parser is not reliable enough. Brace-depth tracking with quote/comment skipping limits insertions to top-level type members so locals and inner-class members are never touched.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant