Skip to content

Commit 2f37b22

Browse files
committed
Add sourcefileURL to GoblintPosition equals and hashcode
1 parent 1508b46 commit 2f37b22

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/main/java/api/messages/GoblintPosition.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,17 @@ public URL getURL() {
8383
return sourcefileURL;
8484
}
8585

86-
// TODO: omits sourcefileURL
8786
@Override
8887
public boolean equals(Object o) {
8988
if (this == o) return true;
9089
if (o == null || getClass() != o.getClass()) return false;
9190
GoblintPosition that = (GoblintPosition) o;
92-
return columnStart == that.columnStart && columnEnd == that.columnEnd && lineStart == that.lineStart && lineEnd == that.lineEnd;
91+
return columnStart == that.columnStart && columnEnd == that.columnEnd && lineStart == that.lineStart && lineEnd == that.lineEnd && Objects.equals(sourcefileURL, that.sourcefileURL);
9392
}
9493

9594
@Override
9695
public int hashCode() {
97-
return Objects.hash(columnStart, columnEnd, lineStart, lineEnd);
96+
return Objects.hash(columnStart, columnEnd, lineStart, lineEnd, sourcefileURL);
9897
}
9998

10099
@Override

src/test/java/GoblintMessagesTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public void testConvertMessagesFromJson() throws IOException {
105105

106106
URL emptyUrl = new File("").toURI().toURL();
107107
GoblintPosition defaultPos = new GoblintPosition(1, 1, 1, 1, emptyUrl);
108+
URL exampleUrl = new File("src/example.c").toURI().toURL();
108109

109110
List<AnalysisResult> response = new ArrayList<>();
110111
response.add(
@@ -121,24 +122,24 @@ public void testConvertMessagesFromJson() throws IOException {
121122
);
122123
response.add(
123124
new GoblintMessagesAnalysisResult(
124-
new GoblintPosition(4, 4, 4, 12, emptyUrl),
125+
new GoblintPosition(4, 4, 4, 12, exampleUrl),
125126
"[Race] Memory location myglobal (race with conf. 110)",
126127
"Warning",
127128
List.of(
128129
Pair.make(
129-
new GoblintPosition(10, 10, 2, 21, emptyUrl),
130+
new GoblintPosition(10, 10, 2, 21, exampleUrl),
130131
"write with [mhp:{tid=[main, t_fun@src/example.c:17:3-17:40#top]}, lock:{mutex1}, thread:[main, t_fun@src/example.c:17:3-17:40#top]] (conf. 110) (exp: & myglobal)"
131132
),
132133
Pair.make(
133-
new GoblintPosition(19, 19, 2, 21, emptyUrl),
134+
new GoblintPosition(19, 19, 2, 21, exampleUrl),
134135
"write with [mhp:{tid=[main]; created={[main, t_fun@src/example.c:17:3-17:40#top]}}, lock:{mutex2}, thread:[main]] (conf. 110) (exp: & myglobal)"
135136
),
136137
Pair.make(
137-
new GoblintPosition(10, 10, 2, 21, emptyUrl),
138+
new GoblintPosition(10, 10, 2, 21, exampleUrl),
138139
"read with [mhp:{tid=[main, t_fun@src/example.c:17:3-17:40#top]}, lock:{mutex1}, thread:[main, t_fun@src/example.c:17:3-17:40#top]] (conf. 110) (exp: & myglobal)"
139140
),
140141
Pair.make(
141-
new GoblintPosition(19, 19, 2, 21, emptyUrl),
142+
new GoblintPosition(19, 19, 2, 21, exampleUrl),
142143
"read with [mhp:{tid=[main]; created={[main, t_fun@src/example.c:17:3-17:40#top]}}, lock:{mutex2}, thread:[main]] (conf. 110) (exp: & myglobal)"
143144
)
144145
)

0 commit comments

Comments
 (0)