diff options
author | matozoid <hexagonaal@gmail.com> | 2016-07-12 23:15:50 +0200 |
---|---|---|
committer | matozoid <hexagonaal@gmail.com> | 2016-07-12 23:15:50 +0200 |
commit | 6aaf522db1fdf0e52731346ce1a94a82a6767e5b (patch) | |
tree | f6eb10e9c871bf20d420b5ac6632fdd1601cc42a | |
parent | b8a29557b0138592058939f5d1b99e9fae012626 (diff) | |
download | platform_external_javaparser-6aaf522db1fdf0e52731346ce1a94a82a6767e5b.tar.gz platform_external_javaparser-6aaf522db1fdf0e52731346ce1a94a82a6767e5b.tar.bz2 platform_external_javaparser-6aaf522db1fdf0e52731346ce1a94a82a6767e5b.zip |
Changes after feedback
3 files changed, 51 insertions, 5 deletions
diff --git a/javaparser-core/src/main/java/com/github/javaparser/Position.java b/javaparser-core/src/main/java/com/github/javaparser/Position.java index 810fa55d1..1d0159d8f 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Position.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Position.java @@ -38,6 +38,12 @@ public class Position implements Comparable<Position> { public static final Position UNKNOWN= new Position(0, 0); public Position(int line, int column) { + if (line < Node.ABSOLUTE_END_LINE) { + throw new IllegalArgumentException("Can't position at line " + line); + } + if (column < -1) { + throw new IllegalArgumentException("Can't position at column " + column); + } this.line = line; this.column = column; } @@ -58,11 +64,11 @@ public class Position implements Comparable<Position> { } public Position withColumn(int column) { - return new Position(line, column); + return new Position(this.line, column); } public Position withLine(int line) { - return new Position(line, column); + return new Position(line, this.column); } public boolean isAfter(Position position) { @@ -96,4 +102,20 @@ public class Position implements Comparable<Position> { } return 0; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Position position = (Position) o; + + return line == position.line && column == position.column; + + } + + @Override + public int hashCode() { + return 31 * line + column; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/Range.java b/javaparser-core/src/main/java/com/github/javaparser/Range.java index 21d8a352b..132d9a934 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/Range.java +++ b/javaparser-core/src/main/java/com/github/javaparser/Range.java @@ -12,6 +12,12 @@ public class Range { public final Position end; public Range(Position begin, Position end) { + if (begin == null) { + throw new IllegalArgumentException("begin can't be null"); + } + if (end == null) { + throw new IllegalArgumentException("end can't be null"); + } this.begin = begin; this.end = end; } @@ -49,11 +55,11 @@ public class Range { } public Range withBegin(Position begin) { - return range(begin, end); + return range(begin, this.end); } public Range withEnd(Position end) { - return range(begin, end); + return range(this.begin, end); } public boolean contains(Range other) { @@ -67,4 +73,23 @@ public class Range { public boolean isAfter(Position position) { return begin.isAfter(position); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Range range = (Range) o; + + if (begin != null ? !begin.equals(range.begin) : range.begin != null) return false; + return end != null ? end.equals(range.end) : range.end == null; + + } + + @Override + public int hashCode() { + int result = begin != null ? begin.hashCode() : 0; + result = 31 * result + (end != null ? end.hashCode() : 0); + return result; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/internal/Utils.java b/javaparser-core/src/main/java/com/github/javaparser/ast/internal/Utils.java index d5e7e4e3c..983afefc0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/internal/Utils.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/internal/Utils.java @@ -27,7 +27,6 @@ import java.util.List; /** * @author Federico Tomassetti - * @since 3.0.0 */ public class Utils { public static <T> List<T> ensureNotNull(List<T> list) { |