package slangc.parser; public final class LocationAnnotation extends Annotation { private final LocationType locationType; private final Token token; public LocationAnnotation(LocationType locationType, Token token) { this.token = token; this.locationType = locationType; } public Token getToken() { return token; } @Override public AnnotationType getAnnotationType() { return AnnotationType.LOCATION; // TODO... } @Override public String toString() { return "LocationAnnotation(" + locationType.name() + ", "+ token.toString() + ")"; } public String niceString() { String start = ""; boolean useEnd = false; switch (locationType) { case LocationType.AFTER: //start = "After "; useEnd = true; break; case LocationType.BEFORE: //start = "Before "; break; default: //start = "Around "; break; } start = "Around "; // NOTE: The 'filename:linenumber...' format is used since VS Code (at least) provides a link back to the source start += "'" + getToken().getSnippet().getStart().getSource().getFilename(); int l = getToken().getSnippet().getStart().getLineCount(); int c = getToken().getSnippet().getStart().getCharacterCount(); if (useEnd) { c += getToken().getSnippet().getLength(); } start += ":" + l + "@" + c + "'"; return start; } }