|
@@ -31,7 +31,7 @@ public final class TokenPrinter {
|
|
|
private static final String TAB_REPLACEMENT = " "; // might depend on files
|
|
private static final String TAB_REPLACEMENT = " "; // might depend on files
|
|
|
|
|
|
|
|
// Configuration:
|
|
// Configuration:
|
|
|
- private static final boolean INDICATE_TINY_TOKEN = true; // print token with length <= 1 in lowercase
|
|
|
|
|
|
|
+ private static final boolean INDICATE_TINY_TOKEN = false; // print token with length <= 1 in lowercase
|
|
|
private static final boolean REPLACE_TABS = false;
|
|
private static final boolean REPLACE_TABS = false;
|
|
|
|
|
|
|
|
private TokenPrinter() {
|
|
private TokenPrinter() {
|
|
@@ -62,6 +62,7 @@ public final class TokenPrinter {
|
|
|
int lineIndex = 0;
|
|
int lineIndex = 0;
|
|
|
int columnIndex = 1;
|
|
int columnIndex = 1;
|
|
|
String file = null; // no file yet
|
|
String file = null; // no file yet
|
|
|
|
|
+ String currentLine = null;
|
|
|
|
|
|
|
|
for (Token token : tokens.allTokens()) {
|
|
for (Token token : tokens.allTokens()) {
|
|
|
// New code file:
|
|
// New code file:
|
|
@@ -80,7 +81,7 @@ public final class TokenPrinter {
|
|
|
columnIndex = 1;
|
|
columnIndex = 1;
|
|
|
|
|
|
|
|
String fileName = token.getFile().isEmpty() ? root.getName() : token.getFile();
|
|
String fileName = token.getFile().isEmpty() ? root.getName() : token.getFile();
|
|
|
- String currentLine = filesToLines.get(fileName).get(lineIndex - 1);
|
|
|
|
|
|
|
+ currentLine = filesToLines.get(fileName).get(lineIndex - 1);
|
|
|
if (REPLACE_TABS) {
|
|
if (REPLACE_TABS) {
|
|
|
currentLine = currentLine.replace(TAB, TAB_REPLACEMENT);
|
|
currentLine = currentLine.replace(TAB, TAB_REPLACEMENT);
|
|
|
}
|
|
}
|
|
@@ -88,6 +89,8 @@ public final class TokenPrinter {
|
|
|
appendTokenLinePrefix(builder);
|
|
appendTokenLinePrefix(builder);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ assert currentLine != null;
|
|
|
|
|
+
|
|
|
// New line if already past token index:
|
|
// New line if already past token index:
|
|
|
if (columnIndex > token.getColumn()) {
|
|
if (columnIndex > token.getColumn()) {
|
|
|
appendTokenLinePrefix(builder);
|
|
appendTokenLinePrefix(builder);
|
|
@@ -95,7 +98,7 @@ public final class TokenPrinter {
|
|
|
}
|
|
}
|
|
|
// Move to token index:
|
|
// Move to token index:
|
|
|
while (columnIndex < token.getColumn()) {
|
|
while (columnIndex < token.getColumn()) {
|
|
|
- builder.append(SPACE);
|
|
|
|
|
|
|
+ builder.append(currentLine.length() > columnIndex && currentLine.charAt(columnIndex - 1) == '\t'? TAB : SPACE);
|
|
|
columnIndex++;
|
|
columnIndex++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -107,7 +110,7 @@ public final class TokenPrinter {
|
|
|
// Move up to token end:
|
|
// Move up to token end:
|
|
|
int tokenEndIndex = token.getColumn() + token.getLength() - 1;
|
|
int tokenEndIndex = token.getColumn() + token.getLength() - 1;
|
|
|
while (columnIndex < tokenEndIndex) {
|
|
while (columnIndex < tokenEndIndex) {
|
|
|
- builder.append(SPACE);
|
|
|
|
|
|
|
+ builder.append(currentLine.length() > columnIndex && currentLine.charAt(columnIndex - 1) == '\t'? TAB : SPACE);
|
|
|
columnIndex++;
|
|
columnIndex++;
|
|
|
}
|
|
}
|
|
|
// Print token end if not already past it:
|
|
// Print token end if not already past it:
|
|
@@ -120,7 +123,7 @@ public final class TokenPrinter {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static StringBuilder appendCodeLinePrefix(StringBuilder builder, int index) {
|
|
private static StringBuilder appendCodeLinePrefix(StringBuilder builder, int index) {
|
|
|
- return builder.append(System.lineSeparator()).append(index + TAB);
|
|
|
|
|
|
|
+ return builder.append(System.lineSeparator()).append(index).append(TAB);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static StringBuilder appendTokenLinePrefix(StringBuilder builder) {
|
|
private static StringBuilder appendTokenLinePrefix(StringBuilder builder) {
|
|
@@ -138,7 +141,7 @@ public final class TokenPrinter {
|
|
|
* Turns a list of files into a map which maps the file names to a list of the contained lines of that file.
|
|
* Turns a list of files into a map which maps the file names to a list of the contained lines of that file.
|
|
|
*/
|
|
*/
|
|
|
private static Map<String, List<String>> readFiles(Collection<File> allFiles) {
|
|
private static Map<String, List<String>> readFiles(Collection<File> allFiles) {
|
|
|
- return allFiles.stream().collect(toMap(it -> it.getName(), it -> linesFromFile(it)));
|
|
|
|
|
|
|
+ return allFiles.stream().collect(toMap(File::getName, TokenPrinter::linesFromFile));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|