File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
main/java/io/github/treesitter/jtreesitter
test/java/io/github/treesitter/jtreesitter/languages Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 11package io .github .treesitter .jtreesitter ;
22
3- import java .lang .foreign .*;
43import static io .github .treesitter .jtreesitter .internal .TreeSitter .*;
54
65import io .github .treesitter .jtreesitter .internal .TreeSitter ;
7-
6+ import java . lang . foreign .*;
87import org .jspecify .annotations .NullMarked ;
98import org .jspecify .annotations .Nullable ;
109
@@ -23,7 +22,7 @@ public final class Language {
2322 public static final @ Unsigned int MIN_COMPATIBLE_LANGUAGE_VERSION = TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION ();
2423
2524 private static final ValueLayout VOID_PTR =
26- ValueLayout .ADDRESS .withTargetLayout (MemoryLayout .sequenceLayout (Long .MAX_VALUE , ValueLayout .JAVA_BYTE ));
25+ ValueLayout .ADDRESS .withTargetLayout (MemoryLayout .sequenceLayout (Long .MAX_VALUE , ValueLayout .JAVA_BYTE ));
2726
2827 private static final FunctionDescriptor FUNC_DESC = FunctionDescriptor .of (VOID_PTR );
2928
Original file line number Diff line number Diff line change @@ -11,9 +11,7 @@ public final class TreeSitterJava {
1111 private static final TreeSitterJava INSTANCE = new TreeSitterJava ();
1212
1313 private final Arena arena = Arena .ofAuto ();
14- private final String library = System .mapLibraryName ("tree-sitter-java" );
15- private final SymbolLookup symbols =
16- SymbolLookup .libraryLookup (library , arena ).or (SymbolLookup .loaderLookup ());
14+ private final SymbolLookup symbols = findLibrary ();
1715
1816 /**
1917 * {@snippet lang=c :
@@ -24,6 +22,15 @@ public static MemorySegment language() {
2422 return INSTANCE .call ("tree_sitter_java" );
2523 }
2624
25+ private SymbolLookup findLibrary () {
26+ try {
27+ var library = System .mapLibraryName ("tree-sitter-java" );
28+ return SymbolLookup .libraryLookup (library , arena );
29+ } catch (IllegalArgumentException e ) {
30+ return SymbolLookup .loaderLookup ();
31+ }
32+ }
33+
2734 private static UnsatisfiedLinkError unresolved (String name ) {
2835 return new UnsatisfiedLinkError ("Unresolved symbol: %s" .formatted (name ));
2936 }
You can’t perform that action at this time.
0 commit comments