Link Here
|
111 |
} |
111 |
} |
112 |
|
112 |
|
113 |
void formatSource(String source, String formattedOutput) { |
113 |
void formatSource(String source, String formattedOutput) { |
|
|
114 |
formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0); |
115 |
} |
116 |
|
117 |
void formatSource(String source, String formattedOutput, int kind, int indentationLevel) { |
114 |
int regionStart = source.indexOf("[#"); |
118 |
int regionStart = source.indexOf("[#"); |
115 |
if (regionStart != -1) { |
119 |
if (regionStart != -1) { |
116 |
IRegion[] regions = new Region[10]; |
120 |
IRegion[] regions = new Region[10]; |
Link Here
|
127 |
start = regionEnd + 2; |
131 |
start = regionEnd + 2; |
128 |
regionStart = source.indexOf("[#", start); |
132 |
regionStart = source.indexOf("[#", start); |
129 |
} |
133 |
} |
130 |
System.arraycopy(regions, 0, regions = new Region[idx], 0, idx); |
|
|
131 |
buffer.append(source.substring(start, source.length())); |
134 |
buffer.append(source.substring(start, source.length())); |
132 |
String newSource = buffer.toString(); |
135 |
String newSource = buffer.toString(); |
133 |
String result = runFormatter(codeFormatter(), newSource, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, regions, Util.LINE_SEPARATOR); |
136 |
String result; |
|
|
137 |
if (idx == 1) { |
138 |
// Use offset and length until bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=233967 is fixed |
139 |
result = runFormatter(codeFormatter(), newSource, kind, indentationLevel, regions[0].getOffset(), regions[0].getLength(), Util.LINE_SEPARATOR); |
140 |
} else { |
141 |
System.arraycopy(regions, 0, regions = new Region[idx], 0, idx); |
142 |
result = runFormatter(codeFormatter(), newSource, kind, indentationLevel, regions, Util.LINE_SEPARATOR); |
143 |
} |
134 |
assertLineEquals(result, newSource, formattedOutput, false); |
144 |
assertLineEquals(result, newSource, formattedOutput, false); |
135 |
} else { |
145 |
} else { |
136 |
formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, false, 0, -1, null); |
146 |
formatSource(source, formattedOutput, kind, indentationLevel, false, 0, -1, null); |
137 |
} |
147 |
} |
138 |
} |
148 |
} |
139 |
|
149 |
|