Community
Participate
Working Groups
Here's a proposition for a more type safe and simple API. This only need changes are in DefaultCodeFormatterConstants.java, the internal representation can be unchanged. // to add to DefaultCodeFormatterConstants: public static String changeForceAlignment(String key, boolean force); public static String changeSplitStyle(String key, String value, int splitStyle); public static String changeIndentStyle(String key, String value, int indentStyle); public static String getAlignmentValue(String key, boolean force, int splitStyle, int indentStyle); public static final int WRAP_NO_SPLIT= 0; public static final int WRAP_COMPACT= 1; public static final int WRAP_COMPACT_FIRST_BREAK= 2; pubilc static final int WRAP_ONE_PER_LINE= 3; public static final int WRAP_NEXT_PER_LINE= 4; public static final int WRAP_NEXT_SHIFTED= 5; public static final int FORMATTER_INDENT_DEFAULT= 10; public static final int FORMATTER_INDENT_BY_ONE= 11; public static final int FORMATTER_INDENT_ON_COLUMN = 12; What do you think? I could even provide you with the implementation, I'm doing something like this in my code.
We might want to consider this. The values of alignment are not very human legible :-).
So we could do this: public void changeIndentStyle(Map options, String key, int indentStyle) { ... } public void changeForceAlignment(Map options, String key, boolean force) { ... } public void changeSplitStyle(String key, String value, int splitStyle) { ... } public static String getAlignmentValue(String key, boolean force, int splitStyle, int indentStyle) { .... } public static final int WRAP_NO_SPLIT= 0; public static final int WRAP_COMPACT= 1; public static final int WRAP_COMPACT_FIRST_BREAK= 2; pubilc static final int WRAP_ONE_PER_LINE= 3; public static final int WRAP_NEXT_PER_LINE= 4; public static final int WRAP_NEXT_SHIFTED= 5; public static final int FORMATTER_INDENT_DEFAULT= 10; public static final int FORMATTER_INDENT_BY_ONE= 11; public static final int FORMATTER_INDENT_ON_COLUMN = 12;
Now that I read it again, we should use 'set' instead of 'change'. And 'ForceSplit' instead of 'ForceAlignment': public void setIndentStyle(Map options, String key, int indentStyle) {...} public void setForceSplit(Map options, String key, boolean forceSplit) {...} public void setSplitStyle(String key, String value, int splitStyle) {...} And: createAlignmentValue(...) {...} because we don't get it from somewhere, but encode it from scratch.
That is fine for me. I'll try to update the code formatter to use these new values. How do you think we should encode the string? An int value? or something else?
Fixed and released in HEAD.
I have a use case here where we need to extract the three settings (force, indent, split) out of a single string and we don't have the whole map available: When one is only interested in getting one setting, JavaCore.getOption(...) can be used which returns it as a string -> no Map available. Using JavaCore.getOptions().get(...) is no alternative, for efficiency reasons. [this is used for the Java indenter to evaluate the code formatter settings]. So we need the following functions in the API in DefaultCodeFormatterConstants: public static String setForceWrapping(String value, boolean force); public static String setWrappingStyle(String value, int wrappingStyle); public static String setIndentStyle(String value, int indentStyle); public static int getForceWrapping(String value); public static int getWrappingStyle(String value); public static int getIndentStyle(String value); and, as before: public static String createAlignmentValue(boolean, int, int); These are more generic than the corresponding functions which take a map, which are for a special case. I'm in favor of removing the latters completely, in order to follow KISS - keep it simple, stupid. What do you think?
So I need to deprecate old ones and add the new ones.
Fixed and released in HEAD. Regression tests added.
Verified in 200402121200.