personthecat.catlib.linting.StackTraceLinter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of catlib-quilt Show documentation
Show all versions of catlib-quilt Show documentation
Utilities for serialization, commands, noise generation, IO, and some new data types.
The newest version!
package personthecat.catlib.linting;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.minecraft.class_124;
import net.minecraft.class_2561;
public class StackTraceLinter extends SyntaxLinter {
private static final Pattern AT_PATTERN = Pattern.compile("\\bat\\s", Pattern.MULTILINE);
private static final Pattern PACKAGE_PATTERN = Pattern.compile("(?<=\\s)[a-z]+(\\.[a-z]+)+(?=\\.)", Pattern.MULTILINE);
private static final Pattern METHOD_PATTERN = Pattern.compile("[\\w$]+(?=\\()", Pattern.MULTILINE);
private static final Pattern SPECIAL_METHOD_PATTERN = Pattern.compile("(|)(?=\\()", Pattern.MULTILINE);
private static final Pattern LINE_PATTERN = Pattern.compile("(?<=\\()(\\w+\\.\\w+:\\d+)(?=\\))", Pattern.MULTILINE);
private static final Pattern MESSAGE_PATTERN = Pattern.compile(":\\s(.+)", Pattern.MULTILINE);
private static final Highlighter[] HIGHLIGHTERS = {
new RegexHighlighter(AT_PATTERN, color(class_124.field_1077)),
new RegexHighlighter(PACKAGE_PATTERN, color(class_124.field_1080)),
new RegexHighlighter(METHOD_PATTERN, color(class_124.field_1065).method_10978(true)),
new RegexHighlighter(SPECIAL_METHOD_PATTERN, color(class_124.field_1065).method_10978(true).method_10982(true)),
new RegexHighlighter(LINE_PATTERN, color(class_124.field_1064).method_27706(class_124.field_1073)),
new RegexHighlighter(MESSAGE_PATTERN, color(class_124.field_1061))
};
public static final StackTraceLinter INSTANCE = new StackTraceLinter();
private StackTraceLinter() {
super(HIGHLIGHTERS);
}
public static class_2561 format(final String stacktrace) {
return INSTANCE.lint(collapsePackages(stacktrace));
}
private static String collapsePackages(final String stacktrace) {
final StringBuilder sb = new StringBuilder(stacktrace.length());
final Matcher matcher = PACKAGE_PATTERN.matcher(stacktrace);
int end = 0;
while (matcher.find()) {
sb.append(stacktrace, end, matcher.start());
final String match = matcher.group(0);
final String[] packs = match.split("\\.");
sb.append(packs[0].charAt(0));
for (int i = 1; i < packs.length; i++) {
sb.append('.').append(packs[i].charAt(0));
}
end = matcher.end();
}
if (end > 0) {
sb.append(stacktrace, end, stacktrace.length());
}
return sb.toString();
}
}