| name | java-distiller |
| description | Simplify, modernize, refactor, and beautify Java code to produce clean, idiomatic Java 25. Use when asked to distill, simplify, modernize, upgrade, refactor, clean up, beautify, or improve Java code. Triggers on "distill this Java", "modernize this code", "simplify this Java", "upgrade to modern Java", "refactor to Java 25", "clean up this code", "make this idiomatic", "beautify this Java", or when Java code needs transformation to current standards. Not for writing new code from scratch — use java-development for that. |
Java Distiller
Transform Java code into its cleanest, most modern, idiomatic form. Distill away verbosity, legacy patterns, and accidental complexity — keep only the essence.
Philosophy
- Distill, don't decorate — remove complexity, don't add abstractions
- Modern Java first — use Java 25 features wherever they simplify the code
- Functional over imperative — prefer streams, lambdas, and declarative style when clearer
- Less code, more meaning — every remaining line should earn its place
Workflow
- Read the input code carefully
- Identify transformation opportunities (see references/transformations.md)
- Apply transformations — prioritize those with the highest impact-to-risk ratio
- Present the distilled code with a brief explanation of what changed and why
Transformation Priority
Apply in this order — high-impact, low-risk first:
- Syntax modernization — var, text blocks, switch expressions, module imports
- API upgrades — java.time, java.nio.file, HttpClient, List.of/Map.of
- Pattern adoption — records, sealed interfaces, pattern matching
- Functional style — streams over loops, lambdas over anonymous classes
- Concurrency modernization — virtual threads, structured concurrency, scoped values
- Structural simplification — flatten hierarchies, inline trivial methods, remove dead code
Output Format
## Distilled
```java
// transformed code
```
### Changes
- <what changed> — <why it's better>
- ...
Rules
- Preserve behavior exactly — distilling is refactoring, not rewriting
- Do not add comments, javadoc, or logging that wasn't there
- Do not add error handling beyond what exists unless the original code has a bug
- Do not introduce new dependencies
- Remove unnecessary blank lines, redundant modifiers, and dead imports
- Use
var where the type is obvious from the right-hand side
- Use module imports (
import module java.net.http;) over individual type imports
- Prefer
void main() over public static void main(String[] args) when appropriate
- When multiple transformations compete, choose the one that produces fewer lines
- If the code is already clean and modern, say so — don't force changes
Detailed Transformation Catalog
See references/transformations.md for the complete catalog of before/after transformation patterns organized by category.