diff --git a/src/main/java/io/github/treesitter/jtreesitter/Logger.java b/src/main/java/io/github/treesitter/jtreesitter/Logger.java index 066ec79..204d260 100644 --- a/src/main/java/io/github/treesitter/jtreesitter/Logger.java +++ b/src/main/java/io/github/treesitter/jtreesitter/Logger.java @@ -1,19 +1,29 @@ package io.github.treesitter.jtreesitter; -import java.util.function.BiConsumer; import org.jspecify.annotations.NonNull; /** A function that logs parsing results. */ @FunctionalInterface -public interface Logger extends BiConsumer { +public interface Logger { /** - * {@inheritDoc} + * Performs this operation on the given arguments. * * @param type the log type * @param message the log message */ - @Override - void accept(@NonNull Type type, @NonNull String message); + void log(@NonNull Type type, @NonNull String message); + + /** + * Performs this operation on the given arguments. + * + * @param type the log type + * @param message the log message + * @deprecated Use {@link #log(Logger.Type, String)} instead + */ + @Deprecated(since = "0.26.0", forRemoval = true) + default void accept(@NonNull Type type, @NonNull String message) { + log(type, message); + } /** The type of a log message. */ enum Type { diff --git a/src/main/java/io/github/treesitter/jtreesitter/ParseCallback.java b/src/main/java/io/github/treesitter/jtreesitter/ParseCallback.java index b9a58fe..59d8bf7 100644 --- a/src/main/java/io/github/treesitter/jtreesitter/ParseCallback.java +++ b/src/main/java/io/github/treesitter/jtreesitter/ParseCallback.java @@ -1,20 +1,32 @@ package io.github.treesitter.jtreesitter; -import java.util.function.BiFunction; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; /** A function that retrieves a chunk of text at a given byte offset and point. */ @FunctionalInterface -public interface ParseCallback extends BiFunction { +public interface ParseCallback { /** - * {@inheritDoc} + * Applies this function to the given arguments. * * @param offset the current byte offset * @param point the current point * @return A chunk of text or {@code null} to indicate the end of the document. */ - @Override @Nullable - String apply(@Unsigned Integer offset, @NonNull Point point); + String read(@Unsigned int offset, @NonNull Point point); + + /** + * Applies this function to the given arguments. + * + * @param offset the current byte offset + * @param point the current point + * @return A chunk of text or {@code null} to indicate the end of the document. + * @deprecated Use {@link #read(int, Point)} instead + */ + @Nullable + @Deprecated(since = "0.26.0", forRemoval = true) + default String apply(@Unsigned Integer offset, @NonNull Point point) { + return read(offset, point); + } } diff --git a/src/main/java/io/github/treesitter/jtreesitter/Parser.java b/src/main/java/io/github/treesitter/jtreesitter/Parser.java index 5b03d45..eb92176 100644 --- a/src/main/java/io/github/treesitter/jtreesitter/Parser.java +++ b/src/main/java/io/github/treesitter/jtreesitter/Parser.java @@ -100,7 +100,7 @@ public Parser setLogger(@Nullable Logger logger) { var log = TSLogger.log.allocate( (p, type, message) -> { var logType = Logger.Type.values()[type]; - logger.accept(logType, message.getString(0)); + logger.log(logType, message.getString(0)); }, arena); TSLogger.log(segment, log); @@ -308,7 +308,7 @@ public Optional parse( // NOTE: can't use _ because of palantir/palantir-java-format#934 var read = TSInput.read.allocate( (payload, index, point, bytes) -> { - var result = parseCallback.apply(index, Point.from(point)); + var result = parseCallback.read(index, Point.from(point)); if (result == null) { bytes.set(C_INT, 0, 0); return MemorySegment.NULL;