From d2eaf66b48a14beb83b44782cee410d72dc3aee2 Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Fri, 6 May 2022 14:03:45 +0200 Subject: [PATCH] Fix a few minor issues with SourcePosition.compareTo --- .../de/hhu/stups/sablecc/patch/SourcePosition.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcePosition.java b/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcePosition.java index 2b3451b..1f43ec5 100644 --- a/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcePosition.java +++ b/sablecc-runtime/src/main/java/de/hhu/stups/sablecc/patch/SourcePosition.java @@ -25,10 +25,15 @@ public class SourcePosition implements Comparable<SourcePosition> { return pos; } + @Override public int compareTo(SourcePosition that) { - if (that.line < line) return 1; - if (that.line > line) return -1; - return pos-that.pos; + if (this.line < that.line) { + return -1; + } else if (this.line > that.line) { + return 1; + } else { + return Integer.compare(this.pos, that.pos); + } } @Override -- GitLab