88
99public class LJDiagnostic extends RuntimeException {
1010
11- private String title ;
12- private String message ;
13- private String details ;
14- private String file ;
15- private ErrorPosition position ;
16- private String accentColor ;
11+ private final String title ;
12+ private final String message ;
13+ private final String details ;
14+ private final String file ;
15+ private final ErrorPosition position ;
16+ private final String accentColor ;
1717
1818 public LJDiagnostic (String title , String message , String details , SourcePosition pos , String accentColor ) {
1919 this .title = title ;
@@ -65,7 +65,7 @@ public String toString() {
6565
6666 // location
6767 if (file != null && position != null ) {
68- sb .append ("\n " ).append (file ).append (":" ).append (position .getLineStart ()).append (Colors .RESET ).append ("\n " );
68+ sb .append ("\n " ).append (file ).append (":" ).append (position .lineStart ()).append (Colors .RESET ).append ("\n " );
6969 }
7070
7171 return sb .toString ();
@@ -83,12 +83,11 @@ public String getSnippet() {
8383 // before and after lines for context
8484 int contextBefore = 2 ;
8585 int contextAfter = 2 ;
86- int startLine = Math .max (1 , position .getLineStart () - contextBefore );
87- int endLine = Math .min (lines .size (), position .getLineEnd () + contextAfter );
86+ int startLine = Math .max (1 , position .lineStart () - contextBefore );
87+ int endLine = Math .min (lines .size (), position .lineEnd () + contextAfter );
8888
8989 // calculate padding for line numbers
90- int maxLineNum = endLine ;
91- int padding = String .valueOf (maxLineNum ).length ();
90+ int padding = String .valueOf (endLine ).length ();
9291
9392 for (int i = startLine ; i <= endLine ; i ++) {
9493 String lineNumStr = String .format ("%" + padding + "d" , i );
@@ -98,9 +97,9 @@ public String getSnippet() {
9897 sb .append (Colors .GREY ).append (lineNumStr ).append (" | " ).append (line ).append (Colors .RESET ).append ("\n " );
9998
10099 // add error markers on the line(s) with the error
101- if (i >= position .getLineStart () && i <= position .getLineEnd ()) {
102- int colStart = (i == position .getLineStart ()) ? position .getColStart () : 1 ;
103- int colEnd = (i == position .getLineEnd ()) ? position .getColEnd () : line .length ();
100+ if (i >= position .lineStart () && i <= position .lineEnd ()) {
101+ int colStart = (i == position .lineStart ()) ? position .colStart () : 1 ;
102+ int colEnd = (i == position .lineEnd ()) ? position .colEnd () : line .length ();
104103
105104 if (colStart > 0 && colEnd > 0 ) {
106105 // line number padding + " | " + column offset
0 commit comments