Skip to content

Commit acb518f

Browse files
authored
Merge pull request #51 from seart-group/bug/sigsegv
2 parents f363267 + 8fe7c81 commit acb518f

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

src/main/java/ch/usi/si/seart/treesitter/OffsetTreeCursor.java

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.experimental.FieldDefaults;
66
import org.jetbrains.annotations.NotNull;
77

8+
import java.util.Collections;
89
import java.util.List;
910
import java.util.Objects;
1011
import java.util.function.Consumer;
@@ -116,11 +117,19 @@ public Node getChildByFieldName(@NotNull String name) {
116117
return new OffsetNode(node.getChildByFieldName(name));
117118
}
118119

120+
@Override
121+
public int getChildCount() {
122+
return node.getChildCount();
123+
}
124+
119125
@Override
120126
public List<Node> getChildren() {
121127
return node.getChildren().stream()
122128
.map(OffsetNode::new)
123-
.collect(Collectors.toList());
129+
.collect(Collectors.collectingAndThen(
130+
Collectors.toList(),
131+
Collections::unmodifiableList
132+
));
124133
}
125134

126135
@Override
@@ -151,6 +160,11 @@ public Point getEndPoint() {
151160
return node.getEndPoint().add(offset);
152161
}
153162

163+
@Override
164+
public String getFieldNameForChild(int child) {
165+
return node.getFieldNameForChild(child);
166+
}
167+
154168
@Override
155169
public Node getFirstChildForByte(int offset) {
156170
throw new UnsupportedOperationException(UOE_MESSAGE_2);
@@ -214,6 +228,41 @@ public Point getStartPoint() {
214228
return node.getStartPoint().add(offset);
215229
}
216230

231+
@Override
232+
public Symbol getSymbol() {
233+
return node.getSymbol();
234+
}
235+
236+
@Override
237+
public String getType() {
238+
return node.getType();
239+
}
240+
241+
@Override
242+
public boolean hasError() {
243+
return node.hasError();
244+
}
245+
246+
@Override
247+
public boolean isExtra() {
248+
return node.isExtra();
249+
}
250+
251+
@Override
252+
public boolean isMissing() {
253+
return node.isMissing();
254+
}
255+
256+
@Override
257+
public boolean isNamed() {
258+
return node.isNamed();
259+
}
260+
261+
@Override
262+
public boolean isNull() {
263+
return node.isNull();
264+
}
265+
217266
@Override
218267
public TreeCursor walk() {
219268
return new OffsetTreeCursor(node, offset);
@@ -223,6 +272,31 @@ public TreeCursor walk() {
223272
public QueryCursor walk(@NotNull Query query) {
224273
throw new UnsupportedOperationException(UOE_MESSAGE_3);
225274
}
275+
276+
@Override
277+
public boolean equals(Object obj) {
278+
if (obj == this) return true;
279+
if (obj == null || getClass() != obj.getClass()) return false;
280+
OffsetNode other = (OffsetNode) obj;
281+
return node.equals(other.node);
282+
}
283+
284+
@Override
285+
public int hashCode() {
286+
return Objects.hash(node, offset);
287+
}
288+
289+
@Override
290+
public String toString() {
291+
String original = node.toString();
292+
int lower = Node.class.getSimpleName().length() + 1;
293+
int upper = original.length() - 1;
294+
String data = original.substring(lower, upper);
295+
return String.format(
296+
"OffsetNode(%s, row: %d, column: %d)",
297+
data, offset.getRow(), offset.getColumn()
298+
);
299+
}
226300
}
227301

228302
@Override

0 commit comments

Comments
 (0)