Matt
Matt

Reputation: 5778

Java Compiler API to get tokens?

Is there some part of the JavaCompiler, or Java ToolProvider that would allow me to get a list of all the tokens in a Java file? That is, all the legal tokens (each as a data structure preferably), and put them in a list (or other data structure)? I know there's probably a 3rd party api out there somewhere, but I'm wondering if it can be done via the javax.tools library, or another way?

Upvotes: 0

Views: 134

Answers (1)

SpaceTrucker
SpaceTrucker

Reputation: 13546

You can query the Abstract Syntax Tree of Java compilation units from the Eclipse JDT API. With a little bit of effort this can also be used as standalone. You may use the AST view as an example.

Upvotes: 1

Related Questions