IrService.java
/*******************************************************************************
* Copyright (c) 2025 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
package org.eclipse.rdf4j.queryrender.sparql.ir;
import java.util.Collections;
import java.util.Set;
import java.util.function.UnaryOperator;
import org.eclipse.rdf4j.query.algebra.Var;
/**
* Textual IR node for a SERVICE block.
*
* The reference is kept as already-rendered text to allow either a variable, IRI, or complex expression (as produced by
* the renderer) and to preserve SILENT when present.
*/
public class IrService extends IrNode {
private final String serviceRefText;
private final boolean silent;
private final IrBGP bgp;
public IrService(String serviceRefText, boolean silent, IrBGP bgp, boolean newScope) {
super(newScope);
this.serviceRefText = serviceRefText;
this.silent = silent;
this.bgp = bgp;
}
public String getServiceRefText() {
return serviceRefText;
}
public boolean isSilent() {
return silent;
}
public IrBGP getWhere() {
return bgp;
}
@Override
public void print(IrPrinter p) {
p.startLine();
p.append("SERVICE ");
if (silent) {
p.append("SILENT ");
}
p.append(serviceRefText);
p.append(" ");
bgp.print(p);
}
@Override
public IrNode transformChildren(UnaryOperator<IrNode> op) {
IrBGP newWhere = this.bgp;
if (newWhere != null) {
IrNode t = op.apply(newWhere);
t = t.transformChildren(op);
if (t instanceof IrBGP) {
newWhere = (IrBGP) t;
}
}
return new IrService(this.serviceRefText, this.silent, newWhere, this.isNewScope());
}
@Override
public Set<Var> getVars() {
return bgp == null ? Collections.emptySet() : bgp.getVars();
}
}