Skip to content

Commit 97e5c43

Browse files
feat(language): implement clone
1 parent e44e457 commit 97e5c43

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/io/github/treesitter/jtreesitter/Language.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/** A class that defines how to parse a particular language. */
1010
@NullMarked
11-
public final class Language {
11+
public final class Language implements Cloneable {
1212
/**
1313
* The latest ABI version that is supported by the current version of the library.
1414
*
@@ -192,6 +192,17 @@ public Query query(String source) throws QueryError {
192192
return new Query(this, source);
193193
}
194194

195+
/**
196+
* Get another reference to the language.
197+
*
198+
* @since 0.24.0
199+
*/
200+
@Override
201+
@SuppressWarnings("MethodDoesntCallSuperMethod")
202+
public Language clone() {
203+
return new Language(ts_language_copy(self));
204+
}
205+
195206
@Override
196207
public boolean equals(Object o) {
197208
if (this == o) return true;

src/test/java/io/github/treesitter/jtreesitter/LanguageTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ void query() {
9292
@Test
9393
void testEquals() {
9494
var other = new Language(TreeSitterJava.language());
95-
assertEquals(language, other);
95+
assertEquals(other, language.clone());
9696
}
9797
}

0 commit comments

Comments
 (0)