Fix line/col numbers in TokenMgrError
Ref #4635 Col number of zero may happen when the error is reported on a newline. In the rest of PMD a newline is considered to sit at the last index of the previous line. So the index is now the first character of the next line, which is slightly wrong but that doesn't matter much.
This commit is contained in:
1 file changed
+6
-4
@@ -4,6 +4,8 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.ast;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@@ -31,8 +33,8 @@ public final class TokenMgrError extends FileAnalysisException {
|
||||
*/
|
||||
public TokenMgrError(int line, int column, @Nullable FileId filename, String message, @Nullable Throwable cause) {
|
||||
super(message, cause);
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
this.line = max(line, 1);
|
||||
this.column = max(column, 1);
|
||||
if (filename != null) {
|
||||
super.setFileId(filename);
|
||||
}
|
||||
@@ -44,8 +46,8 @@ public final class TokenMgrError extends FileAnalysisException {
|
||||
@InternalApi
|
||||
public TokenMgrError(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) {
|
||||
super(makeReason(eofSeen, lexStateName, errorAfter, curChar));
|
||||
line = errorLine;
|
||||
column = errorColumn;
|
||||
line = max(errorLine, 1);
|
||||
column = max(errorColumn, 1);
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
|
||||
Reference in new issue
Block a user