Community
Participate
Working Groups
The Java Code Style's Formatter's settings for Array Initializers need another style to handle nested array initializers. The current options are: Do not wrap Wrap where necessary Wrap first element, others where necessary Wrap all elements, every element on a new line Wrap all elements, indent all but the first element Wrap all elements, except first element if not necessary I have lots of data for modeling aspects of a computer chip. (These are the unit tests. The thorough testing is done elsewhere.) The initializers are nested arrays of integers and look like: final int[][][] tests = { { { 0, 0, 1, 0x8000 }, { 0xffff, -126, Actor.SUBNORM_STAT_FIELD } }, // 5. // Smallest negative subnormal number { { 0, 0, 0x0000, 0x0040 }, { 0x2000, -126, Actor.SUBNORM_STAT_FIELD } }, // 6. // "Middle" positive subnormal number }; The formatting gets messed up every time I format the file. I've tried all the options, and none are the "right" one, as shown above. With one of the options, every new line gets indented a little bit more: final int[][][] tests = { { { 0, 0, 1, 0x8000 }, { 0xffff, -126, Actor.SUBNORM_STAT_FIELD } }, // 5. // Smallest negative subnormal number { { 0, 0, 0x0000, 0x0040 }, { 0x2000, -126, Actor.SUBNORM_STAT_FIELD } }, // 6. // "Middle" positive subnormal number }; I need something that keeps each of the outer index at the same indentation, as show at the top. If necessary, it could wrap the 2nd-level items, at which time I'd want the closing braces to line up so you could easily see the extent of each top-level entry: final int[][][] tests = { { { 0, 0, 1, 0x8000 }, { 0xffff, -126, Actor.SUBNORM_STAT_FIELD } }, // 5. Smallest negative subnormal number { { 0, 0, 0x0000, 0x0040 }, { 0x2000, -126, Actor.SUBNORM_STAT_FIELD } }, // 6. "Middle" positive subnormal number }; -- Configuration Details -- Product: Eclipse 1.4.0.20110609-1120 (org.eclipse.epp.package.jee.product) Installed Features: org.eclipse.jdt 3.7.0.v20110520-0800-7z8gFchFMTdFYKuLqBLqRja9B15B
Great. All the formatting I did was undone!
Created attachment 202945 [details] text showing initial layout of nested array initializer
Created attachment 202946 [details] text showing increasing indentation done by existing formatter
Created attachment 202947 [details] text showing nested 2nd-level initializers
Moving to JDT Core to investigate. Sounds like this is more about the "Indentation policy" rather than the "Line wrapping policy". Steve: To keep control over line breaks, you may want to enable the "Never join already wrapped lines" checkbox in the "General settings", and then do the wrapping manually.