Can eclipse formatter and code cleanup be configured (or extended) to add the indentation I expect in the following examples:
public static void main(String[] args) {
String[] numbers = new String[] {
"one",
"two",
"three",
"four",
};
new MessageFormat("{0} {1} {2} {3}").format(
"this is string one",
"this is string two",
"this is string three"
);
System.out.println(
new MessageFormat("{0} {1} {2} {3}").format(
new String[]{
"this is string zero",
"this is string one",
"this is string two",
"this is string three"
}
)
);
}
I've played around with all the settings that I can find. The "never join lines" option keeps it from completely butchering the code, but even then the indentation is all stripped and the code comes out like this:
String[] numbers = new String[] {
"one",
"two",
"three",
"four",
};
new MessageFormat("{0} {1} {2} {3}").format(
"this is string one",
"this is string two",
"this is string three"
);
System.out.println(
new MessageFormat("{0} {1} {2} {3}").format(
new String[] {
"this is string zero",
"this is string one",
"this is string two",
"this is string three"
}
)
);
I discovered the ability to turn off formatting around such blocks like this:
// @formatter:off
String[] numbers = new String[] {
"one",
"two",
"three",
"four",
};
// @formatter:on
Which is a decent work around, except that my code ends up littered with them, and the "correct indentation" part of code cleanup ignores the directive and messes up the indentation anyway.
Edit: I found the settings for "Line Wrapping" -> "Default indentation for wrapped lines" and "Default indentation for array initializes" and have set them to "1" instead of "0". That is better for the array initializers, but still doesn't indent closing parethesis to match the opening parenthesis the way that I want it to:
public static void main(String[] args) {
String[] numbers = new String[] {
"one",
"two",
"three",
"four",
};
new MessageFormat("{0} {1} {2} {3}").format(
"this is string one",
"this is string two",
"this is string three"
);
System.out.println(
new MessageFormat("{0} {1} {2} {3}").format(
new String[] {
"this is string zero",
"this is string one",
"this is string two",
"this is string three"
}
)
);
}