Java API for source formatting

2019-04-09 21:46发布

There are several PHP or js code formatting libs out there -- does anyone know if similar libs exist in Java?

Ie., Given a string of code, return a formatted string with syntax colouring etc.

It'd be ideal if it auto detected the language, but I might be pushing my luck there...

The text will ultimately be displayed within a Flex application, so while I could use a js lib, we'll be parsing large files (up to 6000 lines), so I'd like to keep client side processing minimal.

Ideal output is HTML without CSS, although I'll take what I can get.

2条回答
forever°为你锁心
2楼-- · 2019-04-09 22:09

Perhaps try to see the Colorer Project: http://colorer.sourceforge.net/

查看更多
戒情不戒烟
3楼-- · 2019-04-09 22:19

That are two distinct tasks. With regard to code formatting, look around using the keyword "java beautifier". Here is a list. I myself have had good experiences with Jalopy which also ships with an Eclipse plugin. With regard to syntax highlighting, it depends on where you'd like to use it. If programmatically, use JHighlight, or if on a webpage, use Prettify (Stackoverflow also uses it and it can detect languages), or as an Eclipse export plugin, use Java2HTML.

查看更多
登录 后发表回答