Friday, 15 April 2011

Generating really big Java code -


I have to fill ~ 20k underlying function and constant with a list of CHM files. First of all I tried to list them, but deserialization takes 1500ms (too early to get code-complete, even on the first hit).

Tried the code generation using string templates, which generates valid code. But this will not compile because the "initEnums () method exceeds the size limit of 65536" (and my eclipse ends soon)

The generated method looks like this:

  Public XModelField [] initEnums () {New XModelField {New XModelField ("Aname", "aType", ...), ... // approximately 4'000 more entries}; }   

If this limit is limited to source code, then I can use another library to generate a class file (maybe codemodel) directly. I would like to keep my code, if possible, any suggestions without rewriting the output generator again from scratch?

I think you should reconsider your strategy, model your data structures and methods accordingly and You do not need to generate code. Instead of generating Java code for 4000 constants, store your data in a file or database and write that data to read that data in the initial time to fill a list with your data object.

Generating code is a powerful tool, but you should use it carefully. I do not think it is also necessary for your use case, but if you think that this is it, you can try to reduce the portion of the code so that to keep things simple, there is a minimum minimum Possible. Often you can extract a lot of generic codes in an intangible superclass so that you only have to code for some methods in subclasses. And generating codes for 4000 constants is really unnecessary, keep the data in the form of data and dynamically work on your data.

No comments:

Post a Comment