/** * Returns a line corresponding to the position denoted by getStartOffset. Returns null if this * information is not available. */ public Integer getStartLine() { LineAndColumn lac = getStartLineAndColumn(); if (lac == null) { return null; } return lac.getLine(); }
/** Returns this location in the format "filename:line". */ public String printPathAndLine() { StringBuilder builder = new StringBuilder(); PathFragment path = getPath(); if (path != null) { builder.append(path.getPathString()); } LineAndColumn position = getStartLineAndColumn(); if (position != null) { builder.append(":").append(position.getLine()); } return builder.toString(); }
private String printWithPath(PathFragment path) { StringBuilder buf = new StringBuilder(); if (path != null) { buf.append(path).append(':'); } LineAndColumn start = getStartLineAndColumn(); if (start == null) { if (getStartOffset() == 0 && getEndOffset() == 0) { buf.append("1"); // i.e. line 1 (special case: no information at all) } else { buf.append("char offsets ").append(getStartOffset()).append("--").append(getEndOffset()); } } else { buf.append(start.getLine()).append(':').append(start.getColumn()); } return buf.toString(); }