int lineOffset = 0;
List<String> brokenLines = new ArrayList<>();
try( BufferedReader r = new BufferedReader( new FileReader( _file))) {
for ( int posIndex=0; posIndex<_positions.size(); posIndex++) {
LineNumberPosition pos = _positions.get( posIndex);
o_LineBrokenPositions.add( new LineNumberPosition(
pos.getOriginalLine(), pos.getEmittedLine()+lineOffset, pos.getEmittedColumn()));
// Copy the input file up to but not including the emitted line # in "pos".
while ( numLinesRead < pos.getEmittedLine()-1) {
brokenLines.add( r.readLine());
numLinesRead++;
}
// Read the line that contains the next line number annotations, but don't write it yet.
String line = r.readLine();
numLinesRead++;
// See if there are two original line annotations on the same emitted line.
LineNumberPosition nextPos;
int prevPartLen = 0;
char[] indent = {};
do {
nextPos = (posIndex < _positions.size()-1) ? _positions.get( posIndex+1) : null;
if ( nextPos != null
&& nextPos.getEmittedLine() == pos.getEmittedLine()
&& nextPos.getOriginalLine() > pos.getOriginalLine()) {
// Two different source line numbers on the same emitted line!
posIndex++;
lineOffset++;
String firstPart = line.substring( 0, nextPos.getEmittedColumn() - prevPartLen - 1);
brokenLines.add( new String(indent) + firstPart);
prevPartLen += firstPart.length();
indent = new char[prevPartLen];
Arrays.fill( indent, ' ');
line = line.substring( firstPart.length(), line.length());
// Alter the position while adding it.
o_LineBrokenPositions.add( new LineNumberPosition(
nextPos.getOriginalLine(), nextPos.getEmittedLine()+lineOffset, nextPos.getEmittedColumn()));
} else {
nextPos = null;
}
} while ( nextPos != null);