mac
mac

Reputation: 2734

Custom formatter for Sun Codemodel

I'm using Java Sun Codemodel to generate java classes on the fly, and it works pretty well for me.

Now I have an additional challenge: How do I control how the code is formatted? Is there any way at all? In particular, I'd like to have all curly brackets in a new line and would like to extend the line length to let's say 130 chars.

E.g., we have a formatter that we use in Eclipse. There's no way I can just tell Codemodel to use that somehow, right?

There's this JFormatter class that kind of looks like it could be useful for something, but it doesn't look like it can do more sophisticated stuff like that.

Upvotes: 1

Views: 626

Answers (1)

Stanislav Mamontov
Stanislav Mamontov

Reputation: 1794

JFormatter declared as final, so not, it isn't possible.

There's only two ways to solve the problem and continue using codemodel.

  1. Process generated code with some another tool/library.
  2. Redefine library classes. Find which concrete classes does unwanted formatting, then create classes with same package/name in your project and write your own implementation. There classes must appear in classpath earlier than codemodel jar.

Upvotes: 1

Related Questions