Community
Participate
Working Groups
CodeFormatter.setIndentationLevel() is deprecated. The only way to specify an indentation level w/o using deprecated methods is to use the static convenience method to format(String, int, Map). However, the static method offers no way of mapping positions. There should be a way to have all features w/o requiring to use deprecated methods.
I think we should set the initial indentation level using the formatter options. Then you don't need to use the format(String, int, Map) method anymore and this method should be deprecated. To set the mapping positions it should be done through setPositionsToMap(int[] positions). And after formatting you get them back using int[] getMappedPositions(). Is this fine for you? Philippe, any comment?
I don't think the indentation level is a format option. A format option is something global (user preference), while the indentation level is specific to the format operation. It has a tight relationship with the string to be formatted and its context. Depending on where you want to insert the string, the indentation level changes. The position mapping is something optional, so I'm fine with the setter/getter. However, I was wondering, why the CodeFormatter creates a new array. It could do the mapping in-place. If the client really needs another array, it can do so by copying the old array itself. I purpose the following 'API': public CodeFormatter(); // defaults to empty options public CodeFormatter(Map options); public void format(String string); // defauls to indentation level == 0 public void format(String string, int indentationLevel); public void setPositionsToMap(int[] positions); I'm not sure what the splitting has to do with formatting. It should be a different class, IMHO. Something like CodeSplitter?
In fact it might be a good idea to split into two components the code formatting and the line splitting. I think we need to investiguate how to rewrite the code formatter which is extremely difficult to maintain. That explains all the problems I have to fix the position mapping. Your API looks good to me. I'll see with Philippe if we change them.
Sounds like a fair change.
Why do you want methods that returns void? You don't want to get the formatted string back? public CodeFormatter(); // defaults to empty options I won't change this one. It is still deprecated. You should always call the CodeFormatter(JavaCore.getOptions()); public void format(String string); // defauls to indentation level == 0 public void format(String string, int indentationLevel); Let me know if you want the return type of these two methods to be String.
uh, that's a bug. Of course they should return String :)
I added the requested API and I removed some convenient static methods. I will send you the new formatter code and let me know if this is close to what you want.
Changed API released in HEAD. Please make all concerned people aware of these changes in ZRH.