Spoon
← works
2014— · Program Analysis · Java · AST

Spoon

An open-source library for parsing, analyzing, and transforming Java source code as an AST.

github ↗ 1,500+ dependent projects

The problem

Working with Java at the source level usually forces a choice between brittle text manipulation and the heavyweight internals of a compiler. Neither is comfortable when you want to query a codebase or rewrite it safely at scale.

The approach

Spoon parses Java into a complete, type-resolved AST — the CtModel — and exposes an intuitive API to traverse it, match patterns, and transform or generate code. Analyses and refactorings become a few lines against the model instead of a parser project.

In practice

Spoon is maintained by INRIA and used far beyond its original group, underpinning a large ecosystem of analysis and refactoring tools. I contribute to the library and have built several of my own analysis and program-repair tools on top of it.

Highlights

  • A complete, type-resolved model of Java — not just syntax
  • One API for analysis, refactoring, and code generation
  • 1,500+ open-source projects depend on it