Search in sources :

Example 1 with ASTVar

use of org.eclipse.rdf4j.query.parser.sparql.ast.ASTVar in project rdf4j by eclipse.

the class WildcardProjectionProcessor method addQueryVars.

private static void addQueryVars(ASTWhereClause queryBody, Node wildcardNode) throws MalformedQueryException {
    QueryVariableCollector visitor = new QueryVariableCollector();
    try {
        // Collect variable names from query
        queryBody.jjtAccept(visitor, null);
        // Adds ASTVar nodes to the ASTProjectionElem nodes and to the parent
        for (String varName : visitor.getVariableNames()) {
            ASTVar varNode = new ASTVar(SyntaxTreeBuilderTreeConstants.JJTVAR);
            ASTProjectionElem projectionElemNode = new ASTProjectionElem(SyntaxTreeBuilderTreeConstants.JJTPROJECTIONELEM);
            varNode.setName(varName);
            projectionElemNode.jjtAppendChild(varNode);
            varNode.jjtSetParent(projectionElemNode);
            wildcardNode.jjtAppendChild(projectionElemNode);
            projectionElemNode.jjtSetParent(wildcardNode);
        }
    } catch (VisitorException e) {
        throw new MalformedQueryException(e);
    }
}
Also used : ASTVar(org.eclipse.rdf4j.query.parser.sparql.ast.ASTVar) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) ASTProjectionElem(org.eclipse.rdf4j.query.parser.sparql.ast.ASTProjectionElem) VisitorException(org.eclipse.rdf4j.query.parser.sparql.ast.VisitorException)

Aggregations

MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)1 ASTProjectionElem (org.eclipse.rdf4j.query.parser.sparql.ast.ASTProjectionElem)1 ASTVar (org.eclipse.rdf4j.query.parser.sparql.ast.ASTVar)1 VisitorException (org.eclipse.rdf4j.query.parser.sparql.ast.VisitorException)1