io.quarkiverse.jackson.jq.JacksonJqScopeRecorder Maven / Gradle / Ivy
package io.quarkiverse.jackson.jq;
import java.util.List;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import net.thisptr.jackson.jq.Function;
import net.thisptr.jackson.jq.Scope;
import net.thisptr.jackson.jq.Version;
import net.thisptr.jackson.jq.internal.IsolatedScopeQuery;
import net.thisptr.jackson.jq.internal.JsonQueryFunction;
import net.thisptr.jackson.jq.internal.javacc.ExpressionParser;
@Recorder
public class JacksonJqScopeRecorder {
public RuntimeValue createScope() {
final Scope scope = Scope.newEmptyScope();
return new RuntimeValue<>(scope);
}
public RuntimeValue createScope(RuntimeValue parent) {
final Scope scope = Scope.newChildScope(parent.getValue());
return new RuntimeValue<>(scope);
}
public void addFunction(RuntimeValue scope, String name, Function function) {
scope.getValue().addFunction(name, function);
}
public void addFunction(RuntimeValue scope, String name, RuntimeValue function) {
scope.getValue().addFunction(name, function.getValue());
}
public void addFunction(RuntimeValue scope, String name, List args, String body, String version) {
try {
Function function = new JsonQueryFunction(
name,
args,
new IsolatedScopeQuery(ExpressionParser.compile(body, Version.valueOf(version))),
scope.getValue());
scope.getValue().addFunction(
name,
args.size(),
function);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy