private static String formatSource(SourceSection sourceSection) { if (sourceSection == null) { return "Unknown"; } Source source = sourceSection.getSource(); if (source == null) { // safety check. likely not necsssary return "Unknown"; } StringBuilder b = new StringBuilder(); String path = source.getPath(); if (path == null) { b.append(source.getName()); } else { Path pathAbsolute = Paths.get(path); Path pathBase = new File("").getAbsoluteFile().toPath(); try { Path pathRelative = pathBase.relativize(pathAbsolute); b.append(pathRelative.toFile()); } catch (IllegalArgumentException e) { b.append(source.getName()); } } b.append(":").append(formatIndices(sourceSection, true)); return b.toString(); }
private static String formatSource(SourceSection sourceSection) { if (sourceSection == null) { return "Unknown"; } Source source = sourceSection.getSource(); if (source == null) { // safety check. likely not necsssary return "Unknown"; } StringBuilder b = new StringBuilder(); String path = source.getPath(); if (path == null) { b.append(source.getName()); } else { Path pathAbsolute = Paths.get(path); Path pathBase = new File("").getAbsoluteFile().toPath(); try { Path pathRelative = pathBase.relativize(pathAbsolute); b.append(pathRelative.toFile()); } catch (IllegalArgumentException e) { b.append(source.getName()); } } b.append(":").append(formatIndices(sourceSection, true)); return b.toString(); }
@Override public StackTraceElement toHostFrame() { if (stackTrace == null) { String declaringClass = "<" + language.getId() + ">"; String methodName = rootName == null ? "" : rootName; String fileName = sourceLocation != null ? sourceLocation.getSource().getName() : "Unknown"; int startLine = sourceLocation != null ? sourceLocation.getStartLine() : -1; stackTrace = new StackTraceElement(declaringClass, methodName, fileName, startLine); } return stackTrace; }
@Override public StackTraceElement toHostFrame() { if (stackTrace == null) { String declaringClass = "<" + language.getId() + ">"; String methodName = rootName == null ? "" : rootName; String fileName = sourceLocation != null ? sourceLocation.getSource().getName() : "Unknown"; int startLine = sourceLocation != null ? sourceLocation.getStartLine() : -1; stackTrace = new StackTraceElement(declaringClass, methodName, fileName, startLine); } return stackTrace; }