Bug 49968 - [formatter] Alignment API
Summary: [formatter] Alignment API
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-01-14 06:01 EST by Silvio Böhler CLA
Modified: 2004-02-12 14:26 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Silvio Böhler CLA 2004-01-14 06:01:33 EST
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.
Comment 1 Olivier Thomann CLA 2004-01-14 08:48:39 EST
We might want to consider this. The values of alignment are not very human
legible :-).
Comment 2 Olivier Thomann CLA 2004-01-16 09:02:14 EST
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;
Comment 3 Silvio Böhler CLA 2004-01-16 09:14:37 EST
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.
Comment 4 Olivier Thomann CLA 2004-01-16 09:18:18 EST
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?
Comment 5 Olivier Thomann CLA 2004-01-16 12:04:02 EST
Fixed and released in HEAD.
Comment 6 Silvio Böhler CLA 2004-01-21 06:05:57 EST
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?
Comment 7 Olivier Thomann CLA 2004-01-21 10:40:36 EST
So I need to deprecate old ones and add the new ones.
Comment 8 Olivier Thomann CLA 2004-01-22 11:23:31 EST
Fixed and released in HEAD.
Regression tests added.
Comment 9 Olivier Thomann CLA 2004-02-12 14:26:53 EST
Verified in 200402121200.