|
|
@ -104,6 +104,9 @@ public class TextBuffer { |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
String original = myStringBuilder.toString(); |
|
|
|
String original = myStringBuilder.toString(); |
|
|
|
if (myLineToOffsetMapping == null || myLineToOffsetMapping.isEmpty()) { |
|
|
|
if (myLineToOffsetMapping == null || myLineToOffsetMapping.isEmpty()) { |
|
|
|
|
|
|
|
if (myLineMapping != null) { |
|
|
|
|
|
|
|
return addOriginalLineNumbers(); |
|
|
|
|
|
|
|
} |
|
|
|
return original; |
|
|
|
return original; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
@ -140,6 +143,26 @@ public class TextBuffer { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String addOriginalLineNumbers() { |
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
|
|
|
|
int lineStart = 0, lineEnd; |
|
|
|
|
|
|
|
int count = 0, length = myLineSeparator.length(); |
|
|
|
|
|
|
|
while ((lineEnd = myStringBuilder.indexOf(myLineSeparator, lineStart)) > 0) { |
|
|
|
|
|
|
|
++count; |
|
|
|
|
|
|
|
sb.append(myStringBuilder.substring(lineStart, lineEnd)); |
|
|
|
|
|
|
|
Integer integer = myLineMapping.get(count); |
|
|
|
|
|
|
|
if (integer != null) { |
|
|
|
|
|
|
|
sb.append("// ").append(integer); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sb.append(myLineSeparator); |
|
|
|
|
|
|
|
lineStart = lineEnd + length; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (lineStart < myStringBuilder.length()) { |
|
|
|
|
|
|
|
sb.append(myStringBuilder.substring(lineStart)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return sb.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void appendLines(StringBuilder res, String[] srcLines, int from, int to, int requiredLineNumber) { |
|
|
|
private void appendLines(StringBuilder res, String[] srcLines, int from, int to, int requiredLineNumber) { |
|
|
|
if (to - from > requiredLineNumber) { |
|
|
|
if (to - from > requiredLineNumber) { |
|
|
|
List<String> strings = compactLines(Arrays.asList(srcLines).subList(from, to) ,requiredLineNumber); |
|
|
|
List<String> strings = compactLines(Arrays.asList(srcLines).subList(from, to) ,requiredLineNumber); |
|
|
@ -278,4 +301,14 @@ public class TextBuffer { |
|
|
|
public StringBuilder getOriginalText() { |
|
|
|
public StringBuilder getOriginalText() { |
|
|
|
return myStringBuilder; |
|
|
|
return myStringBuilder; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<Integer, Integer> myLineMapping = null; // new to original
|
|
|
|
|
|
|
|
public void dumpOriginalLineNumbers(int[] lineMapping) { |
|
|
|
|
|
|
|
if (lineMapping.length > 0) { |
|
|
|
|
|
|
|
myLineMapping = new HashMap<Integer, Integer>(); |
|
|
|
|
|
|
|
for (int i = 0; i < lineMapping.length; i+=2) { |
|
|
|
|
|
|
|
myLineMapping.put(lineMapping[i+1], lineMapping[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|